em-pg-client 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -64,7 +64,7 @@ describe 'em-synchrony-pg default autoreconnect' do
64
64
  end
65
65
 
66
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());')
67
+ @client.send_query('SELECT pg_sleep(50); SELECT pg_database_size(current_database());')
68
68
  system($pgserver_cmd_stop).should be_true
69
69
  system($pgserver_cmd_start).should be_true
70
70
  expect do
@@ -76,7 +76,7 @@ describe 'em-synchrony-pg default autoreconnect' do
76
76
  end
77
77
 
78
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());')
79
+ @client.send_query('SELECT pg_sleep(50); SELECT pg_database_size(current_database());')
80
80
  system($pgserver_cmd_stop).should be_true
81
81
  system($pgserver_cmd_start).should be_true
82
82
  result = @client.get_result
@@ -93,6 +93,72 @@ describe 'em-synchrony-pg default autoreconnect' do
93
93
  EM.stop
94
94
  end
95
95
 
96
+ it "should fail wait_for_notify while server restarts" do
97
+ @client.status.should be PG::CONNECTION_OK
98
+ f = Fiber.current
99
+ notify_flag = false
100
+ Fiber.new do
101
+ expect {
102
+ @client.wait_for_notify do
103
+ raise "This block should not be called"
104
+ end
105
+ }.to raise_error(PG::ConnectionBad)
106
+ @client.status.should be PG::CONNECTION_OK
107
+ Fiber.new do
108
+ @client.wait_for_notify do |name,|
109
+ name.should eq 'em_synchrony_client_autoreconnect'
110
+ notify_flag = true
111
+ end.should eq 'em_synchrony_client_autoreconnect'
112
+ @client.query('UNLISTEN *').should be_an_instance_of PG::Result
113
+ f.resume
114
+ end.resume
115
+ @client.query('LISTEN em_synchrony_client_autoreconnect').should be_an_instance_of PG::Result
116
+ @client.query('NOTIFY em_synchrony_client_autoreconnect').should be_an_instance_of PG::Result
117
+ end.resume
118
+ system($pgserver_cmd_stop).should be_true
119
+ system($pgserver_cmd_start).should be_true
120
+ Fiber.yield
121
+ notify_flag.should be_true
122
+ end
123
+
124
+ it "should fail wait_for_notify and finish slow query while server restarts" do
125
+ @client.status.should be PG::CONNECTION_OK
126
+ f = Fiber.current
127
+ notify_flag = false
128
+ query_flag = false
129
+ start_time = Time.now
130
+ Fiber.new do
131
+ result = @client.query('SELECT pg_sleep(2); SELECT 42')
132
+ result.should be_an_instance_of PG::Result
133
+ result.getvalue(0,0).to_i.should eq 42
134
+ (Time.now - start_time).should be > 2
135
+ query_flag = true
136
+ end.resume
137
+ Fiber.new do
138
+ expect {
139
+ @client.wait_for_notify do
140
+ raise "This block should not be called"
141
+ end
142
+ }.to raise_error(PG::ConnectionBad)
143
+ query_flag.should be_true
144
+ @client.status.should be PG::CONNECTION_OK
145
+ Fiber.new do
146
+ @client.wait_for_notify do |name,|
147
+ name.should eq 'em_synchrony_client_autoreconnect'
148
+ notify_flag = true
149
+ end.should eq 'em_synchrony_client_autoreconnect'
150
+ @client.query('UNLISTEN *').should be_an_instance_of PG::Result
151
+ f.resume
152
+ end.resume
153
+ @client.query('LISTEN em_synchrony_client_autoreconnect').should be_an_instance_of PG::Result
154
+ @client.query('NOTIFY em_synchrony_client_autoreconnect').should be_an_instance_of PG::Result
155
+ end.resume
156
+ system($pgserver_cmd_stop).should be_true
157
+ system($pgserver_cmd_start).should be_true
158
+ Fiber.yield
159
+ notify_flag.should be_true
160
+ end
161
+
96
162
  before(:all) do
97
163
  @tested_proc = proc do
98
164
  @client.query('SELECT pg_database_size(current_database());') do |result|
@@ -138,7 +204,7 @@ describe 'em-synchrony-pg autoreconnect with on_autoreconnect' do
138
204
  @client.on_autoreconnect = proc {
139
205
  EM::DefaultDeferrable.new.tap {|df| df.succeed }
140
206
  }
141
- @client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
207
+ @client.send_query('SELECT pg_sleep(50); SELECT pg_database_size(current_database());')
142
208
  system($pgserver_cmd_stop).should be_true
