qs 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,152 @@
1
+ require 'assert'
2
+ require 'qs/worker'
3
+
4
+ require 'dat-worker-pool/worker'
5
+ require 'much-plugin'
6
+ require 'qs/daemon'
7
+ require 'qs/daemon_data'
8
+ require 'qs/logger'
9
+ require 'qs/queue_item'
10
+ require 'test/support/client_spy'
11
+
12
+ module Qs::Worker
13
+
14
+ class UnitTests < Assert::Context
15
+ include DatWorkerPool::Worker::TestHelpers
16
+
17
+ desc "Qs::Worker"
18
+ setup do
19
+ @worker_class = Class.new{ include Qs::Worker }
20
+ end
21
+ subject{ @worker_class }
22
+
23
+ should "use much-plugin" do
24
+ assert_includes MuchPlugin, Qs::Worker
25
+ end
26
+
27
+ should "be a dat-worker-pool worker" do
28
+ assert_includes DatWorkerPool::Worker, subject
29
+ end
30
+
31
+ end
32
+
33
+ class InitTests < UnitTests
34
+ desc "when init"
35
+ setup do
36
+ @ph_spy = nil
37
+ Assert.stub(Qs::PayloadHandler, :new) do |*args|
38
+ @ph_spy = PayloadHandlerSpy.new(*args)
39
+ end
40
+
41
+ @daemon_data = Qs::DaemonData.new
42
+ @client_spy = ClientSpy.new
43
+ @worker_available = Qs::Daemon::WorkerAvailable.new
44
+ @queue_item = Qs::QueueItem.new(Factory.string, Factory.string)
45
+
46
+ @worker_params = {
47
+ :qs_daemon_data => @daemon_data,
48
+ :qs_client => @client_spy,
49
+ :qs_worker_available => @worker_available,
50
+ :qs_logger => Qs::NullLogger.new
51
+ }
52
+ @runner = test_runner(@worker_class, :params => @worker_params)
53
+ end
54
+ subject{ @runner }
55
+
56
+ should "build and run a payload handler when it processes a queue item" do
57
+ subject.work(@queue_item)
58
+
59
+ assert_not_nil @ph_spy
60
+ assert_equal @daemon_data, @ph_spy.daemon_data
61
+ assert_equal @queue_item, @ph_spy.queue_item
62
+ assert_true @ph_spy.run_called
63
+ end
64
+
65
+ should "signal that a worker is available when it becomes available" do
66
+ signal_called = false
67
+ Assert.stub(@worker_available, :signal){ signal_called = true }
68
+
69
+ subject.make_available
70
+ assert_true signal_called
71
+ end
72
+
73
+ should "requeue a queue item if an error occurs before its started" do
74
+ exception = Factory.exception
75
+ @queue_item.started = false
76
+ subject.error(exception, @queue_item)
77
+
78
+ call = @client_spy.calls.last
79
+ assert_equal :prepend, call.command
80
+ assert_equal @queue_item.queue_redis_key, call.args.first
81
+ assert_equal @queue_item.encoded_payload, call.args.last
82
+ end
83
+
84
+ should "not requeue a queue item if an error occurs after its started" do
85
+ exception = Factory.exception
86
+ @queue_item.started = true
87
+ subject.error(exception, @queue_item)
88
+
89
+ assert_empty @client_spy.calls
90
+ end
91
+
92
+ should "do nothing if not passed a queue item" do
93
+ assert_nothing_raised{ subject.error(Factory.exception) }
94
+ assert_empty @client_spy.calls
95
+ end
96
+
97
+ end
98
+
99
+ class TestHelpersTests < UnitTests
100
+ desc "TestHelpers"
101
+ setup do
102
+ @context_class = Class.new{ include TestHelpers }
103
+ @context = @context_class.new
104
+ end
105
+ subject{ @context }
106
+
107
+ should have_imeths :test_runner
108
+
109
+ should "mixin dat-worker-pool's worker test helpers" do
110
+ assert_includes DatWorkerPool::Worker::TestHelpers, @context_class
111
+ end
112
+
113
+ should "super worker params needed to run a qs worker" do
114
+ runner = @context.test_runner(@worker_class)
115
+ worker_params = runner.dwp_runner.worker_params
116
+
117
+ assert_instance_of Qs::DaemonData, worker_params[:qs_daemon_data]
118
+ assert_instance_of Qs::TestClient, worker_params[:qs_client]
119
+ exp = Qs::Daemon::WorkerAvailable
120
+ assert_instance_of exp, worker_params[:qs_worker_available]
121
+ assert_instance_of Qs::NullLogger, worker_params[:qs_logger]
122
+ end
123
+
124
+ should "allow providing custom worker params for running a qs worker" do
125
+ @params = {
126
+ :qs_daemon_data => Factory.string,
127
+ :qs_client => Factory.string,
128
+ :qs_worker_available => Factory.string,
129
+ :qs_logger => Factory.string
130
+ }
131
+ runner = @context.test_runner(@worker_class, :params => @params)
132
+
133
+ assert_equal @params, runner.dwp_runner.worker_params
134
+ end
135
+
136
+ end
137
+
138
+ class PayloadHandlerSpy
139
+ attr_reader :daemon_data, :queue_item, :run_called
140
+
141
+ def initialize(daemon_data, queue_item)
142
+ @daemon_data = daemon_data
143
+ @queue_item = queue_item
144
+ @run_called = false
145
+ end
146
+
147
+ def run
148
+ @run_called = true
149
+ end
150
+ end
151
+
152
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
8
+ - 6
9
9
  - 0
