connection_pool 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,18 +11,19 @@ class TimedQueue
11
11
  def push(obj)
12
12
  @mutex.synchronize do
13
13
  @que.push obj
14
- @resource.signal
14
+ @resource.broadcast
15
15
  end
16
16
  end
17
17
  alias_method :<<, :push
18
18
 
19
19
  def timed_pop(timeout=0.5)
20
+ deadline = Time.now + timeout
20
21
  @mutex.synchronize do
21
- if @que.empty?
22
+ loop do
23
+ return @que.shift unless @que.empty?
24
+ raise Timeout::Error if Time.now > deadline
22
25
  @resource.wait(@mutex, timeout)
23
- raise Timeout::Error if @que.empty?
24
26
  end
25
- return @que.shift
26
27
  end
27
28
  end
28
29
 
@@ -37,4 +38,4 @@ class TimedQueue
37
38
  def length
38
39
  @que.length
39
40
  end
40
- end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module ConnectionPool
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,3 +1,4 @@
1
+ Thread.abort_on_exception = true
1
2
  require 'helper'
2
3
 
3
4
  class TestConnectionPool < MiniTest::Unit::TestCase
@@ -47,6 +48,7 @@ class TestConnectionPool < MiniTest::Unit::TestCase
47
48
  pool.do_something
48
49
  end
49
50
 
51
+ sleep 0.05
50
52
  pool.with do |conn|
51
53
  refute_nil conn
52
54
  end
@@ -65,4 +67,16 @@ class TestConnectionPool < MiniTest::Unit::TestCase
65
67
  end
66
68
  assert_equal 1, result
67
69
  end
70
+
71
+ def test_heavy_threading
72
+ pool = ConnectionPool.new(:timeout => 0.5, :size => 3) { NetworkConnection.new }
73
+ 20.times do
74
+ Thread.new do
75
+ pool.with do |net|
76
+ sleep 0.05
77
+ end
78
+ end
79
+ end
80
+ sleep 0.5
81
+ end
68
82
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: connection_pool
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mike Perham
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-09 00:00:00 -07:00
13
+ date: 2011-09-12 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16