143
209
  system($pgserver_cmd_start).should be_true
144
210
  expect do
@@ -151,7 +217,7 @@ describe 'em-synchrony-pg autoreconnect with on_autoreconnect' do
151
217
 
152
218
  it "should fail to get each result asynchronously after server restart" do
153
219
  @client.on_autoreconnect = proc { true }
154
- @client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
220
+ @client.send_query('SELECT pg_sleep(50); SELECT pg_database_size(current_database());')
155
221
  system($pgserver_cmd_stop).should be_true
156
222
  system($pgserver_cmd_start).should be_true
157
223
  result = @client.get_result
@@ -168,6 +234,76 @@ describe 'em-synchrony-pg autoreconnect with on_autoreconnect' do
168
234
  EM.stop
169
235
  end
170
236
 
237
+ it "should fail wait_for_notify while server restarts" do
238
+ @client.status.should be PG::CONNECTION_OK
239
+ @client.on_autoreconnect(&@on_autoreconnect)
240
+ f = Fiber.current
241
+ notify_flag = false
242
+ Fiber.new do
243
+ expect {
244
+ @client.wait_for_notify do
245
+ raise "This block should not be called"
246
+ end
247
+ }.to raise_error(PG::ConnectionBad)
248
+ @client.status.should be PG::CONNECTION_OK
249
+ Fiber.new do
250
+ @client.wait_for_notify do |name,|
251
+ name.should eq 'em_synchrony_client_autoreconnect'
252
+ notify_flag = true
253
+ end.should eq 'em_synchrony_client_autoreconnect'
254
+ @client.query('UNLISTEN *').should be_an_instance_of PG::Result
255
+ f.resume
256
+ end.resume
257
+ @client.query('LISTEN em_synchrony_client_autoreconnect').should be_an_instance_of PG::Result
258
+ @client.query('NOTIFY em_synchrony_client_autoreconnect').should be_an_instance_of PG::Result
259
+ end.resume
260
+ system($pgserver_cmd_stop).should be_true
261
+ system($pgserver_cmd_start).should be_true
262
+ Fiber.yield
263
+ notify_flag.should be_true
264
+ @tested_proc.call
265
+ end
266
+
267
+ it "should fail wait_for_notify and finish slow query while server restarts" do
268
+ @client.status.should be PG::CONNECTION_OK
269
+ @client.on_autoreconnect = @on_autoreconnect
270
+ f = Fiber.current
271
+ notify_flag = false
272
+ query_flag = false
273
+ start_time = Time.now
274
+ Fiber.new do
275
+ result = @client.query('SELECT pg_sleep(2); SELECT 42')
276
+ result.should be_an_instance_of PG::Result
277
+ result.getvalue(0,0).to_i.should eq 42
278
+ (Time.now - start_time).should be > 2
279
+ query_flag = true
280
+ end.resume
281
+ Fiber.new do
282
+ expect {
283
+ @client.wait_for_notify do
284
+ raise "This block should not be called"
285
+ end
286
+ }.to raise_error(PG::ConnectionBad)
287
+ query_flag.should be_true
288
+ @client.status.should be PG::CONNECTION_OK
289
+ Fiber.new do
290
+ @client.wait_for_notify do |name,|
291
+ name.should eq 'em_synchrony_client_autoreconnect'
292
+ notify_flag = true
293
+ end.should eq 'em_synchrony_client_autoreconnect'
294
+ @client.query('UNLISTEN *').should be_an_instance_of PG::Result
295
+ f.resume
296
+ end.resume
297
+ @client.query('LISTEN em_synchrony_client_autoreconnect').should be_an_instance_of PG::Result
298
+ @client.query('NOTIFY em_synchrony_client_autoreconnect').should be_an_instance_of PG::Result
299
+ end.resume
300
+ system($pgserver_cmd_stop).should be_true
301
+ system($pgserver_cmd_start).should be_true
302
+ Fiber.yield
303
+ notify_flag.should be_true
304
+ @tested_proc.call
305
+ end
306
+
171
307
  it "should execute on_connect before on_autoreconnect after server restart" do
172
308
  @client.on_connect.should be_nil
173
309
  run_on_connect = false
@@ -259,7 +395,7 @@ describe 'em-synchrony-pg with autoreconnect disabled' do
259
395
  system($pgserver_cmd_stop).should be_true
260
396
  system($pgserver_cmd_start).should be_true
261
397
  begin
