@@ -42,8 +42,42 @@ def n_close(conns):
42
42
43
43
notices = []
44
44
45
+ def debug_output (qs , qs_len , pid , query , expected ):
46
+ something_happened = False
47
+ if (qs_len and len (qs ) != qs_len ):
48
+ print "len(qs): " , len (qs ), ", expected: " , qs_len
49
+ something_happened = True
50
+ if (pid and qs [0 ][0 ] != pid ):
51
+ print "qs[0][0]: " , qs [0 ][0 ], " = " , pid
52
+ something_happened = True
53
+ if (qs [0 ][1 ] != 0 ):
54
+ print "qs[0][1]: " , qs [0 ][1 ], ", expected: 0"
55
+ something_happened = True
56
+ if (qs [0 ][2 ] != query ):
57
+ print "qs[0][2]:\n " , qs [0 ][2 ]
58
+ print "Expected:\n " , query
59
+ something_happened = True
60
+ if (not (re .match (expected , qs [0 ][3 ]))):
61
+ print "qs[0][3]:\n " , qs [0 ][3 ]
62
+ print "Expected:\n " , expected
63
+ something_happened = True
64
+ if (qs [0 ][4 ] != None ):
65
+ print "qs[0][4]: " , qs [0 ][4 ], "Expected: None"
66
+ something_happened = True
67
+ if (qs_len and len (qs ) > qs_len ):
68
+ for i in range (qs_len , len (qs )):
69
+ print "qs[" ,i ,"][0]: " , qs [i ][0 ]
70
+ print "qs[" ,i ,"][1]: " , qs [i ][1 ]
71
+ print "qs[" ,i ,"][2]: " , qs [i ][2 ]
72
+ print "qs[" ,i ,"][3]: " , qs [i ][3 ]
73
+ print "qs[" ,i ,"][4]: " , qs [i ][4 ]
74
+ something_happened = True
75
+ if (something_happened ):
76
+ print "If test have not crashed, then it's OK"
77
+
45
78
def notices_warning ():
46
79
if (len (notices ) > 0 ):
80
+ print ("" )
47
81
print ("WARNING:" )
48
82
print (notices )
49
83
@@ -135,7 +169,10 @@ def test_simple_query(config):
135
169
-> Seq Scan on bar \(Current loop: actual rows=\d+, loop number=1\)"""
136
170
137
171
qs = query_state (config , acon , query )
138
- assert len (qs ) == 1 and qs [0 ][0 ] == acon .get_backend_pid () and qs [0 ][1 ] == 0 \
172
+ debug_output (qs , 1 , acon .get_backend_pid (), query , expected )
173
+ notices_warning ()
174
+ #assert len(qs) == 1 #Skip this check while output of test can be different
175
+ assert qs [0 ][0 ] == acon .get_backend_pid () and qs [0 ][1 ] == 0 \
139
176
and qs [0 ][2 ] == query and re .match (expected , qs [0 ][3 ]) and qs [0 ][4 ] == None
140
177
141
178
n_close ((acon ,))
@@ -230,8 +267,11 @@ def test_insert_on_conflict(config):
230
267
util_conn .commit ()
231
268
232
269
qs = query_state (config , acon , query )
233
- assert len (qs ) == 1 \
234
- and qs [0 ][0 ] == acon .get_backend_pid () and qs [0 ][1 ] == 0 \
270
+
271
+ debug_output (qs , 1 , acon .get_backend_pid (), query , expected )
272
+ notices_warning ()
273
+ #assert len(qs) == 1 \
274
+ assert qs [0 ][0 ] == acon .get_backend_pid () and qs [0 ][1 ] == 0 \
235
275
and qs [0 ][2 ] == query and re .match (expected , qs [0 ][3 ]) \
236
276
and qs [0 ][4 ] == None
237
277
assert len (notices ) == 0
@@ -277,12 +317,16 @@ def test_trigger(config):
277
317
util_conn .commit ()
278
318
279
319
qs = query_state (config , acon , query , {'triggers' : True })
320
+ debug_output (qs , None , acon .get_backend_pid (), query , expected_upper )
321
+ notices_warning ()
280
322
assert qs [0 ][0 ] == acon .get_backend_pid () and qs [0 ][1 ] == 0 \
281
323
and qs [0 ][2 ] == query and re .match (expected_upper , qs [0 ][3 ]) \
282
324
and qs [0 ][4 ] == None
283
325
assert len (notices ) == 0
284
326
285
327
qs = query_state (config , acon , query , {'triggers' : False })
328
+ debug_output (qs , None , acon .get_backend_pid (), query , expected_upper )
329
+ notices_warning ()
286
330
assert qs [0 ][0 ] == acon .get_backend_pid () and qs [0 ][1 ] == 0 \
287
331
and qs [0 ][2 ] == query and re .match (expected_upper , qs [0 ][3 ]) \
288
332
and qs [0 ][4 ] == None
@@ -307,6 +351,8 @@ def test_costs(config):
307
351
-> Seq Scan on bar \(cost=0.00..\d+.\d+ rows=\d+ width=4\) \(Current loop: actual rows=\d+, loop number=1\)"""
308
352
309
353
qs = query_state (config , acon , query , {'costs' : True })
354
+ debug_output (qs , 1 , None , query , expected )
355
+ notices_warning ()
310
356
assert len (qs ) == 1 and re .match (expected , qs [0 ][3 ])
311
357
assert len (notices ) == 0
312
358
@@ -330,6 +376,8 @@ def test_buffers(config):
330
376
set_guc (acon , 'pg_query_state.enable_buffers' , 'on' )
331
377
332
378
qs = query_state (config , acon , query , {'buffers' : True })
379
+ debug_output (qs , 1 , None , query , expected )
380
+ notices_warning ()
333
381
assert len (qs ) == 1 and re .match (expected , qs [0 ][3 ])
334
382
assert len (notices ) == 0
335
383
@@ -351,6 +399,8 @@ def test_timing(config):
351
399
set_guc (acon , 'pg_query_state.enable_timing' , 'on' )
352
400
353
401
qs = query_state (config , acon , query , {'timing' : True })
402
+ debug_output (qs , 1 , None , query , expected )
403
+ notices_warning ()
354
404
assert len (qs ) == 1 and re .match (expected , qs [0 ][3 ])
355
405
assert len (notices ) == 0
356
406
@@ -390,6 +440,8 @@ def test_formats(config):
390
440
-> Seq Scan on bar \(Current loop: actual rows=\d+, loop number=1\)"""
391
441
392
442
qs = query_state (config , acon , query , {'format' : 'text' })
443
+ debug_output (qs , 1 , None , query , expected )
444
+ notices_warning ()
393
445
assert len (qs ) == 1 and re .match (expected , qs [0 ][3 ])
394
446
assert len (notices ) == 0
395
447
0 commit comments