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