qs 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,11 +2,13 @@ require 'assert'
2
2
  require 'qs/daemon'
3
3
 
4
4
  require 'dat-worker-pool/worker_pool_spy'
5
+ require 'much-plugin'
5
6
  require 'ns-options/assert_macros'
6
7
  require 'thread'
7
8
  require 'qs/client'
8
9
  require 'qs/queue'
9
10
  require 'qs/queue_item'
11
+ require 'test/support/client_spy'
10
12
 
11
13
  module Qs::Daemon
12
14
 
@@ -19,13 +21,16 @@ module Qs::Daemon
19
21
 
20
22
  should have_imeths :configuration
21
23
  should have_imeths :name, :pid_file
22
- should have_imeths :min_workers, :max_workers, :workers
23
- should have_imeths :on_worker_start, :on_worker_shutdown
24
- should have_imeths :on_worker_sleep, :on_worker_wakeup
24
+ should have_imeths :worker_class, :worker_params
25
+ should have_imeths :num_workers, :workers
25
26
  should have_imeths :verbose_logging, :logger
26
27
  should have_imeths :shutdown_timeout
27
28
  should have_imeths :init, :error, :queue
28
29
 
30
+ should "use much-plugin" do
31
+ assert_includes MuchPlugin, Qs::Daemon
32
+ end
33
+
29
34
  should "know its configuration" do
30
35
  config = subject.configuration
31
36
  assert_instance_of Configuration, config
@@ -47,43 +52,32 @@ module Qs::Daemon
47
52
  assert_equal expected, subject.pid_file
48
53
  end
49
54
 
50
- should "allow reading/writing its configuration min workers" do
51
- new_min_workers = Factory.integer
52
- subject.min_workers(new_min_workers)
53
- assert_equal new_min_workers, subject.configuration.min_workers
54
- assert_equal new_min_workers, subject.min_workers
55
+ should "allow reading/writing its configuration worker class" do
56
+ new_worker_class = Class.new
57
+ subject.worker_class(new_worker_class)
58
+ assert_equal new_worker_class, subject.configuration.worker_class
59
+ assert_equal new_worker_class, subject.worker_class
55
60
  end
56
61
 
57
- should "allow reading/writing its configuration max workers" do
58
- new_max_workers = Factory.integer
59
- subject.max_workers(new_max_workers)
60
- assert_equal new_max_workers, subject.configuration.max_workers
61
- assert_equal new_max_workers, subject.max_workers
62
+ should "allow reading/writing its configuration worker params" do
63
+ new_worker_params = { Factory.string => Factory.string }
64
+ subject.worker_params(new_worker_params)
65
+ assert_equal new_worker_params, subject.configuration.worker_params
66
+ assert_equal new_worker_params, subject.worker_params
62
67
  end
63
68
 
64
- should "allow reading/writing its configuration workers" do
65
- new_workers = Factory.integer
66
- subject.workers(new_workers)
67
- assert_equal new_workers, subject.configuration.min_workers
68
- assert_equal new_workers, subject.configuration.max_workers
69
- assert_equal new_workers, subject.min_workers
70
- assert_equal new_workers, subject.max_workers
69
+ should "allow reading/writing its configuration num workers" do
70
+ new_num_workers = Factory.integer
71
+ subject.num_workers(new_num_workers)
72
+ assert_equal new_num_workers, subject.configuration.num_workers
73
+ assert_equal new_num_workers, subject.num_workers
71
74
  end
72
75
 
