|
19 | 19 | ExecUtilException, \
|
20 | 20 | BackupException, \
|
21 | 21 | QueryException, \
|
22 |
| - CatchUpException |
| 22 | + CatchUpException, \ |
| 23 | + TimeoutException |
23 | 24 |
|
24 | 25 | from testgres import get_new_node, get_pg_config, configure_testgres
|
25 | 26 | from testgres import bound_ports
|
@@ -60,22 +61,58 @@ def test_restart(self):
|
60 | 61 | res = node.execute('postgres', 'select 2')
|
61 | 62 | self.assertEqual(res, [(2, )])
|
62 | 63 |
|
| 64 | + def test_psql(self): |
| 65 | + with get_new_node('test') as node: |
| 66 | + node.init().start() |
| 67 | + |
| 68 | + # check default params |
| 69 | + got_exception = False |
| 70 | + try: |
| 71 | + node.psql('postgres') |
| 72 | + except QueryException as e: |
| 73 | + got_exception = True |
| 74 | + self.assertTrue(got_exception) |
| 75 | + |
| 76 | + # check returned values |
| 77 | + res = node.psql('postgres', 'select 1') |
| 78 | + self.assertEqual(res[0], 0) |
| 79 | + self.assertEqual(res[1], b'1\n') |
| 80 | + self.assertEqual(res[2], b'') |
| 81 | + |
| 82 | + # check returned values |
| 83 | + res = node.safe_psql('postgres', 'select 1') |
| 84 | + self.assertEqual(res, b'1\n') |
| 85 | + |
| 86 | + node.stop() |
| 87 | + |
| 88 | + # check psql on stopped node |
| 89 | + got_exception = False |
| 90 | + try: |
| 91 | + node.safe_psql('postgres', 'select 1') |
| 92 | + except QueryException as e: |
| 93 | + got_exception = True |
| 94 | + self.assertTrue(got_exception) |
| 95 | + |
63 | 96 | def test_status(self):
|
| 97 | + # check NodeStatus cast to bool |
64 | 98 | condition_triggered = False
|
65 | 99 | if NodeStatus.Running:
|
66 | 100 | condition_triggered = True
|
67 | 101 | self.assertTrue(condition_triggered)
|
68 | 102 |
|
| 103 | + # check NodeStatus cast to bool |
69 | 104 | condition_triggered = False
|
70 | 105 | if NodeStatus.Stopped:
|
71 | 106 | condition_triggered = True
|
72 | 107 | self.assertFalse(condition_triggered)
|
73 | 108 |
|
| 109 | + # check NodeStatus cast to bool |
74 | 110 | condition_triggered = False
|
75 | 111 | if NodeStatus.Uninitialized:
|
76 | 112 | condition_triggered = True
|
77 | 113 | self.assertFalse(condition_triggered)
|
78 | 114 |
|
| 115 | + # check statuses after each operation |
79 | 116 | with get_new_node('test') as node:
|
80 | 117 | self.assertEqual(node.get_pid(), 0)
|
81 | 118 | self.assertEqual(node.status(), NodeStatus.Uninitialized)
|
@@ -336,6 +373,17 @@ def test_poll_query_until(self):
|
336 | 373 | got_exception = True
|
337 | 374 | self.assertTrue(got_exception)
|
338 | 375 |
|
| 376 | + # check timeout |
| 377 | + got_exception = False |
| 378 | + try: |
| 379 | + node.poll_query_until(dbname='postgres', |
| 380 | + query='select 1 > 2', |
| 381 | + max_attempts=5, |
| 382 | + sleep_time=0.2) |
| 383 | + except TimeoutException as e: |
| 384 | + got_exception = True |
| 385 | + self.assertTrue(got_exception) |
| 386 | + |
339 | 387 | def test_logging(self):
|
340 | 388 | logfile = tempfile.NamedTemporaryFile('w', delete=True)
|
341 | 389 |
|
|
0 commit comments