- [false, ActiveRecord::RecordInvalid],
- [true, nil],
- ].each do |preemptible_conf, expected|
- test "having Rails.configuration.Containers.UsePreemptibleInstances=#{preemptible_conf}, create preemptible container request and verify #{expected}" do
- sp = {"preemptible" => true}
- common_attrs = {cwd: "test",
- priority: 1,
- command: ["echo", "hello"],
- output_path: "test",
- scheduling_parameters: sp,
- mounts: {"test" => {"kind" => "json"}}}
- Rails.configuration.Containers.UsePreemptibleInstances = preemptible_conf
+ # client requests preemptible, but types are not configured
+ [false, false, false, true, ActiveRecord::RecordInvalid],
+ [true, false, false, true, ActiveRecord::RecordInvalid],
+ # client requests preemptible, types are configured
+ [false, true, false, true, true],
+ [true, true, false, true, true],
+ # client requests non-preemptible for top-level container
+ [false, false, false, false, false],
+ [true, false, false, false, false],
+ [false, true, false, false, false],
+ [true, true, false, false, false],
+ # client requests non-preemptible for child container, preemptible
+ # is enabled anyway if UsePreemptibleInstances and instance types
+ # are configured.
+ [false, false, true, false, false],
+ [true, false, true, false, false],
+ [false, true, true, false, false],
+ [true, true, true, false, true],
+ ].each do |use_preemptible, have_preemptible, is_child, ask, expect|
+ test "with UsePreemptibleInstances=#{use_preemptible} and preemptible types #{have_preemptible ? '' : 'not '}configured, create #{is_child ? 'child' : 'top-level'} container request with preemptible=#{ask} and expect #{expect}" do
+ Rails.configuration.Containers.UsePreemptibleInstances = use_preemptible
+ if have_preemptible
+ configure_preemptible_instance_type
+ end
+ common_attrs = {
+ cwd: "test",
+ priority: 1,
+ command: ["echo", "hello"],
+ output_path: "test",
+ scheduling_parameters: {"preemptible" => ask},
+ mounts: {"test" => {"kind" => "json"}},
+ }