73
- should "allow reading/writing its configuration worker procs" do
74
- p = proc{}
75
-
76
- subject.on_worker_start(&p)
77
- assert_equal [p], subject.configuration.worker_start_procs
78
-
79
- subject.on_worker_shutdown(&p)
80
- assert_equal [p], subject.configuration.worker_shutdown_procs
81
-
82
- subject.on_worker_sleep(&p)
83
- assert_equal [p], subject.configuration.worker_sleep_procs
84
-
85
- subject.on_worker_wakeup(&p)
86
- assert_equal [p], subject.configuration.worker_wakeup_procs
76
+ should "alias workers as num workers" do
77
+ new_workers = Factory.integer
78
+ subject.workers(new_workers)
79
+ assert_equal new_workers, subject.configuration.num_workers
80
+ assert_equal new_workers, subject.workers
87
81
  end
88
82
 
89
83
  should "allow reading/writing its configuration verbose logging" do
@@ -134,20 +128,12 @@ module Qs::Daemon
134
128
 
135
129
  @daemon_class.name Factory.string
136
130
  @daemon_class.pid_file Factory.file_path
131
+ @daemon_class.worker_params(Factory.string => Factory.string)
137
132
  @daemon_class.workers Factory.integer
138
133
  @daemon_class.verbose_logging Factory.boolean
139
134
  @daemon_class.shutdown_timeout Factory.integer
140
135
  @daemon_class.error{ Factory.string }
141
136
 
142
- @start_procs = Factory.integer(3).times.map{ proc{} }
143
- @shutdown_procs = Factory.integer(3).times.map{ proc{} }
144
- @sleep_procs = Factory.integer(3).times.map{ proc{} }
145
- @wakeup_procs = Factory.integer(3).times.map{ proc{} }
146
- @start_procs.each { |p| @daemon_class.on_worker_start(&p) }
147
- @shutdown_procs.each { |p| @daemon_class.on_worker_shutdown(&p) }
148
- @sleep_procs.each { |p| @daemon_class.on_worker_sleep(&p) }
149
- @wakeup_procs.each { |p| @daemon_class.on_worker_wakeup(&p) }
150
-
151
137
  @queue = Qs::Queue.new do
152
138
  name(Factory.string)
153
139
  job 'test', TestHandler.to_s
@@ -159,12 +145,15 @@ module Qs::Daemon
159
145
  @client_spy = ClientSpy.new(*args)
160
146
  end
161
147
 
162
- @worker_pool_spy = nil
163
- @worker_available = true
164
- Assert.stub(::DatWorkerPool, :new) do |*args, &block|
165
- @worker_pool_spy = DatWorkerPool::WorkerPoolSpy.new(*args, &block)
166
- @worker_pool_spy.worker_available = !!@worker_available
167
- @worker_pool_spy
148
+ @worker_available = WorkerAvailable.new
149
+ Assert.stub(WorkerAvailable, :new){ @worker_available }
150
+
151
+ @wp_spy = nil
152
+ @wp_worker_available = true
153
+ Assert.stub(DatWorkerPool, :new) do |*args|
154
+ @wp_spy = DatWorkerPool::WorkerPoolSpy.new(*args)
155
+ @wp_spy.worker_available = !!@wp_worker_available
156
+ @wp_spy
168
157
  end
169
158
  end
170
159
  teardown do
@@ -176,14 +165,8 @@ module Qs::Daemon
176
165
  class InitTests < InitSetupTests
177
166
  desc "when init"
178
167
  setup do
179
- @current_env_process_label = ENV['QS_PROCESS_LABEL']
180
- ENV['QS_PROCESS_LABEL'] = Factory.string
181
-
182
168
  @daemon = @daemon_class.new
183
169
  end
184
- teardown do
185
- ENV['QS_PROCESS_LABEL'] = @current_env_process_label
186
- end
187
170
  subject{ @daemon }
188
171
 
189
172
  should have_readers :daemon_data, :logger
@@ -206,15 +189,10 @@ module Qs::Daemon
206
189
 
207
190
  assert_instance_of Qs::DaemonData, data
208
191
  assert_equal configuration.name, data.name
209
- assert_equal configuration.process_label, data.process_label
210
192
  assert_equal configuration.pid_file, data.pid_file
