em-pg-client 0.3.3 → 0.3.4

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.
@@ -19,7 +19,7 @@ describe PG::EM::Client do
19
19
  [id, DateTime.now, data]) do |result|
20
20
  result.should be_an_instance_of PG::Result
21
21
  iter.return(DateTime.parse(result[0]['cdate']))
22
- end.should be_a_kind_of ::EM::DefaultDeferrable
22
+ end.should be_a_kind_of ::EM::Deferrable
23
23
  }, proc{ |results|
24
24
  @cdates.replace results
25
25
  results.length.should == @values.length
@@ -12,7 +12,9 @@ DISCONNECTED_ERROR = ENV['PGHOST'].include?('/') ? PG::UnableToSend : PG::Connec
12
12
 
13
13
  shared_context 'pg-em common' do
14
14
  around(:each) do |testcase|
15
- EM.run(&testcase)
15
+ EM.run do
16
+ EM.stop if testcase.call.is_a? Exception
17
+ end
16
18
  end
17
19
 
18
20
  after(:all) do
@@ -71,7 +73,7 @@ describe 'pg-em default autoreconnect' do
71
73
  @client.query_defer('SELECT pg_database_size(current_database());') do |ex|
72
74
  ex.should be_an_instance_of DISCONNECTED_ERROR
73
75
  EM.stop
74
- end.should be_a_kind_of ::EM::DefaultDeferrable
76
+ end.should be_a_kind_of ::EM::Deferrable
75
77
  end
76
78
 
77
79
  it "should get database size using query after server startup" do
@@ -85,7 +87,7 @@ describe 'pg-em default autoreconnect' do
85
87
  @client.query_defer('SELLECT 1') do |ex|
86
88
  ex.should be_an_instance_of PG::SyntaxError
87
89
  EM.stop
88
- end.should be_a_kind_of ::EM::DefaultDeferrable
90
+ end.should be_a_kind_of ::EM::Deferrable
89
91
  end
90
92
 
91
93
  it "should fail when in transaction after server restart" do
@@ -96,12 +98,12 @@ describe 'pg-em default autoreconnect' do
96
98
  @client.query_defer('SELECT pg_database_size(current_database());') do |ex|
97
99
  ex.should be_an_instance_of DISCONNECTED_ERROR
98
100
  @tested_proc.call
99
- end.should be_a_kind_of ::EM::DefaultDeferrable
101
+ end.should be_a_kind_of ::EM::Deferrable
100
102
  end
101
103
  end
102
104
 
103
105
  it "should fail to get last result asynchronously after server restart" do
104
- @client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
106
+ @client.send_query('SELECT pg_sleep(50); SELECT pg_database_size(current_database());')
105
107
  system($pgserver_cmd_stop).should be_true
106
108
  system($pgserver_cmd_start).should be_true
107
109
  @client.get_last_result_defer do |ex|
@@ -111,11 +113,11 @@ describe 'pg-em default autoreconnect' do
111
113
  result.should be_nil
112
114
  EM.stop
113
115
  end
114
- end.should be_a_kind_of EM::DefaultDeferrable
116
+ end.should be_a_kind_of ::EM::Deferrable
115
117
  end
116
118
 
117
119
  it "should fail to get each result asynchronously after server restart" do
118
- @client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
120
+ @client.send_query('SELECT pg_sleep(50); SELECT pg_database_size(current_database());')
119
121
  system($pgserver_cmd_stop).should be_true
120
122
  system($pgserver_cmd_start).should be_true
121
123
  @client.get_result_defer do |result|
@@ -130,18 +132,75 @@ describe 'pg-em default autoreconnect' do
130
132
  @client.get_result_defer do |result|
131
133
  result.should be_nil
132
134
  EM.stop
133
- end.should be_a_kind_of ::EM::DefaultDeferrable
134
- end.should be_a_kind_of EM::DefaultDeferrable
135
+ end.should be_a_kind_of ::EM::Deferrable
136
+ end.should be_a_kind_of ::EM::Deferrable
135
137
  end
136
138
  end
137
139
 
140
+ it "should fail wait_for_notify while server restarts" do
141
+ @client.status.should be PG::CONNECTION_OK
142
+ @client.wait_for_notify_defer do |ex|
143
+ ex.should be_an_instance_of PG::ConnectionBad
144
+ @client.status.should be PG::CONNECTION_OK
145
+ @client.wait_for_notify_defer do |notification|
146
+ notification.should be_an_instance_of Hash
147
+ notification[:relname].should eq 'em_client_autoreconnect'
148
+ @client.query_defer('UNLISTEN *') do |result|
149
+ result.should be_an_instance_of PG::Result
150
+ EM.stop
151
+ end.should be_a_kind_of ::EM::Deferrable
152
+ end.should be_a_kind_of ::EM::Deferrable
153
+ @client.query_defer('LISTEN em_client_autoreconnect') do |result|
154
+ result.should be_an_instance_of PG::Result
155
+ @client.query_defer('NOTIFY em_client_autoreconnect') do |result|
156
+ result.should be_an_instance_of PG::Result
157
+ end.should be_a_kind_of ::EM::Deferrable
158
+ end.should be_a_kind_of ::EM::Deferrable
159
+ end.should be_a_kind_of ::EM::Deferrable
160
+ system($pgserver_cmd_stop).should be_true
161
+ system($pgserver_cmd_start).should be_true
162
+ end
163
+
164
+ it "should fail wait_for_notify and finish slow query while server restarts" do
165
+ @client.status.should be PG::CONNECTION_OK
166
+ start_time = Time.now
167
+ query_flag = false
168
+ @client.query_defer('SELECT pg_sleep(2); SELECT 42') do |result|
169
+ result.should be_an_instance_of PG::Result
170
+ result.getvalue(0,0).to_i.should eq 42
171
+ (Time.now - start_time).should be > 2
172
+ query_flag = true
173
+ end.should be_a_kind_of ::EM::Deferrable
174
+ @client.wait_for_notify_defer do |ex|
175
+ query_flag.should be_true
176
+ ex.should be_an_instance_of PG::ConnectionBad
177
+ @client.status.should be PG::CONNECTION_OK
178
+ @client.wait_for_notify_defer do |notification|
179
+ notification.should be_an_instance_of Hash
180
+ notification[:relname].should eq 'em_client_autoreconnect'
181
+ @client.query_defer('UNLISTEN *') do |result|
182
+ result.should be_an_instance_of PG::Result
183
+ EM.stop
184
+ end.should be_a_kind_of ::EM::Deferrable
185
+ end.should be_a_kind_of ::EM::Deferrable
186
+ @client.query_defer('LISTEN em_client_autoreconnect') do |result|
187
+ result.should be_an_instance_of PG::Result
188
+ @client.query_defer('NOTIFY em_client_autoreconnect') do |result|
189
+ result.should be_an_instance_of PG::Result
190
+ end.should be_a_kind_of ::EM::Deferrable
191
+ end.should be_a_kind_of ::EM::Deferrable
192
+ end.should be_a_kind_of ::EM::Deferrable
193
+ system($pgserver_cmd_stop).should be_true
194
+ system($pgserver_cmd_start).should be_true
195
+ end
196
+
138
197
  before(:all) do
139
198
  @tested_proc = proc do
140
199
  @client.query_defer('SELECT pg_database_size(current_database());') do |result|
141
200
  result.should be_an_instance_of PG::Result
142
201
  result[0]['pg_database_size'].to_i.should be > 0
143
202
  EM.stop
144
- end.should be_a_kind_of ::EM::DefaultDeferrable
203
+ end.should be_a_kind_of ::EM::Deferrable
145
204
  end
146
205
  @options = {async_autoreconnect: true}
147
206
  @client = PG::EM::Client.new(@options)
@@ -176,7 +235,7 @@ describe 'pg-em autoreconnect with on_autoreconnect' do
176
235
  @client.query_defer('SELLECT 1') do |ex|
177
236
  ex.should be_an_instance_of PG::SyntaxError
178
237
  EM.stop
179
- end.should be_a_kind_of ::EM::DefaultDeferrable
238
+ end.should be_a_kind_of ::EM::Deferrable
180
239
  end
181
240
 
182
241
  it "should fail when in transaction after server restart" do
@@ -187,7 +246,7 @@ describe 'pg-em autoreconnect with on_autoreconnect' do
187
246
  @client.query_defer('SELECT pg_database_size(current_database());') do |ex|
188
247
  ex.should be_an_instance_of DISCONNECTED_ERROR
189
248
  @tested_proc.call
190
- end.should be_a_kind_of ::EM::DefaultDeferrable
249
+ end.should be_a_kind_of ::EM::Deferrable
191
250
  end
192
251
  end
193
252
 
@@ -198,7 +257,7 @@ describe 'pg-em autoreconnect with on_autoreconnect' do
198
257
  @client.query_defer('SELECT pg_database_size(current_database());') do |ex|
199
258
  ex.should be_an_instance_of DISCONNECTED_ERROR
200
259
  EM.stop
201
- end.should be_a_kind_of ::EM::DefaultDeferrable
260
+ end.should be_a_kind_of ::EM::Deferrable
202
261
  end
203
262
 
204
263
  it "should complete on true from on_autoreconnect after server restart" do
@@ -209,7 +268,7 @@ describe 'pg-em autoreconnect with on_autoreconnect' do
209
268
  result.should be_an_instance_of PG::Result
210
269
  result[0]['pg_database_size'].to_i.should be > 0
211
270
  EM.stop
212
- end.should be_a_kind_of ::EM::DefaultDeferrable
271
+ end.should be_a_kind_of ::EM::Deferrable
213
272
  end
214
273
 
215
274
  it "should fail on query with true from on_autoreconnect after restart" do
@@ -219,7 +278,7 @@ describe 'pg-em autoreconnect with on_autoreconnect' do
219
278
  @client.query_defer('SELLECT 1') do |ex|
220
279
  ex.should be_an_instance_of PG::SyntaxError
221
280
  EM.stop
222
- end.should be_a_kind_of ::EM::DefaultDeferrable
281
+ end.should be_a_kind_of ::EM::Deferrable
223
282
  end
224
283
 
225
284
  it "should fail on on_autoreconnect deferrable fail after server restart" do
@@ -231,7 +290,7 @@ describe 'pg-em autoreconnect with on_autoreconnect' do
231
290
  @client.query_defer('SELECT 1') do |ex|
232
291
  ex.should be :boo
233
292
  EM.stop
234
- end.should be_a_kind_of ::EM::DefaultDeferrable
293
+ end.should be_a_kind_of ::EM::Deferrable
235
294
  end
236
295
 
237
296
  it "should fail on raised error in on_autoreconnect after server restart" do
@@ -243,12 +302,12 @@ describe 'pg-em autoreconnect with on_autoreconnect' do
243
302
  @client.query_defer('SELECT 1') do |ex|
244
303
  ex.should be_an_instance_of TypeError
245
304
  EM.stop
246
- end.should be_a_kind_of ::EM::DefaultDeferrable
305
+ end.should be_a_kind_of ::EM::Deferrable
247
306
  end
248
307
 
249
308
  it "should fail to get last result asynchronously after server restart" do
250
309
  @client.on_autoreconnect = proc { true }
251
- @client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
310
+ @client.send_query('SELECT pg_sleep(50); SELECT pg_database_size(current_database());')
252
311
  system($pgserver_cmd_stop).should be_true
253
312
  system($pgserver_cmd_start).should be_true
254
313
  @client.get_last_result_defer do |ex|
@@ -258,14 +317,14 @@ describe 'pg-em autoreconnect with on_autoreconnect' do
258
317
  result.should be_nil
259
318
  EM.stop
260
319
  end
261
- end.should be_a_kind_of EM::DefaultDeferrable
320
+ end.should be_a_kind_of ::EM::Deferrable
262
321
  end
263
322
 
264
323
  it "should fail to get each result asynchronously after server restart" do
265
324
  @client.on_autoreconnect = proc {
266
- EM::DefaultDeferrable.new.tap {|df| df.succeed }
325
+ ::EM::DefaultDeferrable.new.tap {|df| df.succeed }
267
326
  }
268
- @client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
327
+ @client.send_query('SELECT pg_sleep(50); SELECT pg_database_size(current_database());')
269
328
  system($pgserver_cmd_stop).should be_true
270
329
  system($pgserver_cmd_start).should be_true
271
330
  @client.get_result_defer do |result|
@@ -280,11 +339,70 @@ describe 'pg-em autoreconnect with on_autoreconnect' do
280
339
  @client.get_result_defer do |result|
281
340
  result.should be_nil
282
341
  EM.stop
283
- end.should be_a_kind_of ::EM::DefaultDeferrable
284
- end.should be_a_kind_of EM::DefaultDeferrable
342
+ end.should be_a_kind_of ::EM::Deferrable
343
+ end.should be_a_kind_of ::EM::Deferrable
285
344
  end
286
345
  end
287
346
 
347
+ it "should fail wait_for_notify while server restarts" do
348
+ @client.status.should be PG::CONNECTION_OK
349
+ @client.on_autoreconnect(&@on_autoreconnect)
350
+ @client.wait_for_notify_defer do |ex|
351
+ ex.should be_an_instance_of PG::ConnectionBad
352
+ @client.status.should be PG::CONNECTION_OK
353
+ @client.wait_for_notify_defer do |notification|
354
+ notification.should be_an_instance_of Hash
355
+ notification[:relname].should eq 'em_client_autoreconnect'
356
+ @client.query_defer('UNLISTEN *') do |result|
357
+ result.should be_an_instance_of PG::Result
358
+ @tested_proc.call
359
+ end.should be_a_kind_of ::EM::Deferrable
360
+ end.should be_a_kind_of ::EM::Deferrable
361
+ @client.query_defer('LISTEN em_client_autoreconnect') do |result|
362
+ result.should be_an_instance_of PG::Result
363
+ @client.query_defer('NOTIFY em_client_autoreconnect') do |result|
364
+ result.should be_an_instance_of PG::Result
365
+ end.should be_a_kind_of ::EM::Deferrable
366
+ end.should be_a_kind_of ::EM::Deferrable
367
+ end.should be_a_kind_of ::EM::Deferrable
368
+ system($pgserver_cmd_stop).should be_true
369
+ system($pgserver_cmd_start).should be_true
370
+ end
371
+
372
+ it "should fail wait_for_notify and finish slow query while server restarts" do
373
+ @client.status.should be PG::CONNECTION_OK
374
+ @client.on_autoreconnect = @on_autoreconnect
375
+ start_time = Time.now
376
+ query_flag = false
377
+ @client.query_defer('SELECT pg_sleep(2); SELECT 42') do |result|
378
+ result.should be_an_instance_of PG::Result
379
+ result.getvalue(0,0).to_i.should eq 42
380
+ (Time.now - start_time).should be > 2
381
+ query_flag = true
382
+ end.should be_a_kind_of ::EM::Deferrable
383
+ @client.wait_for_notify_defer do |ex|
384
+ query_flag.should be_true
385
+ ex.should be_an_instance_of PG::ConnectionBad
386
+ @client.status.should be PG::CONNECTION_OK
387
+ @client.wait_for_notify_defer do |notification|
388
+ notification.should be_an_instance_of Hash
389
+ notification[:relname].should eq 'em_client_autoreconnect'
390
+ @client.query_defer('UNLISTEN *') do |result|
391
+ result.should be_an_instance_of PG::Result
392
+ @tested_proc.call
393
+ end.should be_a_kind_of ::EM::Deferrable
394
+ end.should be_a_kind_of ::EM::Deferrable
395
+ @client.query_defer('LISTEN em_client_autoreconnect') do |result|
396
+ result.should be_an_instance_of PG::Result
397
+ @client.query_defer('NOTIFY em_client_autoreconnect') do |result|
398
+ result.should be_an_instance_of PG::Result
399
+ end.should be_a_kind_of ::EM::Deferrable
400
+ end.should be_a_kind_of ::EM::Deferrable
401
+ end.should be_a_kind_of ::EM::Deferrable
402
+ system($pgserver_cmd_stop).should be_true
403
+ system($pgserver_cmd_start).should be_true
404
+ end
405
+
288
406
  it "should execute on_connect before on_autoreconnect after server restart" do
289
407
  @client.on_connect.should be_nil
290
408
  run_on_connect = false
@@ -327,7 +445,7 @@ describe 'pg-em autoreconnect with on_autoreconnect' do
327
445
  run_on_connect.should be_true
328
446
  run_on_autoreconnect.should be_false
329
447
  EM.stop
330
- end.should be_a_kind_of ::EM::DefaultDeferrable
448
+ end.should be_a_kind_of ::EM::Deferrable
331
449
  end
332
450
 
333
451
  before(:all) do
@@ -336,11 +454,11 @@ describe 'pg-em autoreconnect with on_autoreconnect' do
336
454
  result.should be_an_instance_of PG::Result
337
455
  result[0]['pg_database_size'].to_i.should be > 0
338
456
  EM.stop
339
- end.should be_a_kind_of ::EM::DefaultDeferrable
457
+ end.should be_a_kind_of ::EM::Deferrable
340
458
  end
341
459
  @on_autoreconnect = proc do |client, ex|
342
460
  df = client.prepare_defer('get_db_size', 'SELECT pg_database_size(current_database());')
343
- df.should be_a_kind_of ::EM::DefaultDeferrable
461
+ df.should be_a_kind_of ::EM::Deferrable
344
462
  df
345
463
  end
346
464
  @options = {on_autoreconnect: @on_autoreconnect}
@@ -364,7 +482,7 @@ describe 'pg-em with autoreconnect disabled' do
364
482
  ex.should be_an_instance_of DISCONNECTED_ERROR
365
483
  @client.status.should be PG::CONNECTION_BAD
366
484
  EM.stop
367
- end.should be_a_kind_of ::EM::DefaultDeferrable
485
+ end.should be_a_kind_of ::EM::Deferrable
368
486
  end
369
487
 
370
488
  it "should get database size using query after async manual connection reset" do
@@ -373,10 +491,11 @@ describe 'pg-em with autoreconnect disabled' do
373
491
  conn.should be @client
374
492
  @client.status.should be PG::CONNECTION_OK
375
493
  @tested_proc.call
376
- end.should be_a_kind_of ::EM::DefaultDeferrable
494
+ end.should be_a_kind_of ::EM::Deferrable
377
495
  end
378
496
 
379
497
  it "should fail to get last result asynchronously after server restart" do
498
+ @client.status.should be PG::CONNECTION_OK
380
499
  check_get_last_result = proc do
381
500
  @client.get_last_result_defer do |result|
382
501
  result.should be_nil
@@ -384,30 +503,31 @@ describe 'pg-em with autoreconnect disabled' do
384
503
  conn.should be @client
385
504
  @client.status.should be PG::CONNECTION_OK
386
505
  EM.stop
387
- end.should be_a_kind_of ::EM::DefaultDeferrable
506
+ end.should be_a_kind_of ::EM::Deferrable
388
507
  end
389
508
  end
390
509
  system($pgserver_cmd_stop).should be_true
391
510
  system($pgserver_cmd_start).should be_true
392
511
  begin
393
- @client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
512
+ @client.send_query('SELECT pg_sleep(50); SELECT pg_database_size(current_database());')
394
513
  rescue PG::UnableToSend
395
514
  @client.status.should be PG::CONNECTION_BAD
396
515
  @client.get_last_result_defer do |ex|
397
516
  ex.should be_nil
398
517
  @client.status.should be PG::CONNECTION_BAD
399
518
  check_get_last_result.call
400
- end.should be_a_kind_of EM::DefaultDeferrable
519
+ end.should be_a_kind_of ::EM::Deferrable
401
520
  else
402
521
  @client.get_last_result_defer do |ex|
403
522
  ex.should be_an_instance_of PG::ConnectionBad
404
523
  @client.status.should be PG::CONNECTION_BAD
405
524
  check_get_last_result.call
406
- end.should be_a_kind_of EM::DefaultDeferrable
525
+ end.should be_a_kind_of ::EM::Deferrable
407
526
  end
408
527
  end
409
528
 
410
529
  it "should fail to get each result asynchronously after server restart" do
530
+ @client.status.should be PG::CONNECTION_OK
411
531
  check_get_result = proc do |expected_class|
412
532
  @client.get_result_defer do |result|
413
533
  result.should be_an_instance_of expected_class
@@ -416,13 +536,13 @@ describe 'pg-em with autoreconnect disabled' do
416
536
  conn.should be @client
417
537
  @client.status.should be PG::CONNECTION_OK
418
538
  EM.stop
419
- end.should be_a_kind_of ::EM::DefaultDeferrable
420
- end.should be_a_kind_of EM::DefaultDeferrable
539
+ end.should be_a_kind_of ::EM::Deferrable
540
+ end.should be_a_kind_of ::EM::Deferrable
421
541
  end
422
542
  system($pgserver_cmd_stop).should be_true
423
543
  system($pgserver_cmd_start).should be_true
424
544
  begin
425
- @client.send_query('SELECT pg_sleep(5); SELECT pg_database_size(current_database());')
545
+ @client.send_query('SELECT pg_sleep(50); SELECT pg_database_size(current_database());')
426
546
  rescue PG::UnableToSend
427
547
  @client.get_result_defer do |result|
428
548
  result.should be_nil
@@ -441,13 +561,110 @@ describe 'pg-em with autoreconnect disabled' do
441
561
  end
442
562
  end
443
563
 
564
+ it "should fail wait_for_notify while server restarts" do
565
+ @client.status.should be PG::CONNECTION_OK
566
+ @client.on_autoreconnect(&@on_autoreconnect)
567
+ @client.wait_for_notify_defer do |ex|
568
+ ex.should be_an_instance_of PG::ConnectionBad
569
+ @client.status.should be PG::CONNECTION_BAD
570
+ @client.wait_for_notify_defer do |ex|
571
+ ex.should be_an_instance_of PG::ConnectionBad
572
+ @client.status.should be PG::CONNECTION_BAD
573
+ @client.reset_defer do |conn|
574
+ conn.should be @client
575
+ @client.status.should be PG::CONNECTION_OK
576
+ @client.wait_for_notify_defer do |notification|
577
+ notification.should be_an_instance_of Hash
578
+ notification[:relname].should eq 'em_client_autoreconnect'
579
+ @client.query_defer('UNLISTEN *') do |result|
580
+ result.should be_an_instance_of PG::Result
581
+ EM.stop
582
+ end.should be_a_kind_of ::EM::Deferrable
583
+ end.should be_a_kind_of ::EM::Deferrable
584
+ @client.query_defer('LISTEN em_client_autoreconnect') do |result|
585
+ result.should be_an_instance_of PG::Result
586
+ @client.query_defer('NOTIFY em_client_autoreconnect') do |result|
587
+ result.should be_an_instance_of PG::Result
588
+ end.should be_a_kind_of ::EM::Deferrable
589
+ end.should be_a_kind_of ::EM::Deferrable
590
+ end.should be_a_kind_of ::EM::Deferrable
591
+ end.should be_a_kind_of ::EM::Deferrable
592
+ end.should be_a_kind_of ::EM::Deferrable
593
+ system($pgserver_cmd_stop).should be_true
594
+ system($pgserver_cmd_start).should be_true
595
+ end
596
+
597
+ it "should fail both wait_for_notify and slow query while server restarts" do
598
+ @client.status.should be PG::CONNECTION_OK
599
+ @client.on_autoreconnect = @on_autoreconnect
600
+ query_flag = false
601
+ @client.query_defer('SELECT pg_sleep(2); SELECT 42') do |ex|
602
+ ex.should be_an_instance_of PG::ConnectionBad
603
+ query_flag = true
604
+ end.should be_a_kind_of ::EM::Deferrable
605
+ @client.wait_for_notify_defer do |ex|
606
+ query_flag.should be_true
607
+ ex.should be_an_instance_of PG::ConnectionBad
608
+ @client.status.should be PG::CONNECTION_BAD
609
+ @client.wait_for_notify_defer do |ex|
610
+ ex.should be_an_instance_of PG::ConnectionBad
611
+ @client.status.should be PG::CONNECTION_BAD
612
+ @client.query_defer('SELECT 1') do |ex|
613
+ ex.should be_an_instance_of PG::UnableToSend
614
+ @client.reset_defer do |conn|
615
+ conn.should be @client
616
+ @client.status.should be PG::CONNECTION_OK
617
+ @client.wait_for_notify_defer do |notification|
618
+ notification.should be_an_instance_of Hash
619
+ notification[:relname].should eq 'em_client_autoreconnect'
620
+ @client.query_defer('UNLISTEN *') do |result|
621
+ result.should be_an_instance_of PG::Result
622
+ EM.stop
623
+ end.should be_a_kind_of ::EM::Deferrable
624
+ end.should be_a_kind_of ::EM::Deferrable
625
+ @client.query_defer('LISTEN em_client_autoreconnect') do |result|
626
+ result.should be_an_instance_of PG::Result
627
+ @client.query_defer('NOTIFY em_client_autoreconnect') do |result|
628
+ result.should be_an_instance_of PG::Result
629
+ end.should be_a_kind_of ::EM::Deferrable
630
+ end.should be_a_kind_of ::EM::Deferrable
631
+ end.should be_a_kind_of ::EM::Deferrable
632
+ end.should be_a_kind_of ::EM::Deferrable
633
+ end.should be_a_kind_of ::EM::Deferrable
634
+ end.should be_a_kind_of ::EM::Deferrable
635
+ system($pgserver_cmd_stop).should be_true
636
+ system($pgserver_cmd_start).should be_true
637
+ end
638
+
639
+ it "should fail wait_for_notify when server was shutdown" do
640
+ @client.status.should be PG::CONNECTION_OK
641
+ @client.wait_for_notify_defer(0.1) do |notification|
642
+ notification.should be_nil
643
+ system($pgserver_cmd_stop).should be_true
644
+ @client.wait_for_notify_defer do |ex|
645
+ ex.should be_an_instance_of PG::ConnectionBad
646
+ @client.status.should be PG::CONNECTION_BAD
647
+ @client.wait_for_notify_defer do |ex|
648
+ ex.should be_an_instance_of PG::ConnectionBad
649
+ system($pgserver_cmd_start).should be_true
650
+ @client.status.should be PG::CONNECTION_BAD
651
+ @client.reset_defer do |client|
652
+ client.should be @client
653
+ @client.status.should be PG::CONNECTION_OK
654
+ EM.stop
655
+ end.should be_a_kind_of ::EM::Deferrable
656
+ end.should be_a_kind_of ::EM::Deferrable
657
+ end.should be_a_kind_of ::EM::Deferrable
658
+ end.should be_a_kind_of ::EM::Deferrable
659
+ end
660
+
444
661
  before(:all) do
445
662
  @tested_proc = proc do
446
663
  @client.query_defer('SELECT pg_database_size(current_database());') do |result|
447
664
  result.should be_an_instance_of PG::Result
448
665
  result[0]['pg_database_size'].to_i.should be > 0
449
666
  EM.stop
450
- end.should be_a_kind_of ::EM::DefaultDeferrable
667
+ end.should be_a_kind_of ::EM::Deferrable
451
668
  end
452
669
  @client = PG::EM::Client.new
453
670
  @client.set_notice_processor {|msg| puts "warning from pgsql: #{msg.to_s.chomp.inspect}"}