Skip to content

Commit

Permalink
Ensure that Open3 receives the correct command when bin_override is set
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Rodgers committed Dec 11, 2018
1 parent 46c25b3 commit 4f03d97
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 7 deletions.
34 changes: 34 additions & 0 deletions spec/job/adapters/lsf/batch_spec.rb
Expand Up @@ -222,4 +222,38 @@
it { is_expected.to eq(["-m", "curie"]) }
end
end

describe "customizing bin paths" do
let(:script) { OodCore::Job::Script.new(content: "echo 'hi'") }

context "when calling with no config" do
it "uses the correct command" do
batch = OodCore::Job::Adapters::Lsf::Batch.new
allow(Open3).to receive(:capture3).and_return(["job.123", "", double("success?" => true)])

batch.submit_string(str: script.content)
expect(Open3).to have_received(:capture3).with(anything, "bsub", any_args)
end
end

context "when calling with normal config" do
it "uses the correct command" do
batch = OodCore::Job::Adapters::Lsf::Batch.new(bindir: "/bin", bin_overrides: {})
allow(Open3).to receive(:capture3).and_return(["job.123", "", double("success?" => true)])

batch.submit_string(str: script.content)
expect(Open3).to have_received(:capture3).with(anything, "/bin/bsub", any_args)
end
end

context "when calling with overrides" do
it "uses the correct command" do
batch = OodCore::Job::Adapters::Lsf::Batch.new(bin_overrides: {"bsub" => "not_bsub"})
allow(Open3).to receive(:capture3).and_return(["job.123", "", double("success?" => true)])

batch.submit_string(str: script.content)
expect(Open3).to have_received(:capture3).with(anything, "not_bsub", any_args)
end
end
end
end
20 changes: 14 additions & 6 deletions spec/job/adapters/pbspro_spec.rb
Expand Up @@ -737,27 +737,35 @@ def build_script(opts = {})
end

describe "customizing bin paths" do
let(:script) { OodCore::Job::Script.new(content: "echo 'hi'") }

context "when calling with no config" do
it "uses qsub" do
batch = OodCore::Job::Adapters::PBSPro::Batch.new(host: "owens.osc.edu", pbs_exec: nil, bin_overrides: {})
expect(Open3).to receive(:capture3).with(anything, "qsub", any_args).and_return(["job.123", "", double("success?" => true)])
OodCore::Job::Adapters::PBSPro.new(pbspro: batch, qstat_factor: nil).submit OodCore::Job::Script.new(content: "echo 'hi'")
allow(Open3).to receive(:capture3).and_return(["job.123", "", double("success?" => true)])

OodCore::Job::Adapters::PBSPro.new(pbspro: batch, qstat_factor: nil).submit script
expect(Open3).to have_received(:capture3).with(anything, "qsub", any_args)
end
end

context "when calling with normal config" do
it "uses qsub" do
batch = OodCore::Job::Adapters::PBSPro::Batch.new(host: "owens.osc.edu", pbs_exec: "/opt/pbspro", bin_overrides: {})
expect(Open3).to receive(:capture3).with(anything, "/opt/pbspro/bin/qsub", any_args).and_return(["job.123", "", double("success?" => true)])
OodCore::Job::Adapters::PBSPro.new(pbspro: batch, qstat_factor: nil).submit OodCore::Job::Script.new(content: "echo 'hi'")
allow(Open3).to receive(:capture3).and_return(["job.123", "", double("success?" => true)])

OodCore::Job::Adapters::PBSPro.new(pbspro: batch, qstat_factor: nil).submit script
expect(Open3).to have_received(:capture3).with(anything, "/opt/pbspro/bin/qsub", any_args)
end
end

context "when calling with overrides" do
it "uses qsub" do
batch = OodCore::Job::Adapters::PBSPro::Batch.new(host: "owens.osc.edu", pbs_exec: "/opt/pbspro", bin_overrides: {"qsub" => "/custom/qsubber"})
expect(Open3).to receive(:capture3).with(anything, "/custom/qsubber", any_args).and_return(["job.123", "", double("success?" => true)])
OodCore::Job::Adapters::PBSPro.new(pbspro: batch, qstat_factor: nil).submit OodCore::Job::Script.new(content: "echo 'hi'")
allow(Open3).to receive(:capture3).and_return(["job.123", "", double("success?" => true)])

