work_queue 2.5.2 → 2.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -37,7 +37,7 @@ It's generally recommended to bound the resources used:
37
37
 
38
38
  = Example(s)
39
39
 
40
- Download multiple files in parallel:
40
+ Download multiple files in parallel:
41
41
 
42
42
  require 'open-uri'
43
43
  require 'rubygems'
data/lib/test.rb ADDED
@@ -0,0 +1,12 @@
1
+ require_relative 'work_queue'
2
+
3
+ work_queue = WorkQueue.new(1000)
4
+
5
+ # Force threads to be available - the work_queue gem seems to not always create the threads
6
+ 10000.times do |i|
7
+ work_queue.enqueue_b do
8
+ a = 2
9
+ end
10
+ end
11
+
12
+ puts "ola"
data/lib/work_queue.rb CHANGED
@@ -5,7 +5,7 @@ require 'monitor'
5
5
  # A tunable work queue, designed to coordinate work between a producer and a pool of worker threads.
6
6
  #
7
7
  class WorkQueue
8
- VERSION = "2.5.2"
8
+ VERSION = "2.5.3"
9
9
 
10
10
  ##
11
11
  # Creates an empty work queue with the desired parameters.
@@ -138,7 +138,7 @@ class WorkQueue
138
138
 
139
139
  ##
140
140
  # Halt all worker threads immediately, aborting any ongoing tasks.
141
- # Resets all
141
+ # Resets all
142
142
  #
143
143
  # ==== Example(s)
144
144
  # wq = WorkQueue.new
@@ -185,7 +185,7 @@ class WorkQueue
185
185
  @task_dequeued.wait_until { @tasks.size < @max_tasks }
186
186
  @tasks << [proc, params]
187
187
  @tasks_pending += 1
188
- @task_enqueued.signal
188
+ @task_enqueued.broadcast
189
189
  end
190
190
  spawn_thread
191
191
  end
@@ -233,7 +233,7 @@ class WorkQueue
233
233
  @task_enqueued.wait_while { @tasks.empty? }
234
234
  @threads_waiting -= 1
235
235
  task = @tasks.shift
236
- @task_dequeued.signal
236
+ @task_dequeued.broadcast
237
237
  return task
238
238
  end
239
239
  end
@@ -244,7 +244,7 @@ class WorkQueue
244
244
  def conclude
245
245
  @tasks.synchronize do
246
246
  @tasks_pending -= 1
247
- @task_completed.signal
247
+ @task_completed.broadcast
248
248
  end
249
249
  end
250
250
  end
@@ -9,7 +9,7 @@ class TC_WorkQueue < Test::Unit::TestCase
9
9
  wq.join
10
10
  assert_equal "Hello Proc", s
11
11
  end
12
-
12
+
13
13
  def test_enqueue_block
14
14
  s = String.new
15
15
  wq = WorkQueue.new
@@ -17,7 +17,7 @@ class TC_WorkQueue < Test::Unit::TestCase
17
17
  wq.join
18
18
  assert_equal "Hello Block", s
19
19
  end
20
-
20
+
21
21
  def test_inner_enqueue
22
22
  s = String.new
23
23
  wq = WorkQueue.new
@@ -27,9 +27,9 @@ class TC_WorkQueue < Test::Unit::TestCase
27
27
  sleep 0.01
28
28
  end
29
29
  wq.join
30
- assert_equal "Hello Inner", s
30
+ assert_equal "Hello Inner", s
31
31
  end
32
-
32
+
33
33
  def test_threads_recycle
34
34
  wq = WorkQueue.new
35
35
  wq.enqueue_b { sleep 0.01 }
@@ -51,7 +51,7 @@ class TC_WorkQueue < Test::Unit::TestCase
51
51
  assert_equal 1, wq.cur_threads
52
52
  wq.join
53
53
  end
54
-
54
+
55
55
  def test_max_threads_validation
56
56
  assert_raise(ArgumentError) { WorkQueue.new 0, nil }
57
57
  assert_raise(ArgumentError) { WorkQueue.new -1, nil }
@@ -66,7 +66,7 @@ class TC_WorkQueue < Test::Unit::TestCase
66
66
  assert_equal 1, wq.cur_tasks
67
67
  wq.join
68
68
  end
69
-
69
+
70
70
  def test_max_tasks_validation
71
71
  assert_raise(ArgumentError) { WorkQueue.new nil, 0 }
72
72
  assert_raise(ArgumentError) { WorkQueue.new nil, -1 }
@@ -76,34 +76,34 @@ class TC_WorkQueue < Test::Unit::TestCase
76
76
  i = 0
77
77
  m = Mutex.new
78
78
  wq = WorkQueue.new 100, 200
79
- (1..10000).each do
79
+ (1..1000).each do
80
80
  wq.enqueue_b {
81
81
  sleep 0.01
82
82
  m.synchronize { i += 1 }
83
83
  }
84
84
  end
85
85
  wq.join
86
- assert_equal 10000, i
86
+ assert_equal 1000, i
87
87
  end
88
-
88
+
89
89
  def test_stress_prolonged
90
90
  i = 0
91
91
  m = Mutex.new
92
92
  wq = WorkQueue.new 100, 200
93
- (1..10000).each do
93
+ (1..1000).each do
94
94
  wq.enqueue_b {
95
95
  sleep rand(5)
96
96
  m.synchronize { i += 1 }
97
97
  }
98
98
  end
99
99
  wq.join
100
- assert_equal 10000, i
100
+ assert_equal 1000, i
101
101
  end
102
102
 
103
103
  def test_kill
104
104
  s = String.new
105
105
  wq = WorkQueue.new
106
- wq.enqueue_b(s) { |str|
106
+ wq.enqueue_b(s) { |str|
107
107
  sleep 0.1
108
108
  str.replace "Hello"
109
109
  }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: work_queue
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 5
9
- - 2
10
- version: 2.5.2
9
+ - 3
10
+ version: 2.5.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Miguel Fonseca
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-22 00:00:00 Z
18
+ date: 2013-02-23 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description:
@@ -32,6 +32,7 @@ files:
32
32
  - Rakefile
33
33
  - README.rdoc
34
34
  - tasks/test.rake
35
+ - lib/test.rb
35
36
  - lib/work_queue.rb
36
37
  - test/tc_work_queue.rb
37
38
  homepage: http://github.com/fmmfonseca/work_queue