11170: Updated tests to reflect the use of IO instead of File.
authorLucas Di Pentima <lucas@curoverse.com>
Wed, 22 Mar 2017 13:21:17 +0000 (10:21 -0300)
committerLucas Di Pentima <lucas@curoverse.com>
Wed, 22 Mar 2017 13:21:17 +0000 (10:21 -0300)
services/api/lib/crunch_dispatch.rb
services/api/test/unit/crunch_dispatch_test.rb
services/api/test/unit/fail_jobs_test.rb

index 7c9fa0a25360ac959e521bbc8677554d7a23d3ad..c95db312f4337bb95efccf72e66e01e3bd8cf4e7 100644 (file)
@@ -963,11 +963,10 @@ class CrunchDispatch
   # An array of job_uuids in squeue
   def squeue_jobs
     if Rails.configuration.crunch_job_wrapper == :slurm_immediate
-      IO.popen(['squeue', '-a', '-h', '-o', '%j']) do |squeue_pipe|
-        squeue_pipe.readlines.map do |line|
-          line.strip
-        end
-      end
+      p = IO.popen(['squeue', '-a', '-h', '-o', '%j'])
+      l = p.readlines.map {|line| line.strip}
+      p.close
+      l
     else
       []
     end
index 4646f7afd151c1b6a0467521f2ff08841791c199..d091847df2a20a19bbf08d55a5a9c8e511b8d7b9 100644 (file)
@@ -208,14 +208,14 @@ class CrunchDispatchTest < ActiveSupport::TestCase
     act_as_system_user do
       dispatch = CrunchDispatch.new
 
-      squeue_resp = File.popen("echo zzzzz-8i9sb-pshmckwoma9plh7\necho thisisnotvalidjobuuid\necho zzzzz-8i9sb-4cf0abc123e809j\n")
-      scancel_resp = File.popen("true")
+      squeue_resp = IO.popen("echo zzzzz-8i9sb-pshmckwoma9plh7\necho thisisnotvalidjobuuid\necho zzzzz-8i9sb-4cf0abc123e809j\n")
+      scancel_resp = IO.popen("true")
 
-      File.expects(:popen).
+      IO.expects(:popen).
         with(['squeue', '-a', '-h', '-o', '%j']).
         returns(squeue_resp)
 
-      File.expects(:popen).
+      IO.expects(:popen).
         with(dispatch.sudo_preface + ['scancel', '-n', 'zzzzz-8i9sb-4cf0abc123e809j']).
         returns(scancel_resp)
 
index 8c6539e8dc62820e53076c108aee5c3dfdf32f52..311976501cda65792c23283b98b21882120b17c2 100644 (file)
@@ -38,12 +38,12 @@ class FailJobsTest < ActiveSupport::TestCase
   test 'cancel slurm jobs' do
     Rails.configuration.crunch_job_wrapper = :slurm_immediate
     Rails.configuration.crunch_job_user = 'foobar'
-    fake_squeue = File.popen("echo #{@job[:before_reboot].uuid}")
-    fake_scancel = File.popen("true")
-    File.expects(:popen).
+    fake_squeue = IO.popen("echo #{@job[:before_reboot].uuid}")
+    fake_scancel = IO.popen("true")
+    IO.expects(:popen).
       with(['squeue', '-a', '-h', '-o', '%j']).
       returns(fake_squeue)
-    File.expects(:popen).
+    IO.expects(:popen).
       with(includes('sudo', '-u', 'foobar', 'scancel', '-n', @job[:before_reboot].uuid)).
       returns(fake_scancel)
     @dispatch.fail_jobs(before: Time.at(BOOT_TIME).to_s)