10
- version: 0.5.0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2015-09-08 00:00:00 Z
19
+ date: 2015-11-30 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  requirement: &id001 !ruby/object:Gem::Requirement
@@ -24,11 +24,11 @@ dependencies:
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- hash: 1
27
+ hash: 7
28
28
  segments:
29
29
  - 0
30
- - 5
31
- version: "0.5"
30
+ - 6
31
+ version: "0.6"
32
32
  type: :runtime
33
33
  name: dat-worker-pool
34
34
  version_requirements: *id001
@@ -50,6 +50,21 @@ dependencies:
50
50
  prerelease: false
51
51
  - !ruby/object:Gem::Dependency
52
52
  requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 9
58
+ segments:
59
+ - 0
60
+ - 1
61
+ version: "0.1"
62
+ type: :runtime
63
+ name: much-plugin
64
+ version_requirements: *id003
65
+ prerelease: false
66
+ - !ruby/object:Gem::Dependency
67
+ requirement: &id004 !ruby/object:Gem::Requirement
53
68
  none: false
54
69
  requirements:
55
70
  - - ~>
@@ -61,10 +76,10 @@ dependencies:
61
76
  version: "1.1"
62
77
  type: :runtime
63
78
  name: ns-options
64
- version_requirements: *id003
79
+ version_requirements: *id004
65
80
  prerelease: false
66
81
  - !ruby/object:Gem::Dependency
67
- requirement: &id004 !ruby/object:Gem::Requirement
82
+ requirement: &id005 !ruby/object:Gem::Requirement
68
83
  none: false
69
84
  requirements:
70
85
  - - ~>
@@ -76,10 +91,10 @@ dependencies:
76
91
  version: "1.2"
77
92
  type: :runtime
78
93
  name: SystemTimer
79
- version_requirements: *id004
94
+ version_requirements: *id005
80
95
  prerelease: false
81
96
  - !ruby/object:Gem::Dependency
82
- requirement: &id005 !ruby/object:Gem::Requirement
97
+ requirement: &id006 !ruby/object:Gem::Requirement
83
98
  none: false
84
99
  requirements:
85
100
  - - ~>
@@ -91,22 +106,22 @@ dependencies:
91
106
  version: "2.15"
92
107
  type: :development
93
108
  name: assert
94
- version_requirements: *id005
109
+ version_requirements: *id006
95
110
  prerelease: false
96
111
  - !ruby/object:Gem::Dependency
97
- requirement: &id006 !ruby/object:Gem::Requirement
112
+ requirement: &id007 !ruby/object:Gem::Requirement
98
113
  none: false
99
114
  requirements:
100
115
  - - ~>
101
116
  - !ruby/object:Gem::Version
102
- hash: 5
117
+ hash: 7
103
118
  segments:
104
- - 2
105
119
  - 3
106
- version: "2.3"
120
+ - 0
121
+ version: "3.0"
107
122
  type: :development
108
123
  name: scmd
109
- version_requirements: *id006
124
+ version_requirements: *id007
110
125
  prerelease: false
111
126
  description: Define message queues. Process jobs and events. Profit.
112
127
  email:
@@ -121,7 +136,7 @@ extra_rdoc_files: []
121
136
  files:
122
137
  - .gitignore
123
138
  - Gemfile
124
- - LICENSE.txt
139
+ - LICENSE
125
140
  - README.md
126
141
  - Rakefile
127
142
  - bench/config.qs
