1
+ import asyncio
1
2
import pytest
2
3
import telio
3
4
from contextlib import AsyncExitStack
4
5
from helpers import SetupParameters , setup_mesh_nodes
6
+ from telio import PathType , State
5
7
from telio_features import TelioFeatures , Direct
8
+ from utils import testing
6
9
from utils .connection_util import ConnectionTag
10
+ from utils .ping import Ping
7
11
8
12
9
13
# Marks in-tunnel stack only, exiting only through IPv4
10
14
@pytest .mark .asyncio
11
15
@pytest .mark .parametrize (
12
- "alpha_setup_params" ,
13
- [
14
- pytest .param (
15
- SetupParameters (
16
- connection_tag = ConnectionTag .DOCKER_CONE_CLIENT_1 ,
17
- adapter_type = telio .AdapterType .LinuxNativeWg ,
18
- features = TelioFeatures (direct = Direct (providers = None )),
19
- )
20
- ),
21
- ],
16
+ "direct" ,
17
+ [True , False ],
22
18
)
23
- @pytest .mark .parametrize (
24
- "beta_setup_params" ,
25
- [
26
- pytest .param (
27
- SetupParameters (
28
- connection_tag = ConnectionTag .DOCKER_CONE_CLIENT_2 ,
29
- adapter_type = telio .AdapterType .LinuxNativeWg ,
30
- features = TelioFeatures (direct = Direct (providers = None )),
31
- ),
32
- ),
33
- ],
34
- )
35
- async def test_mesh_off (
36
- alpha_setup_params : SetupParameters , beta_setup_params : SetupParameters
37
- ) -> None :
19
+ async def test_mesh_off (direct ) -> None :
38
20
async with AsyncExitStack () as exit_stack :
21
+ features = (
22
+ TelioFeatures (direct = Direct (providers = None ))
23
+ if direct
24
+ else TelioFeatures (direct = None )
25
+ )
39
26
env = await setup_mesh_nodes (
40
- exit_stack , [alpha_setup_params , beta_setup_params ]
27
+ exit_stack ,
28
+ [
29
+ SetupParameters (
30
+ connection_tag = ConnectionTag .DOCKER_CONE_CLIENT_1 ,
31
+ adapter_type = telio .AdapterType .LinuxNativeWg ,
32
+ features = features ,
33
+ ),
34
+ SetupParameters (
35
+ connection_tag = ConnectionTag .DOCKER_CONE_CLIENT_2 ,
36
+ adapter_type = telio .AdapterType .LinuxNativeWg ,
37
+ features = features ,
38
+ ),
39
+ ],
41
40
)
41
+ alpha , beta = env .nodes
42
42
43
- client_alpha , _ = env .clients
44
- connection_alpha , _ = [conn .connection for conn in env .connections ]
43
+ client_alpha , client_beta = env .clients
44
+ connection_alpha , connection_beta = [
45
+ conn .connection for conn in env .connections
46
+ ]
45
47
46
48
await client_alpha .set_mesh_off ()
47
49
@@ -58,3 +60,25 @@ async def test_mesh_off(
58
60
assert (
59
61
"peer:" not in wg_show_stdout .strip ().split ()
60
62
), f"There are leftover WireGuard peers after mesh is set to off: { wg_show_stdout } "
63
+
64
+ path_type = PathType .Direct if direct else PathType .Relay
65
+
66
+ await client_alpha .wait_for_state_peer (
67
+ beta .public_key , [State .Disconnected ], [path_type ]
68
+ )
69
+
70
+ await client_alpha .set_meshmap (env .api .get_meshmap (alpha .id ))
71
+
72
+ asyncio .gather (
73
+ client_alpha .wait_for_state_peer (
74
+ beta .public_key , [State .Connected ], [path_type ]
75
+ ),
76
+ client_beta .wait_for_state_peer (
77
+ alpha .public_key , [State .Connected ], [path_type ]
78
+ ),
79
+ )
80
+
81
+ async with Ping (connection_alpha , beta .ip_addresses [0 ]).run () as ping :
82
+ await testing .wait_lengthy (ping .wait_for_next_ping ())
83
+ async with Ping (connection_beta , alpha .ip_addresses [0 ]).run () as ping :
84
+ await testing .wait_long (ping .wait_for_next_ping ())
0 commit comments