Sha256: 7c2e2b78ca0c227ffcbcc360b74def4be081558aec6e90656796636b2c69710a

Contents?: true

Size: 1.83 KB

Versions: 28

Compression:

Stored size: 1.83 KB

Contents

require 'test_helper'

class Workhorse::EnqueuerTest < WorkhorseTest
  def test_basic
    assert_equal 0, Workhorse::DbJob.all.count
    Workhorse.enqueue BasicJob.new
    assert_equal 1, Workhorse::DbJob.all.count

    db_job = Workhorse::DbJob.first
    assert_equal 'waiting', db_job.state
    assert_equal Marshal.dump(BasicJob.new), db_job.handler
    assert_nil db_job.locked_by
    assert_nil db_job.queue
    assert_nil db_job.locked_at
    assert_nil db_job.started_at
    assert_nil db_job.last_error
    assert_not_nil db_job.created_at
    assert_not_nil db_job.updated_at
  end

  def test_with_queue
    assert_equal 0, Workhorse::DbJob.all.count
    Workhorse.enqueue BasicJob.new, queue: :q1
    assert_equal 1, Workhorse::DbJob.all.count

    db_job = Workhorse::DbJob.first
    assert_equal 'q1', db_job.queue
    assert_equal 0, db_job.priority
  end

  def test_with_priority
    Workhorse.enqueue BasicJob.new, priority: 1
    assert_equal 1, Workhorse::DbJob.first.priority
  end

  def test_with_description
    assert_equal 0, Workhorse::DbJob.all.count
    Workhorse.enqueue BasicJob.new, description: 'Lorem ipsum'
    assert_equal 1, Workhorse::DbJob.all.count

    db_job = Workhorse::DbJob.first
    assert_equal 'Lorem ipsum', db_job.description
  end

  def test_op
    Workhorse.enqueue_op DummyRailsOpsOp, { queue: :q1 }, foo: :bar

    w = Workhorse::Worker.new(queues: [:q1], polling_interval: 0.2)
    w.start
    sleep 0.2
    w.shutdown

    assert_equal 'succeeded', Workhorse::DbJob.first.state

    assert_equal [{ foo: :bar }], DummyRailsOpsOp.results
  end

  def test_op_without_params
    Workhorse.enqueue_op DummyRailsOpsOp, queue: :q1
    assert_equal 'q1', Workhorse::DbJob.first.queue
  end

  def test_op_without_params_and_queue
    Workhorse.enqueue_op DummyRailsOpsOp
    assert_nil Workhorse::DbJob.first.queue
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workhorse-1.2.24 test/workhorse/enqueuer_test.rb
workhorse-1.2.23 test/workhorse/enqueuer_test.rb
workhorse-1.2.22 test/workhorse/enqueuer_test.rb
workhorse-1.2.21 test/workhorse/enqueuer_test.rb
workhorse-1.2.20 test/workhorse/enqueuer_test.rb
workhorse-1.2.17 test/workhorse/enqueuer_test.rb
workhorse-1.2.17.rc2 test/workhorse/enqueuer_test.rb
workhorse-1.2.17.rc1 test/workhorse/enqueuer_test.rb
workhorse-1.2.17.rc0 test/workhorse/enqueuer_test.rb
workhorse-1.2.16 test/workhorse/enqueuer_test.rb
workhorse-1.2.15 test/workhorse/enqueuer_test.rb
workhorse-1.2.14 test/workhorse/enqueuer_test.rb
workhorse-1.2.13 test/workhorse/enqueuer_test.rb
workhorse-1.2.12 test/workhorse/enqueuer_test.rb
workhorse-1.2.11 test/workhorse/enqueuer_test.rb
workhorse-1.2.10 test/workhorse/enqueuer_test.rb
workhorse-1.2.9 test/workhorse/enqueuer_test.rb
workhorse-1.2.8 test/workhorse/enqueuer_test.rb
workhorse-1.2.7 test/workhorse/enqueuer_test.rb
workhorse-1.2.6 test/workhorse/enqueuer_test.rb