OodCore::Job::Adapters::PBSPro.new(pbspro: batch, qstat_factor: nil).submit script
expect(Open3).to have_received(:capture3).with(anything, "/custom/qsubber", any_args)
end
end
end
Expand Down
34 changes: 34 additions & 0 deletions spec/job/adapters/slurm_spec.rb
Expand Up @@ -859,4 +859,38 @@ def job_info(opts = {})
expect(batch.send(:fields).values.last).to eq("%b")
end
end

describe "customizing bin paths" do
let(:script) { OodCore::Job::Script.new(content: "echo 'hi'") }

context "when calling with no config" do
it "uses the correct command" do
batch = OodCore::Job::Adapters::Slurm::Batch.new(cluster: "owens.osc.edu", conf: "/etc/slurm/conf/", bin: nil, bin_overrides: {})
allow(Open3).to receive(:capture3).and_return(["job.123", "", double("success?" => true)])

OodCore::Job::Adapters::Slurm.new(slurm: batch).submit script
expect(Open3).to have_received(:capture3).with(anything, "sbatch", any_args)
end
end

context "when calling with normal config" do
it "uses the correct command" do
batch = OodCore::Job::Adapters::Slurm::Batch.new(cluster: "owens.osc.edu", conf: "/etc/slurm/conf/", bin: "/bin", bin_overrides: {})
allow(Open3).to receive(:capture3).and_return(["job.123", "", double("success?" => true)])

OodCore::Job::Adapters::Slurm.new(slurm: batch).submit script
expect(Open3).to have_received(:capture3).with(anything, "/bin/sbatch", any_args)
end
end

context "when calling with overrides" do
it "uses the correct command" do
batch = OodCore::Job::Adapters::Slurm::Batch.new(cluster: "owens.osc.edu", conf: "/etc/slurm/conf/", bin: nil, bin_overrides: {"sbatch" => "not_sbatch"})
allow(Open3).to receive(:capture3).and_return(["job.123", "", double("success?" => true)])

OodCore::Job::Adapters::Slurm.new(slurm: batch).submit script
expect(Open3).to have_received(:capture3).with(anything, "not_sbatch", any_args)
end
end
end
end
34 changes: 34 additions & 0 deletions spec/job/adapters/torque/batch_spec.rb
Expand Up @@ -139,4 +139,38 @@
end
end
end

describe "customizing bin paths" do
let(:script) { OodCore::Job::Script.new(content: "echo 'hi'") }

context "when calling with no config" do
it "uses the correct command" do
batch = OodCore::Job::Adapters::Torque::Batch.new(host: "owens.osc.edu", lib: "/lib", bin: nil, bin_overrides: {})
allow(Open3).to receive(:capture3).and_return(["job.123", "", double("success?" => true)])

batch.submit script.content
expect(Open3).to have_received(:capture3).with(anything, "qsub", any_args)
end
end

context "when calling with normal config" do
it "uses the correct command" do
batch = OodCore::Job::Adapters::Torque::Batch.new(host: "owens.osc.edu", lib: "/lib", bin: "/bin", bin_overrides: {})
allow(Open3).to receive(:capture3).and_return(["job.123", "", double("success?" => true)])

batch.submit script.content
expect(Open3).to have_received(:capture3).with(anything, "/bin/qsub", any_args)
end
end

context "when calling with overrides" do
it "uses the correct command" do
batch = OodCore::Job::Adapters::Torque::Batch.new(host: "owens.osc.edu", lib: "/lib", bin: nil, bin_overrides: {"qsub" => "not_qsub"})
allow(Open3).to receive(:capture3).and_return(["job.123", "", double("success?" => true)])

batch.submit script.content
expect(Open3).to have_received(:capture3).with(anything, "not_qsub", any_args)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -103,4 +103,4 @@
# as the one that triggered the failure.
Kernel.srand config.seed
=end
end
end

0 comments on commit 4f03d97

Please sign in to comment.