em-pg-client 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/.travis.yml +31 -0
- data/Gemfile +5 -0
- data/HISTORY.md +10 -0
- data/README.md +31 -10
- data/Rakefile +62 -25
- data/benchmarks/em_pg.rb +15 -12
- data/em-pg-client.gemspec +3 -1
- data/examples/single_row_mode.rb +67 -0
- data/lib/pg/em-version.rb +1 -1
- data/lib/pg/em.rb +187 -54
- data/lib/pg/em/client/connect_watcher.rb +2 -8
- data/lib/pg/em/client/watcher.rb +45 -21
- data/spec/em_client_autoreconnect.rb +140 -8
- data/spec/em_client_common.rb +77 -0
- data/spec/em_synchrony_client.rb +77 -9
- data/spec/em_synchrony_client_autoreconnect.rb +120 -6
- data/spec/pg_em_client_connect_finish.rb +1 -1
- data/spec/pg_em_client_options.rb +13 -3
- data/spec/spec_helper.rb +9 -0
- metadata +42 -4
@@ -5,8 +5,10 @@ require 'date'
|
|
5
5
|
require 'em-synchrony'
|
6
6
|
require 'pg/em'
|
7
7
|
|
8
|
-
$pgserver_cmd_stop = %Q[sudo -i -u postgres pg_ctl -D "#{ENV['PGDATA']}" stop -s -m fast]
|
9
|
-
$pgserver_cmd_start = %Q[sudo -i -u postgres pg_ctl -D "#{ENV['PGDATA']}" start -s -w]
|
8
|
+
$pgserver_cmd_stop = ENV['PG_CTL_STOP_CMD'] || %Q[sudo -i -u postgres pg_ctl -D "#{ENV['PGDATA']}" stop -s -m fast]
|
9
|
+
$pgserver_cmd_start = ENV['PG_CTL_START_CMD'] || %Q[sudo -i -u postgres pg_ctl -D "#{ENV['PGDATA']}" start -s -w]
|
10
|
+
|
11
|
+
DISCONNECTED_ERROR = ENV['PGHOST'].include?('/') ? PG::UnableToSend : PG::ConnectionBad
|
10
12
|
|
11
13
|
shared_context 'em-synchrony-pg common' do
|
12
14
|
around(:each) do |testcase|
|
@@ -42,7 +44,7 @@ describe 'em-synchrony-pg default autoreconnect' do
|
|
42
44
|
system($pgserver_cmd_stop).should be_true
|
43
45
|
expect {
|
44
46
|
@tested_proc.call
|
45
|
-
}.to raise_error
|
47
|
+
}.to raise_error DISCONNECTED_ERROR
|
46
48
|
end
|
47
49
|
|
48
50
|
it "should get database size using query after server startup" do
|
@@ -57,10 +59,40 @@ describe 'em-synchrony-pg default autoreconnect' do
|
|
57
59
|
system($pgserver_cmd_start).should be_true
|
58
60
|
@tested_proc.call
|
59
61
|
end
|
60
|
-
end.to raise_error
|
62
|
+
end.to raise_error DISCONNECTED_ERROR
|
61
63
|
@tested_proc.call
|
62
64
|
end
|
63
65
|
|
66
|
+
it "should fail to get last result asynchronously after server restart" do
|
67
|
+
@client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
|
68
|
+
system($pgserver_cmd_stop).should be_true
|
69
|
+
system($pgserver_cmd_start).should be_true
|
70
|
+
expect do
|
71
|
+
@client.get_last_result
|
72
|
+
end.to raise_error PG::ConnectionBad
|
73
|
+
@client.status.should be PG::CONNECTION_OK
|
74
|
+
@client.get_last_result.should be_nil
|
75
|
+
EM.stop
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should fail to get each result asynchronously after server restart" do
|
79
|
+
@client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
|
80
|
+
system($pgserver_cmd_stop).should be_true
|
81
|
+
system($pgserver_cmd_start).should be_true
|
82
|
+
result = @client.get_result
|
83
|
+
result.should be_an_instance_of PG::Result
|
84
|
+
expect do
|
85
|
+
result.check
|
86
|
+
end.to raise_error PG::Error
|
87
|
+
@client.status.should be PG::CONNECTION_OK
|
88
|
+
expect do
|
89
|
+
@client.get_result
|
90
|
+
end.to raise_error PG::ConnectionBad
|
91
|
+
@client.status.should be PG::CONNECTION_OK
|
92
|
+
@client.get_result.should be_nil
|
93
|
+
EM.stop
|
94
|
+
end
|
95
|
+
|
64
96
|
before(:all) do
|
65
97
|
@tested_proc = proc do
|
66
98
|
@client.query('SELECT pg_database_size(current_database());') do |result|
|
@@ -98,10 +130,44 @@ describe 'em-synchrony-pg autoreconnect with on_autoreconnect' do
|
|
98
130
|
system($pgserver_cmd_start).should be_true
|
99
131
|
@tested_proc.call
|
100
132
|
end
|
101
|
-
end.to raise_error
|
133
|
+
end.to raise_error DISCONNECTED_ERROR
|
102
134
|
@tested_proc.call
|
103
135
|
end
|
104
136
|
|
137
|
+
it "should fail to get last result asynchronously after server restart" do
|
138
|
+
@client.on_autoreconnect = proc {
|
139
|
+
EM::DefaultDeferrable.new.tap {|df| df.succeed }
|
140
|
+
}
|
141
|
+
@client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
|
142
|
+
system($pgserver_cmd_stop).should be_true
|
143
|
+
system($pgserver_cmd_start).should be_true
|
144
|
+
expect do
|
145
|
+
@client.get_last_result
|
146
|
+
end.to raise_error PG::ConnectionBad
|
147
|
+
@client.status.should be PG::CONNECTION_OK
|
148
|
+
@client.get_last_result.should be_nil
|
149
|
+
EM.stop
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should fail to get each result asynchronously after server restart" do
|
153
|
+
@client.on_autoreconnect = proc { true }
|
154
|
+
@client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
|
155
|
+
system($pgserver_cmd_stop).should be_true
|
156
|
+
system($pgserver_cmd_start).should be_true
|
157
|
+
result = @client.get_result
|
158
|
+
result.should be_an_instance_of PG::Result
|
159
|
+
expect do
|
160
|
+
result.check
|
161
|
+
end.to raise_error PG::Error
|
162
|
+
@client.status.should be PG::CONNECTION_OK
|
163
|
+
expect do
|
164
|
+
@client.get_result
|
165
|
+
end.to raise_error PG::ConnectionBad
|
166
|
+
@client.status.should be PG::CONNECTION_OK
|
167
|
+
@client.get_result.should be_nil
|
168
|
+
EM.stop
|
169
|
+
end
|
170
|
+
|
105
171
|
before(:all) do
|
106
172
|
@tested_proc = proc do
|
107
173
|
@client.exec_prepared('get_db_size') do |result|
|
@@ -131,7 +197,7 @@ describe 'em-synchrony-pg with autoreconnect disabled' do
|
|
131
197
|
system($pgserver_cmd_start).should be_true
|
132
198
|
expect {
|
133
199
|
@tested_proc.call
|
134
|
-
}.to raise_error
|
200
|
+
}.to raise_error DISCONNECTED_ERROR
|
135
201
|
end
|
136
202
|
|
137
203
|
it "should get database size using query after manual connection reset" do
|
@@ -141,6 +207,54 @@ describe 'em-synchrony-pg with autoreconnect disabled' do
|
|
141
207
|
@tested_proc.call
|
142
208
|
end
|
143
209
|
|
210
|
+
it "should fail to get last result asynchronously after server restart" do
|
211
|
+
system($pgserver_cmd_stop).should be_true
|
212
|
+
system($pgserver_cmd_start).should be_true
|
213
|
+
begin
|
214
|
+
@client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
|
215
|
+
rescue PG::UnableToSend
|
216
|
+
end
|
217
|
+
expect do
|
218
|
+
@client.get_last_result
|
219
|
+
end.to raise_error PG::ConnectionBad
|
220
|
+
@client.status.should be PG::CONNECTION_BAD
|
221
|
+
expect do
|
222
|
+
@client.get_last_result
|
223
|
+
end.to raise_error PG::ConnectionBad
|
224
|
+
@client.reset
|
225
|
+
@client.status.should be PG::CONNECTION_OK
|
226
|
+
@client.get_last_result.should be_nil
|
227
|
+
EM.stop
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should fail to get each result asynchronously after server restart" do
|
231
|
+
system($pgserver_cmd_stop).should be_true
|
232
|
+
system($pgserver_cmd_start).should be_true
|
233
|
+
begin
|
234
|
+
@client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
|
235
|
+
rescue PG::UnableToSend
|
236
|
+
expect do
|
237
|
+
@client.get_result
|
238
|
+
end.to raise_error PG::ConnectionBad
|
239
|
+
@client.status.should be PG::CONNECTION_BAD
|
240
|
+
else
|
241
|
+
result = @client.get_result
|
242
|
+
result.should be_an_instance_of PG::Result
|
243
|
+
expect do
|
244
|
+
result.check
|
245
|
+
end.to raise_error PG::Error
|
246
|
+
@client.status.should be PG::CONNECTION_OK
|
247
|
+
end
|
248
|
+
expect do
|
249
|
+
@client.get_result
|
250
|
+
end.to raise_error PG::ConnectionBad
|
251
|
+
@client.status.should be PG::CONNECTION_BAD
|
252
|
+
@client.reset
|
253
|
+
@client.status.should be PG::CONNECTION_OK
|
254
|
+
@client.get_result.should be_nil
|
255
|
+
EM.stop
|
256
|
+
end
|
257
|
+
|
144
258
|
before(:all) do
|
145
259
|
@tested_proc = proc do
|
146
260
|
@client.query('SELECT pg_database_size(current_database());') do |result|
|
@@ -47,7 +47,7 @@ describe 'connect failure and finished? status' do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
describe 'with unix socket' do
|
50
|
-
let(:options) { {host: '/tmp', port: bogus_port} }
|
50
|
+
let(:options) { {host: ENV['PGHOST_UNIX'] || '/tmp', port: bogus_port} }
|
51
51
|
include_context 'test deferred'
|
52
52
|
include_context 'test blocking'
|
53
53
|
end unless RSpec.windows_os?
|
@@ -9,14 +9,18 @@ describe 'em-pg-client options' do
|
|
9
9
|
subject { PG::EM::Client }
|
10
10
|
|
11
11
|
let(:callback) { proc {|c, e| false } }
|
12
|
-
let(:args) { [{
|
13
|
-
|
12
|
+
let(:args) { [{
|
13
|
+
query_timeout: 1, async_autoreconnect: true, connect_timeout: 10, host: 'foo'
|
14
|
+
}]}
|
15
|
+
let(:str_key_args) { [{
|
16
|
+
'query_timeout'=>1, 'async_autoreconnect'=>true, 'connect_timeout'=>10, 'host'=>'foo'
|
17
|
+
}]}
|
14
18
|
let(:pgconn_args) { [{connect_timeout: 10, host: 'foo'}] }
|
15
19
|
let(:str_key_pgconn_args) { [{'connect_timeout'=>10, 'host'=>'foo'}] }
|
16
20
|
let(:async_options) { {
|
17
21
|
:@async_autoreconnect => true,
|
18
22
|
:@connect_timeout => 10,
|
19
|
-
:@query_timeout=>
|
23
|
+
:@query_timeout=>1,
|
20
24
|
:@on_autoreconnect=>nil,
|
21
25
|
:@async_command_aborted=>false} }
|
22
26
|
|
@@ -82,4 +86,10 @@ describe 'em-pg-client options' do
|
|
82
86
|
options[:@on_autoreconnect].should be callback
|
83
87
|
end
|
84
88
|
|
89
|
+
it "should raise error with obsolete argument" do
|
90
|
+
expect do
|
91
|
+
subject.parse_async_options [on_reconnect: true]
|
92
|
+
end.to raise_error ArgumentError
|
93
|
+
end
|
94
|
+
|
85
95
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-pg-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 2.
|
53
|
+
version: '2.14'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2.
|
61
|
+
version: '2.14'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: em-synchrony
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,6 +75,38 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 1.0.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: coveralls
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.7.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.7.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: simplecov
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.8.2
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.8.2
|
78
110
|
description: PostgreSQL asynchronous EventMachine client, based on pg interface (PG::Connection)
|
79
111
|
email: rafal@yeondir.com
|
80
112
|
executables: []
|
@@ -85,14 +117,18 @@ extra_rdoc_files:
|
|
85
117
|
- LICENSE
|
86
118
|
- HISTORY.md
|
87
119
|
files:
|
120
|
+
- .rspec
|
121
|
+
- .travis.yml
|
88
122
|
- .yardopts
|
89
123
|
- BENCHMARKS.md
|
124
|
+
- Gemfile
|
90
125
|
- HISTORY.md
|
91
126
|
- LICENSE
|
92
127
|
- README.md
|
93
128
|
- Rakefile
|
94
129
|
- benchmarks/em_pg.rb
|
95
130
|
- em-pg-client.gemspec
|
131
|
+
- examples/single_row_mode.rb
|
96
132
|
- lib/em-pg-client.rb
|
97
133
|
- lib/em-synchrony/pg.rb
|
98
134
|
- lib/pg/em-version.rb
|
@@ -112,6 +148,7 @@ files:
|
|
112
148
|
- spec/pg_em_client_options.rb
|
113
149
|
- spec/pg_em_connection_pool.rb
|
114
150
|
- spec/pg_em_featured_deferrable.rb
|
151
|
+
- spec/spec_helper.rb
|
115
152
|
homepage: http://github.com/royaltm/ruby-em-pg-client
|
116
153
|
licenses:
|
117
154
|
- MIT
|
@@ -144,6 +181,7 @@ specification_version: 3
|
|
144
181
|
summary: EventMachine PostgreSQL client
|
145
182
|
test_files:
|
146
183
|
- spec/pg_em_client_connect_timeout.rb
|
184
|
+
- spec/spec_helper.rb
|
147
185
|
- spec/em_client.rb
|
148
186
|
- spec/connection_pool_helpers.rb
|
149
187
|
- spec/pg_em_client_options.rb
|