211
- assert_equal configuration.min_workers, data.min_workers
212
- assert_equal configuration.max_workers, data.max_workers
213
-
214
- assert_equal configuration.worker_start_procs, data.worker_start_procs
215
- assert_equal configuration.worker_shutdown_procs, data.worker_shutdown_procs
216
- assert_equal configuration.worker_sleep_procs, data.worker_sleep_procs
217
- assert_equal configuration.worker_wakeup_procs, data.worker_wakeup_procs
193
+ assert_equal configuration.worker_class, data.worker_class
194
+ assert_equal configuration.worker_params, data.worker_params
195
+ assert_equal configuration.num_workers, data.num_workers
218
196
 
219
197
  assert_equal configuration.verbose_logging, data.verbose_logging
220
198
  assert_equal configuration.shutdown_timeout, data.shutdown_timeout
@@ -244,11 +222,28 @@ module Qs::Daemon
244
222
  assert_not_nil @client_spy
245
223
  exp = Qs.redis_config.merge({
246
224
  :timeout => 1,
247
- :size => subject.daemon_data.max_workers + 1
225
+ :size => subject.daemon_data.num_workers + 1
248
226
  })
249
227
  assert_equal exp, @client_spy.redis_config
250
228
  end
251
229
 
230
+ should "build a worker pool" do
231
+ data = subject.daemon_data
232
+
233
+ assert_not_nil @wp_spy
234
+ assert_equal data.worker_class, @wp_spy.worker_class
235
+ assert_equal data.dwp_logger, @wp_spy.logger
236
+ assert_equal data.num_workers, @wp_spy.num_workers
237
+ exp = data.worker_params.merge({
238
+ :qs_daemon_data => data,
239
+ :qs_client => @client_spy,
240
+ :qs_worker_available => @worker_available,
241
+ :qs_logger => data.logger
242
+ })
243
+ assert_equal exp, @wp_spy.worker_params
244
+ assert_false @wp_spy.start_called
245
+ end
246
+
252
247
  should "not be running by default" do
253
248
  assert_false subject.running?
254
249
  end
@@ -282,27 +277,8 @@ module Qs::Daemon
282
277
  assert_equal [subject.signals_redis_key], call.args
283
278
  end
284
279
 
285
- should "build and start a worker pool" do
286
- assert_not_nil @worker_pool_spy
287
- assert_equal @daemon_class.min_workers, @worker_pool_spy.min_workers
288
- assert_equal @daemon_class.max_workers, @worker_pool_spy.max_workers
289
-
290
- exp = 1
291
- assert_equal exp, @worker_pool_spy.on_worker_error_callbacks.size
292
-
293
- exp = @start_procs.size
294
- assert_equal exp, @worker_pool_spy.on_worker_start_callbacks.size
295
-
296
- exp = @shutdown_procs.size
297
- assert_equal exp, @worker_pool_spy.on_worker_shutdown_callbacks.size
298
-
299
- exp = @sleep_procs.size + 1 # configured plus 1 internal
300
- assert_equal exp, @worker_pool_spy.on_worker_sleep_callbacks.size
301
-
302
- exp = @wakeup_procs.size
303
- assert_equal exp, @worker_pool_spy.on_worker_wakeup_callbacks.size
304
-
305
- assert_true @worker_pool_spy.start_called
280
+ should "start its worker pool" do
281
+ assert_true @wp_spy.start_called
306
282
  end
307
283
 
308
284
  end
@@ -310,7 +286,7 @@ module Qs::Daemon
310
286
  class RunningWithoutAvailableWorkerTests < InitSetupTests
311
287
  desc "running without an available worker"
312
288
  setup do
313
- @worker_available = false
289
+ @wp_worker_available = false
314
290
 
315
291
  @daemon = @daemon_class.new
316
292
  @thread = @daemon.start
@@ -322,7 +298,7 @@ module Qs::Daemon
322
298
  assert_equal 'sleep', @thread.status
