em-pg-client 0.3.2 → 0.3.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.
- checksums.yaml +7 -0
- data/.travis.yml +4 -3
- data/HISTORY.md +11 -0
- data/README.md +2 -1
- data/Rakefile +30 -1
- data/benchmarks/single_row_mode.rb +8 -8
- data/lib/pg/em-version.rb +1 -1
- data/lib/pg/em.rb +137 -40
- data/lib/pg/em/client/connect_watcher.rb +32 -2
- data/lib/pg/em/connection_pool.rb +41 -9
- data/spec/em_client_autoreconnect.rb +45 -0
- data/spec/em_client_on_connect.rb +171 -0
- data/spec/em_connection_pool.rb +198 -0
- data/spec/em_synchrony_client_autoreconnect.rb +48 -0
- data/spec/pg_em_client_options.rb +39 -1
- data/spec/pg_em_connection_pool.rb +25 -1
- metadata +17 -27
@@ -168,6 +168,54 @@ describe 'em-synchrony-pg autoreconnect with on_autoreconnect' do
|
|
168
168
|
EM.stop
|
169
169
|
end
|
170
170
|
|
171
|
+
it "should execute on_connect before on_autoreconnect after server restart" do
|
172
|
+
@client.on_connect.should be_nil
|
173
|
+
run_on_connect = false
|
174
|
+
@client.on_connect = proc do |client, is_async, is_reset|
|
175
|
+
client.should be_an_instance_of PG::EM::Client
|
176
|
+
is_async.should be_true
|
177
|
+
is_reset.should be_true
|
178
|
+
client.query('SELECT pg_database_size(current_database());') {
|
179
|
+
run_on_connect = true
|
180
|
+
}
|
181
|
+
end
|
182
|
+
@client.on_autoreconnect = proc do |client, ex|
|
183
|
+
run_on_connect.should be_true
|
184
|
+
@on_autoreconnect.call(client, ex)
|
185
|
+
end
|
186
|
+
system($pgserver_cmd_stop).should be_true
|
187
|
+
system($pgserver_cmd_start).should be_true
|
188
|
+
@tested_proc.call
|
189
|
+
EM.stop
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should skip on_autoreconnect when on_connect failed after server restart" do
|
193
|
+
run_on_connect = false
|
194
|
+
run_on_autoreconnect = false
|
195
|
+
@client.on_connect = proc do |client, is_async, is_reset|
|
196
|
+
client.should be_an_instance_of PG::EM::Client
|
197
|
+
is_async.should be_true
|
198
|
+
is_reset.should be_true
|
199
|
+
begin
|
200
|
+
client.query('SELLECT 1;')
|
201
|
+
ensure
|
202
|
+
run_on_connect = true
|
203
|
+
end
|
204
|
+
end
|
205
|
+
@client.on_autoreconnect = proc do |client, ex|
|
206
|
+
run_on_autoreconnect = true
|
207
|
+
end
|
208
|
+
system($pgserver_cmd_stop).should be_true
|
209
|
+
system($pgserver_cmd_start).should be_true
|
210
|
+
expect do
|
211
|
+
@client.exec_prepared('get_db_size')
|
212
|
+
end.to raise_error PG::SyntaxError
|
213
|
+
@client.status.should be PG::CONNECTION_OK
|
214
|
+
run_on_connect.should be_true
|
215
|
+
run_on_autoreconnect.should be_false
|
216
|
+
EM.stop
|
217
|
+
end
|
218
|
+
|
171
219
|
before(:all) do
|
172
220
|
@tested_proc = proc do
|
173
221
|
@client.exec_prepared('get_db_size') do |result|
|
@@ -21,6 +21,7 @@ describe 'em-pg-client options' do
|
|
21
21
|
:@async_autoreconnect => true,
|
22
22
|
:@connect_timeout => 10,
|
23
23
|
:@query_timeout=>1,
|
24
|
+
:@on_connect=>nil,
|
24
25
|
:@on_autoreconnect=>nil,
|
25
26
|
:@async_command_aborted=>false} }
|
26
27
|
|
@@ -78,7 +79,7 @@ describe 'em-pg-client options' do
|
|
78
79
|
end.to raise_error(ArgumentError, /must respond to/)
|
79
80
|
|
80
81
|
expect do
|
81
|
-
subject.parse_async_options [on_autoreconnect
|
82
|
+
subject.parse_async_options ['on_autoreconnect' => Object.new]
|
82
83
|
end.to raise_error(ArgumentError, /must respond to/)
|
83
84
|
|
84
85
|
options = subject.parse_async_options [on_autoreconnect: callback]
|
@@ -86,10 +87,47 @@ describe 'em-pg-client options' do
|
|
86
87
|
options[:@on_autoreconnect].should be callback
|
87
88
|
end
|
88
89
|
|
90
|
+
it "should set only callable on_connect" do
|
91
|
+
expect do
|
92
|
+
subject.parse_async_options [on_connect: true]
|
93
|
+
end.to raise_error(ArgumentError, /must respond to/)
|
94
|
+
|
95
|
+
expect do
|
96
|
+
subject.parse_async_options ['on_connect' => Object.new]
|
97
|
+
end.to raise_error(ArgumentError, /must respond to/)
|
98
|
+
|
99
|
+
options = subject.parse_async_options [on_connect: callback]
|
100
|
+
options.should be_an_instance_of Hash
|
101
|
+
options[:@on_connect].should be callback
|
102
|
+
end
|
103
|
+
|
89
104
|
it "should raise error with obsolete argument" do
|
90
105
|
expect do
|
91
106
|
subject.parse_async_options [on_reconnect: true]
|
92
107
|
end.to raise_error ArgumentError
|
93
108
|
end
|
94
109
|
|
110
|
+
it "should set on_* options with a writer or a block" do
|
111
|
+
async_args = subject.parse_async_options([])
|
112
|
+
client = subject.allocate
|
113
|
+
client.instance_eval {
|
114
|
+
async_args.each {|k, v| instance_variable_set(k, v) }
|
115
|
+
}
|
116
|
+
client.should be_an_instance_of subject
|
117
|
+
client.on_connect.should be_nil
|
118
|
+
client.on_autoreconnect.should be_nil
|
119
|
+
client.on_connect = callback
|
120
|
+
client.on_connect.should be callback
|
121
|
+
client.on_autoreconnect = callback
|
122
|
+
client.on_autoreconnect.should be callback
|
123
|
+
client.on_connect = nil
|
124
|
+
client.on_connect.should be_nil
|
125
|
+
client.on_autoreconnect = nil
|
126
|
+
client.on_autoreconnect.should be_nil
|
127
|
+
client.on_connect(&callback).should be callback
|
128
|
+
client.on_connect.should be callback
|
129
|
+
client.on_autoreconnect(&callback).should be callback
|
130
|
+
client.on_autoreconnect.should be callback
|
131
|
+
end
|
132
|
+
|
95
133
|
end
|
@@ -19,6 +19,7 @@ describe PG::EM::ConnectionPool do
|
|
19
19
|
let(:pgerror) { PG::Error.new }
|
20
20
|
let(:fooerror) { RuntimeError.new 'foo' }
|
21
21
|
let(:timeout) { 10 }
|
22
|
+
let(:hook) { proc {|c| }}
|
22
23
|
|
23
24
|
it "should allocate one connection" do
|
24
25
|
client.should_receive(:new).with({}).once.and_return(client.allocate)
|
@@ -60,6 +61,8 @@ describe PG::EM::ConnectionPool do
|
|
60
61
|
client.allocate.tap do |conn|
|
61
62
|
conn.should_receive(:connect_timeout=).with(timeout).once
|
62
63
|
conn.should_receive(:query_timeout=).with(timeout).once
|
64
|
+
conn.should_receive(:on_autoreconnect=).with(hook).twice
|
65
|
+
conn.should_receive(:on_connect=).with(hook).twice
|
63
66
|
conn.should_receive(:finish).once
|
64
67
|
end
|
65
68
|
end.exactly(3)
|
@@ -87,6 +90,12 @@ describe PG::EM::ConnectionPool do
|
|
87
90
|
pool.allocated.length.should eq 2
|
88
91
|
pool.connect_timeout = timeout
|
89
92
|
pool.query_timeout = timeout
|
93
|
+
pool.on_connect = hook
|
94
|
+
pool.on_connect.should be hook
|
95
|
+
pool.on_connect(&hook)
|
96
|
+
pool.on_autoreconnect = hook
|
97
|
+
pool.on_autoreconnect.should be hook
|
98
|
+
pool.on_autoreconnect(&hook)
|
90
99
|
end
|
91
100
|
end.resume
|
92
101
|
end
|
@@ -99,12 +108,15 @@ describe PG::EM::ConnectionPool do
|
|
99
108
|
pool.max_size.should eq 3
|
100
109
|
pool.available.length.should eq 0
|
101
110
|
pool.allocated.length.should eq 0
|
111
|
+
pool.on_connect.should be hook
|
112
|
+
pool.on_autoreconnect.should be hook
|
102
113
|
pool.size.should eq 0
|
103
114
|
end
|
104
115
|
|
105
116
|
it "should allocate new connection with altered attributes" do
|
106
117
|
client.should_receive(:new).with(
|
107
|
-
{connect_timeout: timeout, query_timeout: timeout
|
118
|
+
{connect_timeout: timeout, query_timeout: timeout,
|
119
|
+
on_connect: hook, on_autoreconnect: hook}
|
108
120
|
).once.and_return(client.allocate)
|
109
121
|
pool = subject.new connection_class: client, size: 1, lazy: true
|
110
122
|
pool.should be_an_instance_of subject
|
@@ -112,8 +124,12 @@ describe PG::EM::ConnectionPool do
|
|
112
124
|
pool.query_timeout.should be_nil
|
113
125
|
pool.connect_timeout = timeout
|
114
126
|
pool.query_timeout = timeout
|
127
|
+
pool.on_connect = hook
|
128
|
+
pool.on_autoreconnect(&hook)
|
115
129
|
pool.connect_timeout.should eq timeout
|
116
130
|
pool.query_timeout.should eq timeout
|
131
|
+
pool.on_connect.should be hook
|
132
|
+
pool.on_autoreconnect.should be hook
|
117
133
|
pool.max_size.should eq 1
|
118
134
|
pool.available.length.should eq 0
|
119
135
|
pool.allocated.length.should eq 0
|
@@ -130,19 +146,27 @@ describe PG::EM::ConnectionPool do
|
|
130
146
|
options.should be_empty
|
131
147
|
pool.connect_timeout = timeout
|
132
148
|
pool.query_timeout = timeout
|
149
|
+
pool.on_connect = hook
|
150
|
+
pool.on_autoreconnect(&hook)
|
133
151
|
client.allocate.tap do |conn|
|
134
152
|
conn.should_receive(:connect_timeout=).with(timeout).once
|
135
153
|
conn.should_receive(:query_timeout=).with(timeout).once
|
154
|
+
conn.should_receive(:on_autoreconnect=).with(hook).once
|
155
|
+
conn.should_receive(:on_connect=).with(hook).once
|
136
156
|
end
|
137
157
|
end.once
|
138
158
|
client.should_receive(:connect_defer) do |options|
|
139
159
|
options.should be_empty
|
140
160
|
pool.connect_timeout = timeout
|
141
161
|
pool.query_timeout = timeout
|
162
|
+
pool.on_connect(&hook)
|
163
|
+
pool.on_autoreconnect = hook
|
142
164
|
deferrable.new.tap do |df|
|
143
165
|
df.succeed(client.allocate.tap do |conn|
|
144
166
|
conn.should_receive(:connect_timeout=).with(timeout).once
|
145
167
|
conn.should_receive(:query_timeout=).with(timeout).once
|
168
|
+
conn.should_receive(:on_autoreconnect=).with(hook).once
|
169
|
+
conn.should_receive(:on_connect=).with(hook).once
|
146
170
|
end)
|
147
171
|
end
|
148
172
|
end.once
|
metadata
CHANGED
@@ -1,36 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-pg-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Rafal Michalski
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-03-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: pg
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.17.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.17.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: eventmachine
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: em-synchrony
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ~>
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ~>
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -78,33 +69,29 @@ dependencies:
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: coveralls
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: 0.7.0
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: 0.7.0
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: simplecov
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - '>='
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: 0.8.2
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: 0.8.2
|
110
97
|
description: PostgreSQL asynchronous EventMachine client, based on pg interface (PG::Connection)
|
@@ -144,6 +131,8 @@ files:
|
|
144
131
|
- spec/em_client.rb
|
145
132
|
- spec/em_client_autoreconnect.rb
|
146
133
|
- spec/em_client_common.rb
|
134
|
+
- spec/em_client_on_connect.rb
|
135
|
+
- spec/em_connection_pool.rb
|
147
136
|
- spec/em_synchrony_client.rb
|
148
137
|
- spec/em_synchrony_client_autoreconnect.rb
|
149
138
|
- spec/pg_em_client_connect_finish.rb
|
@@ -155,6 +144,7 @@ files:
|
|
155
144
|
homepage: http://github.com/royaltm/ruby-em-pg-client
|
156
145
|
licenses:
|
157
146
|
- MIT
|
147
|
+
metadata: {}
|
158
148
|
post_install_message:
|
159
149
|
rdoc_options:
|
160
150
|
- --title
|
@@ -164,23 +154,21 @@ rdoc_options:
|
|
164
154
|
require_paths:
|
165
155
|
- lib
|
166
156
|
required_ruby_version: !ruby/object:Gem::Requirement
|
167
|
-
none: false
|
168
157
|
requirements:
|
169
|
-
- -
|
158
|
+
- - '>='
|
170
159
|
- !ruby/object:Gem::Version
|
171
160
|
version: 1.9.2
|
172
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
|
-
none: false
|
174
162
|
requirements:
|
175
|
-
- -
|
163
|
+
- - '>='
|
176
164
|
- !ruby/object:Gem::Version
|
177
165
|
version: '0'
|
178
166
|
requirements:
|
179
167
|
- PostgreSQL server
|
180
168
|
rubyforge_project:
|
181
|
-
rubygems_version:
|
169
|
+
rubygems_version: 2.0.14
|
182
170
|
signing_key:
|
183
|
-
specification_version:
|
171
|
+
specification_version: 4
|
184
172
|
summary: EventMachine PostgreSQL client
|
185
173
|
test_files:
|
186
174
|
- spec/pg_em_client_connect_timeout.rb
|
@@ -189,8 +177,10 @@ test_files:
|
|
189
177
|
- spec/connection_pool_helpers.rb
|
190
178
|
- spec/pg_em_client_options.rb
|
191
179
|
- spec/em_synchrony_client.rb
|
180
|
+
- spec/em_client_on_connect.rb
|
192
181
|
- spec/em_client_common.rb
|
193
182
|
- spec/em_synchrony_client_autoreconnect.rb
|
183
|
+
- spec/em_connection_pool.rb
|
194
184
|
- spec/pg_em_client_connect_finish.rb
|
195
185
|
- spec/pg_em_connection_pool.rb
|
196
186
|
- spec/em_client_autoreconnect.rb
|