ezpool 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,159 @@
1
+ require_relative 'helper'
2
+
3
+ class TestEzPoolTimedStack < Minitest::Test
4
+
5
+ def setup
6
+ @manager = EzPool::ConnectionManager.new(
7
+ lambda { Object.new }
8
+ )
9
+ @stack = EzPool::TimedStack.new(@manager, 0)
10
+ end
11
+
12
+ def test_empty_eh
13
+ stack = EzPool::TimedStack.new(@manager, 1)
14
+
15
+ refute_empty stack
16
+
17
+ popped = stack.pop
18
+
19
+ assert_empty stack
20
+
21
+ stack.push popped
22
+
23
+ refute_empty stack
24
+ end
25
+
26
+ def test_length
27
+ stack = EzPool::TimedStack.new(@manager, 1)
28
+
29
+ assert_equal 1, stack.length
30
+
31
+ popped = stack.pop
32
+
33
+ assert_equal 0, stack.length
34
+
35
+ stack.push popped
36
+
37
+ assert_equal 1, stack.length
38
+ end
39
+
40
+ def test_object_creation_fails
41
+ @manager.connect_with do
42
+ raise 'failure'
43
+ end
44
+ stack = EzPool::TimedStack.new(@manager, 2)
45
+
46
+ begin
47
+ stack.pop
48
+ rescue => error
49
+ assert_equal 'failure', error.message
50
+ end
51
+
52
+ begin
53
+ stack.pop
54
+ rescue => error
55
+ assert_equal 'failure', error.message
56
+ end
57
+
58
+ refute_empty stack
59
+ assert_equal 2, stack.length
60
+ end
61
+
62
+ def test_pop
63
+ object = Object.new
64
+ @stack.push object
65
+
66
+ popped = @stack.pop
67
+
68
+ assert_same object, popped
69
+ end
70
+
71
+ def test_pop_empty
72
+ e = assert_raises Timeout::Error do
73
+ @stack.pop timeout: 0
74
+ end
75
+
76
+ assert_equal 'Waited 0 sec', e.message
77
+ end
78
+
79
+ def test_pop_empty_2_0_compatibility
80
+ e = assert_raises Timeout::Error do
81
+ @stack.pop 0
82
+ end
83
+
84
+ assert_equal 'Waited 0 sec', e.message
85
+ end
86
+
87
+ def test_pop_full
88
+ stack = EzPool::TimedStack.new(@manager, 1)
89
+
90
+ popped = stack.pop
91
+
92
+ refute_nil popped
93
+ assert_empty stack
94
+ end
95
+
96
+ def test_pop_wait
97
+ thread = Thread.start do
98
+ @stack.pop
99
+ end
100
+
101
+ Thread.pass while thread.status == 'run'
102
+
103
+ object = Object.new
104
+
105
+ @stack.push object
106
+
107
+ assert_same object, thread.value
108
+ end
109
+
110
+ def test_pop_shutdown
111
+ @stack.shutdown { }
112
+
113
+ assert_raises EzPool::PoolShuttingDownError do
114
+ @stack.pop
115
+ end
116
+ end
117
+
118
+ def test_push
119
+ stack = EzPool::TimedStack.new(@manager, 1)
120
+
121
+ conn = stack.pop
122
+
123
+ stack.push conn
124
+
125
+ refute_empty stack
126
+ end
127
+
128
+ def test_push_shutdown
129
+ called = []
130
+
131
+ @manager.disconnect_with do |object|
132
+ called << object
133
+ end
134
+
135
+ @stack.shutdown
136
+
137
+ @stack.push @manager.create_new
138
+
139
+ refute_empty called
140
+ assert_empty @stack
141
+ end
142
+
143
+ def test_shutdown
144
+ @stack.push @manager.create_new
145
+
146
+ called = []
147
+
148
+ @manager.disconnect_with do |object|
149
+ called << object
150
+ end
151
+
152
+ @stack.shutdown
153
+
154
+ refute_empty called
155
+ assert_empty @stack
156
+ end
157
+
158
+ end
159
+
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ezpool
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Perham
8
+ - Damian Janowski
9
+ - James Brown
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2016-12-07 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: More featureful generic connection pool for Ruby
58
+ email:
59
+ - oss@easypost.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
+ - ezpool.gemspec
72
+ - lib/ezpool.rb
73
+ - lib/ezpool/connection_manager.rb
74
+ - lib/ezpool/connection_wrapper.rb
75
+ - lib/ezpool/errors.rb
76
+ - lib/ezpool/monotonic_time.rb
77
+ - lib/ezpool/timed_stack.rb
78
+ - lib/ezpool/version.rb
79
+ - test/helper.rb
80
+ - test/test_ezpool.rb
81
+ - test/test_ezpool_timed_stack.rb
82
+ homepage: https://github.com/EasyPost/ezpool
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.0.14.1
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: More featureful generic connection pool for Ruby
106
+ test_files:
107
+ - test/helper.rb
108
+ - test/test_ezpool.rb
109
+ - test/test_ezpool_timed_stack.rb