bixby-common 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f917af6b0c09f9ac2c4b27040bf752ca4a83399f
4
- data.tar.gz: 2d0e5e87a996acfa68e19cbe93e794cbc1ca4e8c
3
+ metadata.gz: 7ef49eaa3aea879b94f4ba4f77fe7e152044f415
4
+ data.tar.gz: 403008eee8f7dc8e787afceba4a9fe7696ad4b51
5
5
  SHA512:
6
- metadata.gz: 60bf34b93f1ba0c9a306b7c6c86e88bbb20c951a2147804194285faf74beb35c7f4f06d0dc34094a0774c424e5bab17068ac3bef274d9f153959d8b536fee1c6
7
- data.tar.gz: 3287f8e98887ae22ff62bad20c2eda2f2bee8fd2b7fd53c855ba7aae06bbb071fd18d1adc2a6d47e72df59762ef6fc456e15b465b74de2aa349e2b6d230d33e3
6
+ metadata.gz: 5eb86970763068ff7a08fb5f84cad02e910bf6a73e3e419f2c044827fea39e1a55aa69431983d264a65311dc7c8177ed2158d662ed874c4bed54134c735f0cba
7
+ data.tar.gz: c8dbaf3da89d7243b028c449665f454350f9ec3edb2c13b5252d961b08d60cca75bf857adce8c0e422080ca7a0384fe2cec450a8995afb0fca491ab5b615048a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.6.3
data/bixby-common.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: bixby-common 0.6.2 ruby lib
5
+ # stub: bixby-common 0.6.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "bixby-common"
9
- s.version = "0.6.2"
9
+ s.version = "0.6.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -32,7 +32,7 @@ module Bixby
32
32
  logger.debug { "enqueue new task: #{command}" }
33
33
  @input_queue.push(Task.new(command, block))
34
34
  if command == :perform then
35
- grow_pool
35
+ grow
36
36
  end
37
37
  nil
38
38
  end
@@ -125,7 +125,6 @@ module Bixby
125
125
  end
126
126
 
127
127
  enqueue(:shutdown, callback)
128
- @size -= 1
129
128
  end
130
129
  end
131
130
 
@@ -165,8 +164,8 @@ module Bixby
165
164
  exit_handler = lambda { |worker, reason|
166
165
  @lock.synchronize do
167
166
  if reason == :exception or (reason == :timeout && @size > @min_size) then
168
- @size -= 1
169
167
  remove_worker(worker)
168
+ grow
170
169
  return true
171
170
  end
172
171
  false
@@ -179,13 +178,15 @@ module Bixby
179
178
  end
180
179
 
181
180
  # Grow the pool by one if we have more jobs than idle workers
182
- def grow_pool
181
+ def grow
183
182
  @lock.synchronize do
183
+ prune
184
184
  logger.debug { "jobs: #{num_jobs}; busy: #{num_working}; idle: #{num_idle}" }
185
- if @size < @max_size && num_jobs > 0 && num_jobs > num_idle then
185
+ if @size == 0 || (@size < @max_size && num_jobs > 0 && num_jobs > num_idle) then
186
186
  space = @max_size-@size
187
187
  jobs = num_jobs-num_idle
188
188
  needed = space < jobs ? space : jobs
189
+ needed = 1 if needed <= 0
189
190
  expand(needed)
190
191
  else
191
192
  logger.debug "NOT growing the pool!"
@@ -195,9 +196,19 @@ module Bixby
195
196
  nil
196
197
  end
197
198
 
199
+ # Remove any dead worker threads which may not have been cleaned up properly
200
+ # (via callback handler)
201
+ def prune
202
+ @lock.synchronize do
203
+ @workers.delete_if { |w| !w.alive? }
204
+ @size = @workers.size
205
+ end
206
+ end
207
+
198
208
  def remove_worker(worker)
199
209
  @lock.synchronize do
200
210
  @workers.delete(worker)
211
+ @size -= 1
201
212
  end
202
213
 
203
214
  nil
@@ -2,6 +2,13 @@
2
2
  require 'helper'
3
3
 
4
4
  module Bixby
5
+
6
+ class ThreadPool
7
+ def workers
8
+ @workers
9
+ end
10
+ end
11
+
5
12
  module Test
6
13
  class TestThreadPool < TestCase
7
14
 
@@ -78,6 +85,40 @@ class TestThreadPool < TestCase
78
85
  assert_equal 1, @pool.size, "pool should shrink to 1"
79
86
  end
80
87
 
88
+ def test_handle_exception
89
+ @pool.perform do
90
+ raise "bleh"
91
+ end
92
+
93
+ while @pool.num_busy > 0 || @pool.num_jobs > 0 do
94
+ sleep 0.1
95
+ end
96
+
97
+ assert_equal 1, @pool.size
98
+ assert_equal 0, @pool.workers.find_all{ |w| !w.thread.alive? }.size, "no dead threads"
99
+ end
100
+
101
+ def test_handle_killed_thread
102
+ assert_equal 1, @pool.size
103
+ assert @pool.workers.find{ |w| w.thread.alive? }
104
+ @pool.workers.first.thread.kill
105
+ sleep 0.01
106
+ assert_equal 1, @pool.size
107
+ assert_equal 1, @pool.num_idle
108
+ refute @pool.workers.find{ |w| w.thread.alive? }
109
+
110
+ foo = []
111
+ @pool.perform do
112
+ foo << "bar"
113
+ end
114
+
115
+ @pool.dispose
116
+
117
+ @pool.summary
118
+ assert_equal 1, foo.size
119
+ assert_equal "bar", foo.first
120
+ end
121
+
81
122
  end # TestThreadPool
82
123
  end # Test
83
124
  end # Bixby
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bixby-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chetan Sarva