|
2 | 2 | import json |
3 | 3 | import logging |
4 | 4 | import math |
| 5 | +import nats |
5 | 6 | import os.path as p |
6 | 7 | import random |
7 | 8 | import subprocess |
@@ -46,6 +47,24 @@ def wait_nats_to_start(nats_port, ssl_ctx=None, timeout=180): |
46 | 47 | except Exception as ex: |
47 | 48 | logging.debug("Can't connect to NATS " + str(ex)) |
48 | 49 | time.sleep(0.5) |
| 50 | + |
| 51 | + assert False, "NATS is unavailable" |
| 52 | + |
| 53 | +# function to check if nats is paused, because in some cases we successfully connected to it after calling pause_container |
| 54 | +def wait_nats_paused(nats_port, ssl_ctx=None, timeout=180): |
| 55 | + start = time.time() |
| 56 | + while time.time() - start < timeout: |
| 57 | + try: |
| 58 | + asyncio.run(check_nats_is_available(nats_port, ssl_ctx=ssl_ctx)) |
| 59 | + time.sleep(0.5) |
| 60 | + except nats.errors.NoServersError: |
| 61 | + logging.debug("NATS is paused") |
| 62 | + return |
| 63 | + except Exception as ex: |
| 64 | + logging.warning("Detect NATS status failed with error \"" + str(ex) + "\" - continue waiting for proper status...") |
| 65 | + time.sleep(0.5) |
| 66 | + |
| 67 | + assert False, "NATS is not paused" |
49 | 68 |
|
50 | 69 | def nats_check_query_result(query, time_limit_sec = 60): |
51 | 70 | query_result = "" |
@@ -1326,6 +1345,7 @@ def test_nats_restore_failed_connection_without_losses_on_write(nats_cluster): |
1326 | 1345 |
|
1327 | 1346 | def test_nats_no_connection_at_startup_1(nats_cluster): |
1328 | 1347 | with nats_cluster.pause_container("nats1"): |
| 1348 | + wait_nats_paused(nats_cluster.nats_port, nats_cluster.nats_ssl_context) |
1329 | 1349 | instance.query_and_get_error( |
1330 | 1350 | """ |
1331 | 1351 | CREATE TABLE test.cs (key UInt64, value UInt64) |
@@ -1369,6 +1389,7 @@ def test_nats_no_connection_at_startup_2(nats_cluster): |
1369 | 1389 | """ |
1370 | 1390 | ) |
1371 | 1391 | with nats_cluster.pause_container("nats1"): |
| 1392 | + wait_nats_paused(nats_cluster.nats_port, nats_cluster.nats_ssl_context) |
1372 | 1393 | instance.query("ATTACH TABLE test.cs") |
1373 | 1394 |
|
1374 | 1395 | wait_for_table_is_ready(instance, "test.cs") |
|
0 commit comments