@@ -142,11 +157,9 @@ files:
142
157
  - lib/qs/error_handler.rb
143
158
  - lib/qs/event.rb
144
159
  - lib/qs/event_handler.rb
145
- - lib/qs/event_handler_test_helpers.rb
146
160
  - lib/qs/io_pipe.rb
147
161
  - lib/qs/job.rb
148
162
  - lib/qs/job_handler.rb
149
- - lib/qs/job_handler_test_helpers.rb
150
163
  - lib/qs/logger.rb
151
164
  - lib/qs/message.rb
152
165
  - lib/qs/message_handler.rb
@@ -162,10 +175,12 @@ files:
162
175
  - lib/qs/runner.rb
163
176
  - lib/qs/test_runner.rb
164
177
  - lib/qs/version.rb
178
+ - lib/qs/worker.rb
165
179
  - log/.gitkeep
166
180
  - qs.gemspec
167
181
  - test/helper.rb
168
182
  - test/support/app_daemon.rb
183
+ - test/support/client_spy.rb
169
184
  - test/support/config.qs
170
185
  - test/support/config_files/empty.qs
171
186
  - test/support/config_files/invalid.qs
@@ -173,6 +188,7 @@ files:
173
188
  - test/support/config_invalid_run.qs
174
189
  - test/support/config_no_run.qs
175
190
  - test/support/factory.rb
191
+ - test/support/message_handler.rb
176
192
  - test/support/pid_file_spy.rb
177
193
  - test/support/runner_spy.rb
178
194
  - test/system/daemon_tests.rb
@@ -186,11 +202,9 @@ files:
186
202
  - test/unit/dispatch_job_tests.rb
187
203
  - test/unit/dispatcher_queue_tests.rb
188
204
  - test/unit/error_handler_tests.rb
189
- - test/unit/event_handler_test_helpers_tests.rb
190
205
  - test/unit/event_handler_tests.rb
191
206
  - test/unit/event_tests.rb
192
207
  - test/unit/io_pipe_tests.rb
193
- - test/unit/job_handler_test_helper_tests.rb
194
208
  - test/unit/job_handler_tests.rb
195
209
  - test/unit/job_tests.rb
196
210
  - test/unit/logger_tests.rb
@@ -208,6 +222,7 @@ files:
208
222
  - test/unit/route_tests.rb
209
223
  - test/unit/runner_tests.rb
210
224
  - test/unit/test_runner_tests.rb
225
+ - test/unit/worker_tests.rb
211
226
  - tmp/.gitkeep
212
227
  homepage: http://github.com/redding/qs
213
228
  licenses:
@@ -238,13 +253,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
253
  requirements: []
239
254
 
240
255
  rubyforge_project:
241
- rubygems_version: 1.8.29
256
+ rubygems_version: 1.8.25
242
257
  signing_key:
243
258
  specification_version: 3
244
259
  summary: Define message queues. Process jobs and events. Profit.
245
260
  test_files:
246
261
  - test/helper.rb
247
262
  - test/support/app_daemon.rb
263
+ - test/support/client_spy.rb
248
264
  - test/support/config.qs
249
265
  - test/support/config_files/empty.qs
250
266
  - test/support/config_files/invalid.qs
@@ -252,6 +268,7 @@ test_files:
252
268
  - test/support/config_invalid_run.qs
253
269
  - test/support/config_no_run.qs
254
270
  - test/support/factory.rb
271
+ - test/support/message_handler.rb
255
272
  - test/support/pid_file_spy.rb
256
273
  - test/support/runner_spy.rb
257
274
  - test/system/daemon_tests.rb
@@ -265,11 +282,9 @@ test_files:
265
282
  - test/unit/dispatch_job_tests.rb
266
283
  - test/unit/dispatcher_queue_tests.rb
267
284
  - test/unit/error_handler_tests.rb
268
- - test/unit/event_handler_test_helpers_tests.rb
269
285
  - test/unit/event_handler_tests.rb
270
286
  - test/unit/event_tests.rb
271
287
  - test/unit/io_pipe_tests.rb
272
- - test/unit/job_handler_test_helper_tests.rb
273
288
  - test/unit/job_handler_tests.rb
274
289
  - test/unit/job_tests.rb
275
290
  - test/unit/logger_tests.rb
@@ -287,3 +302,4 @@ test_files:
287
302
  - test/unit/route_tests.rb
288
303
  - test/unit/runner_tests.rb
289
304
  - test/unit/test_runner_tests.rb
