1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
Commit graph

41 commits

Author SHA1 Message Date
Brandon Hilkert
ed55232a78 Create separate data structures for queue and worker
Rspec allows expectations to be written using change(LogWorker.jobs,
:size). The result of .jobs in this case was a derived array that wasn't
manipulated under the covers. So when Rspec went to check the size of
the array after the fact, it appeared that nothing had changed.

This sets up a true array for the jobs for a single worker and
pulls jobs off that array so rspec can properly make assertions.
2015-11-25 07:15:34 -05:00
Brandon Hilkert
6b277de4d5 Revert "Revert "Merge pull request from mperham/queue-testing-api""
This reverts commit 56ebcfd161.
2015-11-17 13:07:30 -05:00
Brandon Hilkert
56ebcfd161 Revert "Merge pull request from mperham/queue-testing-api"
This reverts commit df739ca968, reversing
changes made to dbd8bed17c.
2015-11-17 12:44:56 -05:00
Brandon Hilkert
3cc996aaef Revert "Merge pull request from mhenrixon/master"
This reverts commit fdb7ded6d8, reversing
changes made to df739ca968.
2015-11-17 12:44:40 -05:00
Mikael Henriksson
d95f22e685 Ensure comparison between strings
I have a lot of symbols in my code and so do others. This pull request
ensure that testing queus and jobs (just like production) are only ever
compared as strings.
2015-11-14 13:54:01 +01:00
Brandon Hilkert
4bac132ded Send inline jobs through the same interface to process 2015-11-13 17:50:07 -05:00
Brandon Hilkert
df755bbeef Unique all workers and ensure symbol queues are stringified via testing
API
2015-11-13 17:08:54 -05:00
Brandon Hilkert
19f9e05d88 Run job inline during testing inline 2015-11-13 16:38:01 -05:00
Brandon Hilkert
9bad77f8a3 Update documentation 2015-11-13 16:30:22 -05:00
Brandon Hilkert
ec006873ac Can't use constantize if the worker doesn't exist 2015-11-13 16:20:15 -05:00
Brandon Hilkert
321234e81d Implements queue-based testing API
When using the Sidekiq::Client API to push jobs on to the queue, it's
not ideal to assert the size of the queue from the perspective of a
worker because the worker may not exist in the application.

This API implements a testing API from the perspective of a queue. The
existing Worker-based testing API remains unchanged, but leverages the
job hash implemented through the Sidekiq::Queues class.

Examples:

    assert_equal 1, Sidekiq::Queues["default"].size
    assert_equal "SpecialWorker", Sidekiq::Queues["default"].first["class"]
    Sidekiq::Queues["default"].clear
    Sidekiq::Queues.clear_all
2015-11-13 15:25:10 -05:00
Ryan Schlesinger
a71e1bbe18 Add middleware stack to Testing 2015-09-04 15:35:33 -07:00
Michal Cichra
8cd70cfa83 Set Worker's bid when using Sidekiq::Testing
Closes 
2015-05-13 09:52:44 +02:00
Mike Perham
cf834366d1 Merge pull request from aprescott/enqueue-and-perform-for-inline
Rely on perform_one for inline testing
2014-12-18 10:20:51 -08:00
Abdelkader Boudih
de42941e48 yield instead of block.call 2014-10-09 14:04:00 +00:00
Adam Prescott
03fb5f2346 Rely on perform_one for inline testing.
Inline testing currently overrides perform_async to simply directly call

    SomeJob.new.perform(*args)

after round-tripping *args through JSON serialization/deserialization
and setting up a fake worker.jid value.

After Sidekiq issue 1938, most (all?) other places now use execute_job
instead, which indirectly calls SomeJob.new.perform(*args).

testing.rb defines a perform_one which is one of the places where the
new execute_job method is used. It also takes care of setting
worker.jid.

This change replaces the inline testing mode from a direct
SomeJob.new.perform method call to instead:

    1. Place a job on the faked array queue, at the front of the list.
    2. Immediately call perform_one, to take the job off the front of
       the list.

