dat-worker-pool 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  class DatWorkerPool
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,33 @@
1
+ class DatWorkerPool
2
+
3
+ class WorkerPoolSpy
4
+ attr_reader :work_items
5
+ attr_reader :shutdown_called, :shutdown_timeout
6
+ attr_accessor :worker_available
7
+
8
+ def initialize
9
+ @worker_available = false
10
+ @work_items = []
11
+ @shutdown_called = false
12
+ @shutdown_timeout = nil
13
+ end
14
+
15
+ def worker_available?
16
+ @worker_available
17
+ end
18
+
19
+ def queue_empty?
20
+ @work_items.empty?
21
+ end
22
+
23
+ def add_work(work)
24
+ @work_items << work if work
25
+ end
26
+
27
+ def shutdown(timeout)
28
+ @shutdown_called = true
29
+ @shutdown_timeout = timeout
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,67 @@
1
+ require 'assert'
2
+ require 'dat-worker-pool/worker_pool_spy'
3
+
4
+ class DatWorkerPool::WorkerPoolSpy
5
+
6
+ class UnitTests < Assert::Context
7
+ desc "DatWorkerPool::WorkerPoolSpy"
8
+ setup do
9
+ @worker_pool_spy = DatWorkerPool::WorkerPoolSpy.new
10
+ end
11
+ subject{ @worker_pool_spy }
12
+
13
+ should have_readers :work_items
14
+ should have_readers :shutdown_called, :shutdown_timeout
15
+ should have_accessors :worker_available
16
+ should have_imeths :worker_available?, :queue_empty?
17
+ should have_imeths :add_work, :shutdown
18
+
19
+ should "have nothing in it's work items by default" do
20
+ assert subject.work_items.empty?
21
+ end
22
+
23
+ should "not have a worker available by default" do
24
+ assert_equal false, subject.worker_available
25
+ assert_not subject.worker_available?
26
+ end
27
+
28
+ should "return false for shutdown called by default" do
29
+ assert_equal false, subject.shutdown_called
30
+ end
31
+
32
+ should "return `nil` for shutdown timeout by default" do
33
+ assert_nil subject.shutdown_timeout
34
+ end
35
+
36
+ should "allow setting whether a worker is available" do
37
+ subject.worker_available = true
38
+ assert_equal true, subject.worker_available
39
+ assert subject.worker_available?
40
+ end
41
+
42
+ should "allow adding work to the work items with #add_work" do
43
+ subject.add_work 'work'
44
+ assert_equal 1, subject.work_items.size
45
+ assert_includes 'work', subject.work_items
46
+ end
47
+
48
+ should "not add `nil` work to the work items with #add_work" do
49
+ subject.add_work nil
50
+ assert_equal 0, subject.work_items.size
51
+ end
52
+
53
+ should "return whether the work items is empty with #queue_empty?" do
54
+ assert_equal true, subject.queue_empty?
55
+ subject.add_work 'work'
56
+ assert_equal false, subject.queue_empty?
57
+ end
58
+
59
+ should "know when it's been shutdown and with what timeout" do
60
+ subject.shutdown(10)
61
+ assert subject.shutdown_called
62
+ assert_equal 10, subject.shutdown_timeout
63
+ end
64
+
65
+ end
66
+
67
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dat-worker-pool
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Collin Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-10-01 00:00:00 Z
19
+ date: 2013-10-10 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -68,11 +68,13 @@ files:
68
68
  - lib/dat-worker-pool/queue.rb
69
69
  - lib/dat-worker-pool/version.rb
70
70
  - lib/dat-worker-pool/worker.rb
71
+ - lib/dat-worker-pool/worker_pool_spy.rb
71
72
  - log/.gitkeep
72
73
  - test/helper.rb
73
74
  - test/system/use_worker_pool_tests.rb
74
75
  - test/unit/dat-worker-pool_tests.rb
75
76
  - test/unit/queue_tests.rb
77
+ - test/unit/worker_pool_spy_tests.rb
76
78
  - test/unit/worker_tests.rb
77
79
  - tmp/.gitkeep
78
80
  homepage: http://github.com/redding/dat-worker-pool
@@ -113,4 +115,5 @@ test_files:
113
115
  - test/system/use_worker_pool_tests.rb
114
116
  - test/unit/dat-worker-pool_tests.rb
115
117
  - test/unit/queue_tests.rb
118
+ - test/unit/worker_pool_spy_tests.rb
116
119
  - test/unit/worker_tests.rb