|
16 | 16 | import pytest |
17 | 17 |
|
18 | 18 | from pyignite.exceptions import ReconnectError |
19 | | -from tests.util import start_ignite, kill_process_tree |
| 19 | +from tests.affinity.conftest import CLIENT_SOCKET_TIMEOUT |
| 20 | +from tests.util import start_ignite, kill_process_tree, get_client |
20 | 21 |
|
21 | 22 |
|
22 | | -def test_client_with_multiple_bad_servers(client_not_connected): |
| 23 | +@pytest.fixture(params=['with-partition-awareness', 'without-partition-awareness']) |
| 24 | +def with_partition_awareness(request): |
| 25 | + yield request.param == 'with-partition-awareness' |
| 26 | + |
| 27 | + |
| 28 | +def test_client_with_multiple_bad_servers(with_partition_awareness): |
23 | 29 | with pytest.raises(ReconnectError) as e_info: |
24 | | - client_not_connected.connect([("127.0.0.1", 10900), ("127.0.0.1", 10901)]) |
| 30 | + with get_client(partition_aware=with_partition_awareness) as client: |
| 31 | + client.connect([("127.0.0.1", 10900), ("127.0.0.1", 10901)]) |
25 | 32 | assert str(e_info.value) == "Can not connect." |
26 | 33 |
|
27 | 34 |
|
28 | | -def test_client_with_failed_server(request, client_not_connected): |
| 35 | +def test_client_with_failed_server(request, with_partition_awareness): |
29 | 36 | srv = start_ignite(idx=4) |
30 | 37 | try: |
31 | | - client_not_connected.connect([("127.0.0.1", 10804)]) |
32 | | - cache = client_not_connected.get_or_create_cache(request.node.name) |
33 | | - cache.put(1, 1) |
34 | | - kill_process_tree(srv.pid) |
35 | | - with pytest.raises(ConnectionResetError): |
36 | | - cache.get(1) |
| 38 | + with get_client(partition_aware=with_partition_awareness) as client: |
| 39 | + client.connect([("127.0.0.1", 10804)]) |
| 40 | + cache = client.get_or_create_cache(request.node.name) |
| 41 | + cache.put(1, 1) |
| 42 | + kill_process_tree(srv.pid) |
| 43 | + |
| 44 | + if with_partition_awareness: |
| 45 | + ex_class = (ReconnectError, ConnectionResetError) |
| 46 | + else: |
| 47 | + ex_class = ConnectionResetError |
| 48 | + |
| 49 | + with pytest.raises(ex_class): |
| 50 | + cache.get(1) |
37 | 51 | finally: |
38 | 52 | kill_process_tree(srv.pid) |
39 | 53 |
|
40 | 54 |
|
41 | | -def test_client_with_recovered_server(request, client_not_connected): |
| 55 | +def test_client_with_recovered_server(request, with_partition_awareness): |
42 | 56 | srv = start_ignite(idx=4) |
43 | 57 | try: |
44 | | - client_not_connected.connect([("127.0.0.1", 10804)]) |
45 | | - cache = client_not_connected.get_or_create_cache(request.node.name) |
46 | | - cache.put(1, 1) |
| 58 | + with get_client(partition_aware=with_partition_awareness, timeout=CLIENT_SOCKET_TIMEOUT) as client: |
| 59 | + client.connect([("127.0.0.1", 10804)]) |
| 60 | + cache = client.get_or_create_cache(request.node.name) |
| 61 | + cache.put(1, 1) |
47 | 62 |
|
48 | | - # Kill and restart server |
49 | | - kill_process_tree(srv.pid) |
50 | | - srv = start_ignite(idx=4) |
| 63 | + # Kill and restart server |
| 64 | + kill_process_tree(srv.pid) |
| 65 | + srv = start_ignite(idx=4) |
51 | 66 |
|
52 | | - # First request fails |
53 | | - with pytest.raises(Exception): |
54 | | - cache.put(1, 2) |
| 67 | + # First request may fail. |
| 68 | + try: |
| 69 | + cache.put(1, 2) |
| 70 | + except: |
| 71 | + pass |
55 | 72 |
|
56 | | - # Retry succeeds |
57 | | - cache.put(1, 2) |
58 | | - assert cache.get(1) == 2 |
| 73 | + # Retry succeeds |
| 74 | + cache.put(1, 2) |
| 75 | + assert cache.get(1) == 2 |
59 | 76 | finally: |
60 | 77 | kill_process_tree(srv.pid) |
0 commit comments