| 1 |
use Test2::V0 -target => 'Test2::Harness::Runner::Resource::SharedJobSlots::Config'; |
| 2 |
use Test2::Harness::Runner::Resource::SharedJobSlots::Config; |
| 3 |
|
| 4 |
my $dir = __FILE__; |
| 5 |
$dir =~ s{Config\.t$}{}g; |
| 6 |
chdir($dir) or die "Could not chdir ($dir): $!"; |
| 7 |
|
| 8 |
sub CONFIG { |
| 9 |
return { |
| 10 |
DEFAULT => { |
| 11 |
default_slots_per_run => 1, |
| 12 |
default_slots_per_job => 1, |
| 13 |
}, |
| 14 |
COMMON => { |
| 15 |
algorithm => 'fair', |
| 16 |
state_file => '/tmp/yath-state-config-test', |
| 17 |
max_slots => 4, |
| 18 |
max_slots_per_run => 4, |
| 19 |
max_slots_per_job => 2, |
| 20 |
default_slots_per_run => 2, |
| 21 |
default_slots_per_job => 2, |
| 22 |
}, |
| 23 |
foo => { |
| 24 |
max_slots => 13, |
| 25 |
max_slots_per_run => 13, |
| 26 |
max_slots_per_job => 5, |
| 27 |
default_slots_per_run => 3, |
| 28 |
default_slots_per_job => 2, |
| 29 |
}, |
| 30 |
bar => { |
| 31 |
max_slots => 8, |
| 32 |
max_slots_per_run => 6, |
| 33 |
max_slots_per_job => 2, |
| 34 |
default_slots_per_run => 4, |
| 35 |
default_slots_per_job => 2, |
| 36 |
state_umask => '0077', |
| 37 |
}, |
| 38 |
baz => { |
| 39 |
algorithm => 'first', |
| 40 |
max_slots => 64, |
| 41 |
max_slots_per_run => 64, |
| 42 |
max_slots_per_job => 32, |
| 43 |
default_slots_per_run => 64, |
| 44 |
default_slots_per_job => 32, |
| 45 |
}, |
| 46 |
bat => undef, |
| 47 |
ban => { |
| 48 |
use_common => '0', |
| 49 |
}, |
| 50 |
baf => { |
| 51 |
use_common => 0, |
| 52 |
max_slots => 7, |
| 53 |
}, |
| 54 |
}; |
| 55 |
} |
| 56 |
|
| 57 |
my $one = $CLASS->find(host => 'foo'); |
| 58 |
|
| 59 |
like( |
| 60 |
$one, |
| 61 |
hash { |
| 62 |
field host => 'foo'; |
| 63 |
field common_conf => CONFIG()->{COMMON}; |
| 64 |
field host_conf => CONFIG()->{foo}; |
| 65 |
field config_file => '.sharedjobslots.yml'; |
| 66 |
field config_raw => CONFIG(); |
| 67 |
etc; |
| 68 |
}, |
| 69 |
"Found the config file, loaded options" |
| 70 |
); |
| 71 |
|
| 72 |
is($one->state_umask, 0007, "Got default umask"); |
| 73 |
is($one->state_file, '/tmp/yath-state-config-test', "Got state file from common"); |
| 74 |
is($one->algorithm, '_redistribute_fair', "got algorithm from common"); |
| 75 |
is($one->max_slots, 13, "got max slots from host"); |
| 76 |
is($one->min_slots_per_run, 0, "default min slots per run at 0"); |
| 77 |
is($one->max_slots_per_job, 5, "got max slots per job from host"); |
| 78 |
is($one->max_slots_per_run, 13, "got max slots per run from host"); |
| 79 |
is($one->default_slots_per_job, 2, "got default slots per job from host"); |
| 80 |
is($one->default_slots_per_run, 3, "got default slots per run from host"); |
| 81 |
|
| 82 |
$one = $CLASS->find(host => 'bar'); |
| 83 |
is($one->state_umask, '0077', "Got host umask"); |
| 84 |
|
| 85 |
$one = $CLASS->find(host => 'bat'); |
| 86 |
is($one->algorithm, '_redistribute_fair', "got algorithm from common"); |
| 87 |
is($one->max_slots, 4, "got max slots from common"); |
| 88 |
is($one->min_slots_per_run, 0, "default min slots per run at 0"); |
| 89 |
is($one->max_slots_per_job, 2, "got max slots per job from common"); |
| 90 |
is($one->max_slots_per_run, 4, "got max slots per run from common"); |
| 91 |
is($one->default_slots_per_job, 2, "got default slots per job from common"); |
| 92 |
is($one->default_slots_per_run, 2, "got default slots per run from common"); |
| 93 |
|
| 94 |
$one = $CLASS->find(host => 'baf'); |
| 95 |
is($one->algorithm, '_redistribute_fair', "got algorithm from default"); |
| 96 |
is($one->max_slots, 7, "got max slots from host"); |
| 97 |
is($one->min_slots_per_run, 0, "default min slots per run at 0"); |
| 98 |
is($one->max_slots_per_job, 7, "got max slots per job from default"); |
| 99 |
is($one->max_slots_per_run, 7, "got max slots per run from default"); |
| 100 |
is($one->default_slots_per_job, 7, "got default slots per job from default"); |
| 101 |
is($one->default_slots_per_run, 7, "got default slots per run from default"); |
| 102 |
|
| 103 |
is( |
| 104 |
dies { $one = $CLASS->find(host => 'ban') }, |
| 105 |
"'max_slots' not set in '\.sharedjobslots\.yml' for host 'ban' or under 'COMMON' config.\n", |
| 106 |
"Need a value for max slots" |
| 107 |
); |
| 108 |
|
| 109 |
done_testing; |