Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
euler-room committed Oct 28, 2024
1 parent bc646ef commit 4265348
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ class AutoOutputDirectory < Attribute
# Value of auto_output_directory attribute
# Defaults to first script path in the project
# @return [String] attribute value
def error_path_value
"#{opts[:value]}/%j-output.log" || 'Default Output Directory'
end

def output_path_value
"#{opts[:value]}/%j-error.log" || 'Default Output Directory'
def value
opts[:value] || 'Default Output Directory'
end

def widget
Expand All @@ -32,13 +28,26 @@ def label(*)
(opts[:label] || 'Output Directory').to_s
end

def output_directory_hash
{ output_path: output_path_value, error_path: error_path_value }
end

# Submission hash describing how to submit this attribute
# @param fmt [String, nil] formatting of hash
# @return [Hash] submission hash
def submit(*)
{ script: { output_path: output_path_value, error_path: error_path_value } }
opts[:value] ? { script: output_directory_hash } : nil
end

private

def error_path_value
"#{opts[:value]}/%j-error.log"
end

def output_path_value
"#{opts[:value]}/%j-output.log"
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require 'test_helper'
require 'smart_attributes'

module SmartAttributes
class AutoOutputDirectoryTest < ActiveSupport::TestCase
def setup
stub_clusters
stub_user
stub_sacctmgr
end

def dynamic_env
{
OOD_BC_DYNAMIC_JS: 'true'
}
end

test 'correctly sets the value' do
with_modified_env(dynamic_env) do
options = {
value: 'output_extravaganza',
label: 'Output Directory'
}
attribute = SmartAttributes::AttributeFactory.build('auto_output_directory', options)

assert_equal('output_extravaganza', attribute.value.to_s)
end
end
end
end
52 changes: 51 additions & 1 deletion apps/dashboard/test/system/project_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,55 @@ def add_auto_environment_variable(project_id, script_id, save: true)
end
end

# super similar to test above, only it adds auto_output_directory
test 'submitting a script with output directory' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
script_id = setup_script(project_id)
project_dir = File.join(dir, 'projects', project_id)
ondemand_dir = File.join(project_dir, '.ondemand')
add_account(project_id, script_id, save: false)

click_on('Add new option')
select('Log Output Directory', from: 'add_new_field_select')
click_on(I18n.t('dashboard.add'))
fill_in('launcher_auto_output_directory', with: 'output_extravaganza')
click_on(I18n.t('dashboard.save'))

launcher_path = project_launcher_path(project_id, script_id)
find("[href='#{launcher_path}'].btn-success").click
assert_selector('h1', text: 'the script title', count: 1)

# assert defaults
assert_equal 'oakley', find('#launcher_auto_batch_clusters').value
assert_equal 'pzs0715', find('#launcher_auto_accounts').value
assert_equal "#{project_dir}/my_cool_script.sh", find('#launcher_auto_scripts').value
assert_nil YAML.safe_load(File.read("#{ondemand_dir}/job_log.yml"))

select('owens', from: 'launcher_auto_batch_clusters')
select('pas2051', from: 'launcher_auto_accounts')
select('my_cooler_script.bash', from: 'launcher_auto_scripts')

Open3
.stubs(:capture3)
.with({}, 'sbatch', '-o', 'output_extravaganza/job-id-123-output.log',
'-e', 'output_extravaganza/job-id-123-error.log' '-A', 'pas2051',
'--export', 'NONE', '--parsable', '-M', 'owens',
stdin_data: "hostname\n")
.returns(['job-id-123', '', exit_success])

OodCore::Job::Adapters::Slurm.any_instance
.stubs(:info).returns(OodCore::Job::Info.new(id: 'job-id-123', status: :running))

click_on 'Launch'
assert_selector('.alert-success', text: 'job-id-123')
jobs = YAML.safe_load(File.read("#{ondemand_dir}/job_log.yml"), permitted_classes: [Time])

assert_equal(1, jobs.size)
assert_equal('job-id-123', jobs[0]['id'])
end
end

test 'submitting a script with auto attributes that fails' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)
Expand Down Expand Up @@ -506,7 +555,8 @@ def add_auto_environment_variable(project_id, script_id, save: true)
actual_new_options = page.all("##{new_field_id} option").map(&:value).to_set
expected_new_options = [
'bc_num_hours', 'auto_queues', 'bc_num_slots', 'auto_cores',
'auto_accounts', 'auto_job_name', 'auto_environment_variable'
'auto_accounts', 'auto_job_name', 'auto_environment_variable',
'auto_output_directory'
].to_set
assert_equal expected_new_options, actual_new_options
end
Expand Down

0 comments on commit 4265348

Please sign in to comment.