323
299
  @client_spy.append(@queue.redis_key, Factory.string)
324
300
  @thread.join(0.1)
325
- assert_empty @worker_pool_spy.work_items
301
+ assert_empty @wp_spy.work_items
326
302
  end
327
303
 
328
304
  end
@@ -344,7 +320,7 @@ module Qs::Daemon
344
320
  exp = [subject.signals_redis_key, subject.queue_redis_keys, 0].flatten
345
321
  assert_equal exp, call.args
346
322
  exp = Qs::QueueItem.new(@queue.redis_key, @encoded_payload)
347
- assert_equal exp, @worker_pool_spy.work_items.first
323
+ assert_equal exp, @wp_spy.work_items.first
348
324
  end
349
325
 
350
326
  end
@@ -400,75 +376,18 @@ module Qs::Daemon
400
376
 
401
377
  end
402
378
 
403
- class WorkerPoolWorkProcTests < InitSetupTests
404
- desc "worker pool work proc"
405
- setup do
406
- @ph_spy = nil
407
- Assert.stub(Qs::PayloadHandler, :new) do |*args|
408
- @ph_spy = PayloadHandlerSpy.new(*args)
409
- end
410
-
411
- @daemon = @daemon_class.new
412
- @thread = @daemon.start
413
-
414
- @queue_item = Qs::QueueItem.new(Factory.string, Factory.string)
415
- @worker_pool_spy.work_proc.call(@queue_item)
416
- end
417
- subject{ @daemon }
418
-
419
- should "build and run a payload handler" do
420
- assert_not_nil @ph_spy
421
- assert_equal subject.daemon_data, @ph_spy.daemon_data
422
- assert_equal @queue_item, @ph_spy.queue_item
423
- end
424
-
425
- end
426
-
427
- class WorkerPoolOnWorkerErrorTests < InitSetupTests
428
- desc "worker pool on worker error proc"
429
- setup do
430
- @daemon = @daemon_class.new
431
- @thread = @daemon.start
432
-
433
- @exception = Factory.exception
434
- @queue_item = Qs::QueueItem.new(Factory.string, Factory.string)
435
- @callback = @worker_pool_spy.on_worker_error_callbacks.first
436
- end
437
- subject{ @daemon }
438
-
439
- should "requeue the queue item if it wasn't started" do
440
- @queue_item.started = false
441
- @callback.call('worker', @exception, @queue_item)
442
- call = @client_spy.calls.detect{ |c| c.command == :prepend }
443
- assert_not_nil call
444
- assert_equal @queue_item.queue_redis_key, call.args.first
445
- assert_equal @queue_item.encoded_payload, call.args.last
446
- end
447
-
448
- should "not requeue the queue item if it was started" do
449
- @queue_item.started = true
450
- @callback.call('worker', @exception, @queue_item)
451
- assert_nil @client_spy.calls.detect{ |c| c.command == :prepend }
452
- end
453
-
454
- should "do nothing if not passed a queue item" do
455
- assert_nothing_raised{ @callback.call(@exception, nil) }
456
- end
457
-
458
- end
459
-
460
379
  class StopTests < StartTests
461
380
  desc "and then stopped"
462
381
  setup do
463
382
  @queue_item = Qs::QueueItem.new(@queue.redis_key, Factory.string)
464
- @worker_pool_spy.add_work(@queue_item)
383
+ @wp_spy.push(@queue_item)
465
384
 
466
385
  @daemon.stop true
467
386
  end
468
387
 
469
388
  should "shutdown the worker pool" do
470
- assert_true @worker_pool_spy.shutdown_called
471
- assert_equal @daemon_class.shutdown_timeout, @worker_pool_spy.shutdown_timeout
389
+ assert_true @wp_spy.shutdown_called
390
+ assert_equal @daemon_class.shutdown_timeout, @wp_spy.shutdown_timeout
472
391
  end
