r18_connection_pool 2.2.2a

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,149 @@
1
+ require_relative 'helper'
2
+
3
+ class TestConnectionPoolTimedStack < Minitest::Test
4
+
5
+ def setup
6
+ @stack = ConnectionPool::TimedStack.new { Object.new }
7
+ end
8
+
9
+ def test_empty_eh
10
+ stack = ConnectionPool::TimedStack.new(1) { Object.new }
11
+
12
+ refute_empty stack
13
+
14
+ popped = stack.pop
15
+
16
+ assert_empty stack
17
+
18
+ stack.push popped
19
+
20
+ refute_empty stack
21
+ end
22
+
23
+ def test_length
24
+ stack = ConnectionPool::TimedStack.new(1) { Object.new }
25
+
26
+ assert_equal 1, stack.length
27
+
28
+ popped = stack.pop
29
+
30
+ assert_equal 0, stack.length
31
+
32
+ stack.push popped
33
+
34
+ assert_equal 1, stack.length
35
+ end
36
+
37
+ def test_object_creation_fails
38
+ stack = ConnectionPool::TimedStack.new(2) { raise 'failure' }
39
+
40
+ begin
41
+ stack.pop
42
+ rescue => error
43
+ assert_equal 'failure', error.message
44
+ end
45
+
46
+ begin
47
+ stack.pop
48
+ rescue => error
49
+ assert_equal 'failure', error.message
50
+ end
51
+
52
+ refute_empty stack
53
+ assert_equal 2, stack.length
54
+ end
55
+
56
+ def test_pop
57
+ object = Object.new
58
+ @stack.push object
59
+
60
+ popped = @stack.pop
61
+
62
+ assert_same object, popped
63
+ end
64
+
65
+ def test_pop_empty
66
+ e = assert_raises Timeout::Error do
67
+ @stack.pop timeout: 0
68
+ end
69
+
70
+ assert_equal 'Waited 0 sec', e.message
71
+ end
72
+
73
+ def test_pop_empty_2_0_compatibility
74
+ e = assert_raises Timeout::Error do
75
+ @stack.pop 0
76
+ end
77
+
78
+ assert_equal 'Waited 0 sec', e.message
79
+ end
80
+
81
+ def test_pop_full
82
+ stack = ConnectionPool::TimedStack.new(1) { Object.new }
83
+
84
+ popped = stack.pop
85
+
86
+ refute_nil popped
87
+ assert_empty stack
88
+ end
89
+
90
+ def test_pop_wait
91
+ thread = Thread.start do
92
+ @stack.pop
93
+ end
94
+
95
+ Thread.pass while thread.status == 'run'
96
+
97
+ object = Object.new
98
+
99
+ @stack.push object
100
+
101
+ assert_same object, thread.value
102
+ end
103
+
104
+ def test_pop_shutdown
105
+ @stack.shutdown { }
106
+
107
+ assert_raises ConnectionPool::PoolShuttingDownError do
108
+ @stack.pop
109
+ end
110
+ end
111
+
112
+ def test_push
113
+ stack = ConnectionPool::TimedStack.new(1) { Object.new }
114
+
115
+ conn = stack.pop
116
+
117
+ stack.push conn
118
+
119
+ refute_empty stack
120
+ end
121
+
122
+ def test_push_shutdown
123
+ called = []
124
+
125
+ @stack.shutdown do |object|
126
+ called << object
127
+ end
128
+
129
+ @stack.push Object.new
130
+
131
+ refute_empty called
132
+ assert_empty @stack
133
+ end
134
+
135
+ def test_shutdown
136
+ @stack.push Object.new
137
+
138
+ called = []
139
+
140
+ @stack.shutdown do |object|
141
+ called << object
142
+ end
143
+
144
+ refute_empty called
145
+ assert_empty @stack
146
+ end
147
+
148
+ end
149
+
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: r18_connection_pool
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.2.2a
5
+ platform: ruby
6
+ authors:
7
+ - Mike Perham
8
+ - Damian Janowski
9
+ - Mayama Takeshi
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2023-11-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: minitest
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 5.0.0
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 5.0.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ description: Generic connection pool for Ruby 1.8
58
+ email:
59
+ - mayamatakeshi@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".travis.yml"
66
+ - Changes.md
67
+ - Gemfile
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - devjournal
72
+ - lib/connection_pool.rb
73
+ - lib/connection_pool/monotonic_time.rb
74
+ - lib/connection_pool/timed_stack.rb
75
+ - lib/connection_pool/version.rb
76
+ - r18_connection_pool.gemspec
77
+ - test/helper.rb
78
+ - test/test_connection_pool.rb
79
+ - test/test_connection_pool_timed_stack.rb
80
+ homepage: https://github.com/MayamaTakeshi/connection_pool
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">"
96
+ - !ruby/object:Gem::Version
97
+ version: 1.3.1
98
+ requirements: []
99
+ rubygems_version: 3.3.5
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Generic connection pool for Ruby 1.8
103
+ test_files: []