305
+ - test/unit/worker_tests.rb
@@ -1,17 +0,0 @@
1
- require 'qs/test_runner'
2
-
3
- module Qs::EventHandler
4
-
5
- module TestHelpers
6
-
7
- def test_runner(handler_class, args = nil)
8
- Qs::EventTestRunner.new(handler_class, args)
9
- end
10
-
11
- def test_handler(handler_class, args = nil)
12
- test_runner(handler_class, args).handler
13
- end
14
-
15
- end
16
-
17
- end
@@ -1,17 +0,0 @@
1
- require 'qs/test_runner'
2
-
3
- module Qs::JobHandler
4
-
5
- module TestHelpers
6
-
7
- def test_runner(handler_class, args = nil)
8
- Qs::JobTestRunner.new(handler_class, args)
9
- end
10
-
11
- def test_handler(handler_class, args = nil)
12
- test_runner(handler_class, args).handler
13
- end
14
-
15
- end
16
-
17
- end
@@ -1,55 +0,0 @@
1
- require 'assert'
2
- require 'qs/event_handler_test_helpers'
3
-
4
- require 'qs/event_handler'
5
- require 'qs/test_runner'
6
- require 'test/support/runner_spy'
7
-
8
- module Qs::EventHandler::TestHelpers
9
-
10
- class UnitTests < Assert::Context
11
- desc "Qs::TestHelpers"
12
- setup do
13
- @test_helpers = Qs::EventHandler::TestHelpers
14
- end
15
- subject{ @test_helpers }
16
-
17
- end
18
-
19
- class MixinTests < UnitTests
20
- desc "as a mixin"
21
- setup do
22
- @handler_class = Class.new
23
- @args = { Factory.string => Factory.string }
24
-
25
- @runner_spy = nil
26
- Assert.stub(Qs::EventTestRunner, :new) do |*args|
27
- @runner_spy = RunnerSpy.new(*args)
28
- end
29
-
30
- context_class = Class.new{ include Qs::EventHandler::TestHelpers }
31
- @context = context_class.new
32
- end
33
- subject{ @context }
34
-
35
- should have_imeths :test_runner, :test_handler
36
-
37
- should "build an event test runner for a given handler using `test_runner`" do
38
- result = subject.test_runner(@handler_class, @args)
39
-
40
- assert_not_nil @runner_spy
41
- assert_equal @handler_class, @runner_spy.handler_class
42
- assert_equal @args, @runner_spy.args
43
- assert_equal @runner_spy, result
44
- end
45
-
46
- should "return an initialized handler instance using `test_handler`" do
47
- result = subject.test_handler(@handler_class, @args)
48
-
49
- assert_not_nil @runner_spy
50
- assert_equal @runner_spy.handler, result
51
- end
52
-
53
- end
54
-
55
- end
@@ -1,55 +0,0 @@
1
- require 'assert'
2
- require 'qs/job_handler_test_helpers'
3
-
4
- require 'qs/job_handler'
5
- require 'qs/test_runner'
6
- require 'test/support/runner_spy'
7
-
8
- module Qs::JobHandler::TestHelpers
9
-
10
- class UnitTests < Assert::Context
11
- desc "Qs::TestHelpers"
12
- setup do
13
- @test_helpers = Qs::JobHandler::TestHelpers
14
- end
15
- subject{ @test_helpers }
16
-
17
- end
18
-
19
- class MixinTests < UnitTests
20
- desc "as a mixin"
21
- setup do
22
- @handler_class = Class.new
23
- @args = { Factory.string => Factory.string }
24
-
25
- @runner_spy = nil
26
- Assert.stub(Qs::JobTestRunner, :new) do |*args|
27
- @runner_spy = RunnerSpy.new(*args)
28
- end
29
-
30
- context_class = Class.new{ include Qs::JobHandler::TestHelpers }
31
- @context = context_class.new
32
- end
33
- subject{ @context }
34
-
35
- should have_imeths :test_runner, :test_handler
36
-
37
- should "build a job test runner for a given handler using `test_runner`" do
38
- result = subject.test_runner(@handler_class, @args)
39
-
40
- assert_not_nil @runner_spy
41
- assert_equal @handler_class, @runner_spy.handler_class
42
- assert_equal @args, @runner_spy.args
43
- assert_equal @runner_spy, result
44
- end
45
-
46
- should "return an initialized handler instance using `test_handler`" do
47
- result = subject.test_handler(@handler_class, @args)
48
-
49
- assert_not_nil @runner_spy
50
- assert_equal @runner_spy.handler, result
51
- end
52
-
53
- end
54
-
55
- end