262
- @client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
398
+ @client.send_query('SELECT pg_sleep(50); SELECT pg_database_size(current_database());')
263
399
  rescue PG::UnableToSend
264
400
  @client.status.should be PG::CONNECTION_BAD
265
401
  @client.get_last_result.should be_nil
@@ -280,7 +416,7 @@ describe 'em-synchrony-pg with autoreconnect disabled' do
280
416
  system($pgserver_cmd_stop).should be_true
281
417
  system($pgserver_cmd_start).should be_true
282
418
  begin
283
- @client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
419
+ @client.send_query('SELECT pg_sleep(50); SELECT pg_database_size(current_database());')
284
420
  rescue PG::UnableToSend
285
421
  @client.status.should be PG::CONNECTION_BAD
286
422
  @client.get_result.should be_nil
@@ -304,6 +440,113 @@ describe 'em-synchrony-pg with autoreconnect disabled' do
304
440
  EM.stop
305
441
  end
306
442
 
443
+ it "should fail wait_for_notify while server restarts" do
444
+ @client.status.should be PG::CONNECTION_OK
445
+ f = Fiber.current
446
+ notify_flag = false
447
+ Fiber.new do
448
+ expect {
449
+ @client.wait_for_notify do
450
+ raise "This block should not be called"
451
+ end
452
+ }.to raise_error(PG::ConnectionBad)
453
+ @client.status.should be PG::CONNECTION_BAD
454
+ expect {
455
+ @client.wait_for_notify do
456
+ raise "This block should not be called"
457
+ end
458
+ }.to raise_error(PG::ConnectionBad)
459
+ @client.status.should be PG::CONNECTION_BAD
460
+ @client.reset
461
+ @client.status.should be PG::CONNECTION_OK
462
+ Fiber.new do
463
+ @client.wait_for_notify do |name,|
464
+ name.should eq 'em_synchrony_client_autoreconnect'
465
+ notify_flag = true
466
+ end.should eq 'em_synchrony_client_autoreconnect'
467
+ @client.query('UNLISTEN *').should be_an_instance_of PG::Result
468
+ f.resume
469
+ end.resume
470
+ @client.query('LISTEN em_synchrony_client_autoreconnect').should be_an_instance_of PG::Result
471
+ @client.query('NOTIFY em_synchrony_client_autoreconnect').should be_an_instance_of PG::Result
472
+ end.resume
473
+ system($pgserver_cmd_stop).should be_true
474
+ system($pgserver_cmd_start).should be_true
475
+ Fiber.yield
476
+ notify_flag.should be_true
477
+ end
478
+
479
+ it "should fail both wait_for_notify and slow query while server restarts" do
480
+ @client.status.should be PG::CONNECTION_OK
481
+ f = Fiber.current
482
+ notify_flag = false
483
+ query_flag = false
484
+ Fiber.new do
485
+ expect {
486
+ @client.query('SELECT pg_sleep(2); SELECT 42')
487
+ }.to raise_error(PG::ConnectionBad)
488
+ query_flag = true
489
+ end.resume
490
+ Fiber.new do
491
+ expect {
492
+ @client.wait_for_notify do
493
+ raise "This block should not be called"
494
+ end
495
+ }.to raise_error(PG::ConnectionBad)
496
+ query_flag.should be_true
497
+ @client.status.should be PG::CONNECTION_BAD
498
+ expect {
499
+ @client.wait_for_notify do
500
+ raise "This block should not be called"
501
+ end
502
+ }.to raise_error(PG::ConnectionBad)
503
+ @client.status.should be PG::CONNECTION_BAD
504
+ expect {
505
+ @client.query('SELECT 1')
506
+ }.to raise_error(PG::UnableToSend)
507
+ @client.reset
508
+ @client.status.should be PG::CONNECTION_OK
509
+ Fiber.new do
510
+ @client.wait_for_notify do |name,|
511
+ name.should eq 'em_synchrony_client_autoreconnect'
512
+ notify_flag = true
513
+ end.should eq 'em_synchrony_client_autoreconnect'
514
+ @client.query('UNLISTEN *').should be_an_instance_of PG::Result
515
+ f.resume
516
+ end.resume
517
+ @client.query('LISTEN em_synchrony_client_autoreconnect').should be_an_instance_of PG::Result
518
+ @client.query('NOTIFY em_synchrony_client_autoreconnect').should be_an_instance_of PG::Result
519
+ end.resume
520
+ system($pgserver_cmd_stop).should be_true
521
+ system($pgserver_cmd_start).should be_true
522
+ Fiber.yield
523
+ notify_flag.should be_true
524
+ end
525
+
526
+ it "should fail wait_for_notify when server was shutdown" do
527
+ @client.status.should be PG::CONNECTION_OK
528
+ @client.wait_for_notify(0.1) do
529
+ raise "This block should not be called"
530
+ end.should be_nil
531
+ system($pgserver_cmd_stop).should be_true
532
+ expect {
533
+ @client.wait_for_notify do
534
+ raise "This block should not be called"
535
+ end
536
+ }.to raise_error(PG::ConnectionBad)
537
+ @client.status.should be PG::CONNECTION_BAD
538
+ expect {
539
+ @client.wait_for_notify do
540
+ raise "This block should not be called"
541
+ end
542
+ }.to raise_error(PG::ConnectionBad)
543
+ @client.status.should be PG::CONNECTION_BAD
544
+ system($pgserver_cmd_start).should be_true
545
+ @client.status.should be PG::CONNECTION_BAD
546
+ @client.reset
547
+ @client.status.should be PG::CONNECTION_OK
548
+ end
549
+
307
550
  before(:all) do