473
392
 
474
393
  should "requeue any work left on the pool" do
@@ -491,7 +410,7 @@ module Qs::Daemon
491
410
  class StopWhileWaitingForWorkerTests < InitSetupTests
492
411
  desc "stopped while waiting for a worker"
493
412
  setup do
494
- @worker_available = false
413
+ @wp_worker_available = false
495
414
  @daemon = @daemon_class.new
496
415
  @thread = @daemon.start
497
416
  @daemon.stop(true)
@@ -508,14 +427,14 @@ module Qs::Daemon
508
427
  desc "and then halted"
509
428
  setup do
510
429
  @queue_item = Qs::QueueItem.new(@queue.redis_key, Factory.string)
511
- @worker_pool_spy.add_work(@queue_item)
430
+ @wp_spy.push(@queue_item)
512
431
 
513
432
  @daemon.halt true
514
433
  end
515
434
 
516
435
  should "shutdown the worker pool with a 0 timeout" do
517
- assert_true @worker_pool_spy.shutdown_called
518
- assert_equal 0, @worker_pool_spy.shutdown_timeout
436
+ assert_true @wp_spy.shutdown_called
437
+ assert_equal 0, @wp_spy.shutdown_timeout
519
438
  end
520
439
 
521
440
  should "requeue any work left on the pool" do
@@ -538,7 +457,7 @@ module Qs::Daemon
538
457
  class HaltWhileWaitingForWorkerTests < InitSetupTests
539
458
  desc "halted while waiting for a worker"
540
459
  setup do
541
- @worker_available = false
460
+ @wp_worker_available = false
542
461
  @daemon = @daemon_class.new
543
462
  @thread = @daemon.start
544
463
  @daemon.halt(true)
@@ -555,17 +474,18 @@ module Qs::Daemon
555
474
  desc "with a work loop error"
556
475
  setup do
557
476
  # cause a non-dequeue error
558
- Assert.stub(@worker_pool_spy, :worker_available?){ raise RuntimeError }
477
+ Assert.stub(@wp_spy, :worker_available?){ raise RuntimeError }
559
478
 
560
- # cause the daemon to loop, its sleeping on the original block_dequeue
479
+ # cause the daemon to loop, it's sleeping on the original `block_dequeue`
561
480
  # call that happened before the stub
562
481
  @queue_item = Qs::QueueItem.new(@queue.redis_key, Factory.string)
563
482
  @client_spy.append(@queue_item.queue_redis_key, @queue_item.encoded_payload)
483
+ @thread.join
564
484
  end
565
485
 
566
486
  should "shutdown the worker pool" do
567
- assert_true @worker_pool_spy.shutdown_called
568
- assert_equal @daemon_class.shutdown_timeout, @worker_pool_spy.shutdown_timeout
487
+ assert_true @wp_spy.shutdown_called
488
+ assert_equal @daemon_class.shutdown_timeout, @wp_spy.shutdown_timeout
569
489
  end
570
490
 
571
491
  should "requeue any work left on the pool" do
@@ -604,14 +524,12 @@ module Qs::Daemon
604
524
  subject{ @configuration }
605
525
 
606
526
  should have_options :name, :pid_file
607
- should have_options :min_workers, :max_workers
527
+ should have_options :num_workers
608
528
  should have_options :verbose_logging, :logger
609
529
  should have_options :shutdown_timeout
610
- should have_accessors :process_label
611
530
  should have_accessors :init_procs, :error_procs
531
+ should have_accessors :worker_class, :worker_params
612
532
  should have_accessors :queues
613
- should have_readers :worker_start_procs, :worker_shutdown_procs
614
- should have_readers :worker_sleep_procs, :worker_wakeup_procs
615
533
  should have_imeths :routes
616
534
  should have_imeths :to_hash
617
535
  should have_imeths :valid?, :validate!
