Sha256: 7091153f813392b5e4e9ce6455c997780a9ae730af931f61adfd4dc380f222bb

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

require File.expand_path("../../spec_helper", __FILE__)

module JCukeForker
  describe TaskManager do
    let(:worker_path) { '/tmp/jcukeforker-test-socket' }
    let(:task) { {name: 'my task'} }
    let(:mock_socket) { double('socket', :puts => nil) }

    it "can register a worker" do

      UNIXSocket.stub(:open).and_return(mock_socket)
      expect(mock_socket).to receive(:puts).with(task.to_json)

      task_manager = TaskManager.new
      task_manager.add task
      task_manager.on_worker_register worker_path
    end

    it "can finish task" do

      expect(mock_socket).to receive(:puts).with(task.to_json)

      task_manager = TaskManager.new
      task_manager.add task
      task_manager.instance_variable_get(:@worker_sockets)[worker_path] = mock_socket
      task_manager.on_task_finished worker_path, nil, nil
    end

    it "can close dead worker" do

      expect(mock_socket).to receive(:close)

      task_manager = TaskManager.new
      task_manager.add task
      task_manager.instance_variable_get(:@worker_sockets)[worker_path] = mock_socket
      task_manager.on_worker_dead worker_path
    end

    it "can send '__KILL__' when there are no tasks left" do

      expect(mock_socket).to receive(:puts).with('__KILL__')

      task_manager = TaskManager.new
      task_manager.instance_variable_get(:@worker_sockets)[worker_path] = mock_socket
      task_manager.on_task_finished worker_path, nil, nil
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jcukeforker-0.2.4 spec/jcukeforker/task_manager_spec.rb
jcukeforker-0.2.3 spec/jcukeforker/task_manager_spec.rb
jcukeforker-0.2.2 spec/jcukeforker/task_manager_spec.rb