Sha256: fd9093dd4af0d10144b5deb7abf8a3a9798444ca5f8373f2d9b97919bd7fcef1

Contents?: true

Size: 1.64 KB

Versions: 31

Compression:

Stored size: 1.64 KB

Contents

require File.join(File.dirname(__FILE__), 'test_helper')

class WorkerTest < Test::Unit::TestCase
  context "with a file to test and a destination to verify" do
    setup do
      FileUtils.rm_f(target_file)
    end

    teardown do
      FileUtils.rm_f(target_file)
    end

    # run the worker in the foreground and the requests in the background
    should "run a test in the foreground" do
      num_runners = 4
      pipe = Hydra::Pipe.new
      child = Process.fork do
        request_a_file_and_verify_completion(pipe, num_runners)
      end
      run_the_worker(pipe, num_runners)
      Process.wait(child)
    end

    # inverse of the above test to run the worker in the background
    should "run a test in the background" do
      num_runners = 4
      pipe = Hydra::Pipe.new
      child = Process.fork do
        run_the_worker(pipe, num_runners)
      end
      request_a_file_and_verify_completion(pipe, num_runners)
      Process.wait(child)
    end
  end

  module WorkerTestHelper
    def run_the_worker(pipe, num_runners)
      pipe.identify_as_child
      Hydra::Worker.new({:io => pipe, :runners => num_runners})
    end

    def request_a_file_and_verify_completion(pipe, num_runners)
      pipe.identify_as_parent
      num_runners.times do
        assert pipe.gets.is_a?(Hydra::Messages::Worker::RequestFile)
      end
      pipe.write(Hydra::Messages::Master::RunFile.new(:file => test_file))

      assert pipe.gets.is_a?(Hydra::Messages::Worker::Results)

      pipe.write(Hydra::Messages::Master::Shutdown.new)

      assert File.exists?(target_file)
      assert_equal "HYDRA", File.read(target_file)
    end
  end
  include WorkerTestHelper
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
hydra-0.19.0 test/worker_test.rb
hydra-0.18.0 test/worker_test.rb
sskirby-hydra-0.17.1 test/worker_test.rb
sskirby-hydra-0.16.10 test/worker_test.rb
hydra-0.17.0 test/worker_test.rb
sskirby-hydra-0.16.9 test/worker_test.rb
hydra-0.16.7 test/worker_test.rb
hydra-0.16.6 test/worker_test.rb
hydra-0.16.5 test/worker_test.rb
hydra-0.16.4 test/worker_test.rb
hydra-0.16.3 test/worker_test.rb
hydra-0.16.2 test/worker_test.rb
hydra-0.16.1 test/worker_test.rb
hydra-0.16.0 test/worker_test.rb
hydra-0.15.1 test/worker_test.rb
hydra-0.15.0 test/worker_test.rb
hydra-0.14.1 test/worker_test.rb
hydra-0.14.0 test/worker_test.rb
hydra-0.13.0 test/worker_test.rb
hydra-0.12.0 test/worker_test.rb