@@ -624,41 +542,19 @@ module Qs::Daemon
624
542
  config = Configuration.new
625
543
  assert_nil config.name
626
544
  assert_nil config.pid_file
627
- assert_equal 1, config.min_workers
628
- assert_equal 4, config.max_workers
545
+ assert_equal 4, config.num_workers
629
546
  assert_true config.verbose_logging
630
547
  assert_instance_of Qs::NullLogger, config.logger
631
548
  assert_nil subject.shutdown_timeout
632
549
 
633
- assert_nil config.process_label
634
550
  assert_equal [], config.init_procs
635
551
  assert_equal [], config.error_procs
636
- assert_equal [], subject.worker_start_procs
637
- assert_equal [], subject.worker_shutdown_procs
638
- assert_equal [], subject.worker_sleep_procs
639
- assert_equal [], subject.worker_wakeup_procs
552
+ assert_equal DefaultWorker, config.worker_class
553
+ assert_nil config.worker_params
640
554
  assert_equal [], config.queues
641
555
  assert_equal [], config.routes
642
556
  end
643
557
 
644
- should "prefer an env var for the label but fall back to the name option" do
645
- current_env_process_label = ENV['QS_PROCESS_LABEL']
646
-
647
- ENV['QS_PROCESS_LABEL'] = Factory.string
648
- config = Configuration.new(:name => Factory.string)
649
- assert_equal ENV['QS_PROCESS_LABEL'], config.process_label
650
-
651
- ENV['QS_PROCESS_LABEL'] = ''
652
- config = Configuration.new(:name => Factory.string)
653
- assert_equal config.name, config.process_label
654
-
655
- ENV.delete('QS_PROCESS_LABEL')
656
- config = Configuration.new(:name => Factory.string)
657
- assert_equal config.name, config.process_label
658
-
659
- ENV['QS_PROCESS_LABEL'] = current_env_process_label
660
- end
661
-
662
558
  should "not be valid by default" do
663
559
  assert_false subject.valid?
664
560
  end
@@ -670,17 +566,13 @@ module Qs::Daemon
670
566
  should "include some attrs (not just the options) in its hash" do
671
567
  config_hash = subject.to_hash
672
568
 
673
- assert_equal subject.process_label, config_hash[:process_label]
674
569
  assert_equal subject.error_procs, config_hash[:error_procs]
570
+ assert_equal subject.worker_class, config_hash[:worker_class]
571
+ assert_equal subject.worker_params, config_hash[:worker_params]
675
572
  assert_equal subject.routes, config_hash[:routes]
676
573
 
677
574
  exp = subject.queues.map(&:redis_key)
678
575
  assert_equal exp, config_hash[:queue_redis_keys]
679
-
680
- assert_equal subject.worker_start_procs, config_hash[:worker_start_procs]
681
- assert_equal subject.worker_shutdown_procs, config_hash[:worker_shutdown_procs]
682
- assert_equal subject.worker_sleep_procs, config_hash[:worker_sleep_procs]
683
- assert_equal subject.worker_wakeup_procs, config_hash[:worker_wakeup_procs]
684
576
  end
685
577
 
686
578
  should "call its init procs when validated" do
@@ -708,6 +600,14 @@ module Qs::Daemon
708
600
  subject.routes.each{ |route| assert_not_nil route.handler_class }
709
601
  end
710
602
 
603
+ should "validate its worker class when validated" do
604
+ subject.worker_class = Module.new
605
+ assert_raises(InvalidError){ subject.validate! }
606
+
607
+ subject.worker_class = Class.new
608
+ assert_raises(InvalidError){ subject.validate! }
609
+ end
610
+
711
611
  should "be valid after being validated" do
712
612
  assert_false subject.valid?
713
613
  subject.validate!
@@ -725,94 +625,57 @@ module Qs::Daemon
725
625
 
726
626
  end
727
627
 