308
551
  @tested_proc = proc do
309
552
  @client.query('SELECT pg_database_size(current_database());') do |result|
@@ -13,7 +13,7 @@ shared_context 'test deferred' do
13
13
  ex.connection.should be_an_instance_of subject
14
14
  ex.connection.finished?.should be_false
15
15
  EM.stop
16
- end.should be_a_kind_of ::EM::DefaultDeferrable
16
+ end.should be_a_kind_of ::EM::Deferrable
17
17
  end
18
18
  end
19
19
  end
@@ -15,7 +15,7 @@ shared_context 'test async connect timeout' do
15
15
  ex.message.should include 'timeout expired (async)'
16
16
  (Time.now - start).should be > timeout
17
17
  EM.stop
18
- end.should be_a_kind_of ::EM::DefaultDeferrable
18
+ end.should be_a_kind_of ::EM::Deferrable
19
19
  this.should be :first
20
20
  end
21
21
 
metadata CHANGED
@@ -1,32 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-pg-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Rafal Michalski
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-03-22 00:00:00.000000000 Z
12
+ date: 2014-05-24 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: pg
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: 0.17.0
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.17.0
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: eventmachine
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rspec
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ~>
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: em-synchrony
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ~>
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ~>
67
76
  - !ruby/object:Gem::Version
@@ -69,29 +78,33 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: coveralls
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
- - - '>='
83
+ - - ! '>='
74
84
  - !ruby/object:Gem::Version
75
85
  version: 0.7.0
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
- - - '>='
91
+ - - ! '>='
81
92
  - !ruby/object:Gem::Version
82
93
  version: 0.7.0
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: simplecov
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
- - - '>='
99
+ - - ! '>='
88
100
  - !ruby/object:Gem::Version
89
101
  version: 0.8.2
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
- - - '>='
107
+ - - ! '>='
95
108
  - !ruby/object:Gem::Version
96
109
  version: 0.8.2
97
110
  description: PostgreSQL asynchronous EventMachine client, based on pg interface (PG::Connection)
@@ -144,7 +157,6 @@ files:
144
157
  homepage: http://github.com/royaltm/ruby-em-pg-client
145
158
  licenses:
146
159
  - MIT
147
- metadata: {}
148
160
  post_install_message:
149
161
  rdoc_options:
150
162
  - --title
@@ -154,21 +166,23 @@ rdoc_options:
154
166
  require_paths:
155
167
  - lib
156
168
  required_ruby_version: !ruby/object:Gem::Requirement
169
+ none: false
157
170
  requirements:
158
- - - '>='
171
+ - - ! '>='
159
172
  - !ruby/object:Gem::Version
160
173
  version: 1.9.2
161
174
  required_rubygems_version: !ruby/object:Gem::Requirement
175
+ none: false
162
176
  requirements:
163
- - - '>='
177
+ - - ! '>='
164
178
  - !ruby/object:Gem::Version
165
179
  version: '0'
166
180
  requirements:
167
181
  - PostgreSQL server
168
182
  rubyforge_project:
169
- rubygems_version: 2.0.14
183
+ rubygems_version: 1.8.25
170
184
  signing_key:
171
- specification_version: 4
185
+ specification_version: 3
172
186
  summary: EventMachine PostgreSQL client
173
187
  test_files:
174
188
  - spec/pg_em_client_connect_timeout.rb