This reduces the duplication around what it means to execute a job,
makes the usage of execute_job consistent across applications, and
improves inline testing's mirroring of how the job would actually be
run -- by "placing" it on a queue and then "pulling" the job off the
queue straight away.

As a bonus, any third-party gems which provide an implementation of
execute_job (such as in issue 1938) can test that their execute_job is
working by using perform_async with inline testing, instead of manually
calling perform_one in the fake testing mode or disabling Sidekiq
testing entirely.
2014-09-10 18:09:57 -04:00
jejacks0n
7714d19619 extracts worker.perform so call can be enhanced
- defines execute_job as an API hook
2014-09-10 11:13:24 -06:00
Mike Perham
274fda8c2d testing requires client and worker, fixes 2014-04-09 15:31:09 -07:00
Mike Perham
b0107b5d99 Add JID for inline testing, fixes 2014-01-30 09:22:07 -08:00
Mike Perham
b76ac9464c Rejigger Sidekiq::Client to be instance-based, 2013-10-23 21:49:37 -07:00
Ryan Schlesinger
fd0232eb15 Add dynamic testing
In addition to requiring 'sidekiq/testing' and 'sidekiq/testing/inline',
a user can also call the following methods to control the test harness:

Sidekiq::Testing.fake!
Sidekiq::Testing.inline!
Sidekiq::Testing.disable!

Each of the above methods also accepts a block to execute within that
context before reverting to the state present before method invocation.

To query the current state, use the following methods:

Sidekiq::Testing.enabled?
Sidekiq::Testing.disabled?
Sidekiq::Testing.fake?
Sidekiq::Testing.inline?

Closes 
2013-09-23 12:07:23 -07:00
Reinaldo Mello
d8c4c80d5d Sets worker JID before performing job during tests 2013-07-02 11:43:59 -03:00
Mike Perham
919e3c7da9 More cleanup 2013-05-30 21:16:56 -07:00
awaw
9724c703ab better formatting for readability 2013-05-31 02:59:57 +08:00
awaw
8e98314bc9 raise error upon empty queue 2013-05-31 02:39:01 +08:00
awaw
ad4a0b9c93 rename shift_and_perform to perform_one 2013-05-31 00:28:47 +08:00
awaw
4cfa817bfb add testing method shift_and_perform 2013-05-30 13:06:08 +08:00
Mike Perham
07a2781ac0 Update sidekiq/testing to execute almost all of the client api, fixes
This should ensure tests reproduce a maximum amount of the implementation details that you'll see in production.
2013-03-27 21:24:47 -07:00
João Daniel
8dd3660646 fixing return for client_push in testing 2013-02-28 18:42:08 -03:00
João Daniel
c8e510d1af return array position in testing push 2013-02-28 17:55:52 -03:00
Thibaud Guillaume-Gentil
d19af9c102 Ensure that all jobs are drained
Even when workers create new jobs when drained.
2012-11-01 15:49:35 +01:00
Samuel Cochran
2907777987 Add Worker clear_all and drain_all 2012-10-19 12:16:28 +08:00
Dimitrij Denissenko
8dbea0fbe1 DRY testing API 2012-06-28 08:46:18 +01:00
Mike Perham
de616bb188 Update testing to support scheduled API changes, fixes 2012-06-03 11:03:22 -07:00
Pan Thomakos
82c43d2447 Renamed perform to drain to match Rails 4 API. 2012-05-02 10:59:31 -07:00
Pan Thomakos
b9bfc03c68 Add perform method to workers in tests.
The `#perform` method allows workers to be execute all their previously
queued jobs at once.
2012-05-02 10:45:05 -07:00
Mike Perham
ff3417c381 delayed example for testing 2012-04-05 20:06:47 -07:00
Mike Perham
b210dd788c Update Sidekiq logging to use standard Ruby logger 2012-02-14 09:00:26 -08:00
Mike Perham
a8226227c4 Update testing infrastructure 2012-02-10 20:30:14 -08:00
Mike Perham
69b00cfe50 Minimize annoying warnings 2012-02-09 22:33:36 -08:00
Mike Perham
f89eedf326 Add new sidekiq/testing feature.
This makes job processing synchronous when required.
2012-02-09 21:46:44 -08:00