728
- class SignalTests < UnitTests
729
- desc "Signal"
628
+ class StateTests < UnitTests
629
+ desc "State"
730
630
  setup do
731
- @signal = Signal.new(:stop)
631
+ @state = State.new
732
632
  end
733
- subject{ @signal }
633
+ subject{ @state }
734
634
 
735
- should have_imeths :set, :start?, :stop?, :halt?
635
+ should have_imeths :run?, :stop?, :halt?
736
636
 
737
- should "allow setting it to start" do
738
- subject.set :start
739
- assert_true subject.start?
740
- assert_false subject.stop?
741
- assert_false subject.halt?
637
+ should "be a dat-worker-pool locked object" do
638
+ assert State < DatWorkerPool::LockedObject
639
+ end
640
+
641
+ should "know if its in the run state" do
642
+ assert_false subject.run?
643
+ subject.set :run
644
+ assert_true subject.run?
742
645
  end
743
646
 
744
- should "allow setting it to stop" do
647
+ should "know if its in the stop state" do
648
+ assert_false subject.stop?
745
649
  subject.set :stop
746
- assert_false subject.start?
747
650
  assert_true subject.stop?
748
- assert_false subject.halt?
749
651
  end
750
652
 
751
- should "allow setting it to halt" do
653
+ should "know if its in the halt state" do
654
+ assert_false subject.halt?
752
655
  subject.set :halt
753
- assert_false subject.start?
754
- assert_false subject.stop?
755
656
  assert_true subject.halt?
756
657
  end
757
658
 
758
659
  end
759
660
 
760
- TestHandler = Class.new
761
-
762
- class PayloadHandlerSpy
763
- attr_reader :daemon_data, :queue_item, :run_called
764
-
765
- def initialize(daemon_data, queue_item)
766
- @daemon_data = daemon_data
767
- @queue_item = queue_item
768
- @run_called = false
769
- end
770
-
771
- def run
772
- @run_called = true
773
- end
774
- end
775
-
776
- class ClientSpy < Qs::TestClient
777
- attr_reader :calls
778
-
779
- def initialize(*args)
780
- super
781
- @calls = []
782
- @list = []
783
- @mutex = Mutex.new
784
- @cv = ConditionVariable.new
785
- end
786
-
787
- def block_dequeue(*args)
788
- @calls << Call.new(:block_dequeue, args)
789
- if @list.empty?
790
- @mutex.synchronize{ @cv.wait(@mutex) }
791
- end
792
- @list.shift
793
- end
794
-
795
- def append(*args)
796
- @calls << Call.new(:append, args)
797
- @list << args
798
- @cv.signal
799
- end
800
-
801
- def prepend(*args)
802
- @calls << Call.new(:prepend, args)
803
- @list << args
804
- @cv.signal
661
+ class WorkerAvailableTests < UnitTests
662
+ desc "WorkerAvailable"
663
+ setup do
664
+ @worker_available = WorkerAvailable.new
805
665
  end
666
+ subject{ @worker_available }
806
667
 
807
- def clear(*args)
808
- @calls << Call.new(:clear, args)
809
- end
668
+ should have_imeths :wait, :signal
810
669
 
811
- def ping
812
- @calls << Call.new(:ping)
670
+ should "allow waiting and signalling" do
671
+ thread = Thread.new{ subject.wait }
672
+ assert_equal 'sleep', thread.status
673
+ subject.signal
674
+ assert_equal false, thread.status # dead, done running
813
675
  end
814
676
 
815
- Call = Struct.new(:command, :args)
816
677
  end
817
678
 
679
+ TestHandler = Class.new
680
+
818
681
  end
@@ -1,7 +1,7 @@
1
1
  require 'assert'
2
2
  require 'qs/dispatch_job_handler'
3
3
 
4
- require 'qs/job_handler_test_helpers'
4
+ require 'qs/job_handler'
5
5
 
6
6
  module Qs::DispatchJobHandler
7
7