Skip to content

Commit 9d6739f

Browse files
committed
test_p2p: Add native/WebRTC interop test with TURN
1 parent 42cc1fc commit 9d6739f

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

tests/test_p2p.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,10 @@ def ClientServerExpectedFailureTest( server_extra_args=[], client_extra_args=[],
720720

721721
def ClientServerTest( server_extra_args=[], client_extra_args=[], expected_route=None, ice_impl=1, expected_counters=None, expected_candidates=None, timeout_sec=None, stun=_DEFAULT_STUN, turn=_DEFAULT_TURN, server_ice_impl=None, client_ice_impl=None ):
722722
global g_failed
723-
srv_impl_args = [ '--ice-implementation', str(server_ice_impl if server_ice_impl is not None else ice_impl) ]
724-
cli_impl_args = [ '--ice-implementation', str(client_ice_impl if client_ice_impl is not None else ice_impl) ]
723+
_srv_impl = server_ice_impl if server_ice_impl is not None else ice_impl
724+
_cli_impl = client_ice_impl if client_ice_impl is not None else ice_impl
725+
srv_impl_args = [ '--ice-implementation', str(_srv_impl) ]
726+
cli_impl_args = [ '--ice-implementation', str(_cli_impl) ]
725727
server = StartClientInThread( "server", "peer_server", "peer_client", server_extra_args + srv_impl_args, stun=stun, turn=turn )
726728
client = StartClientInThread( "client", "peer_client", "peer_server", client_extra_args + cli_impl_args, stun=stun, turn=turn )
727729

@@ -740,9 +742,12 @@ def ClientServerTest( server_extra_args=[], client_extra_args=[], expected_route
740742
print( "ERROR: %s route type '%s', expected '%s'" % ( peer, thread.route_type, expected_route ) )
741743
g_failed = True
742744

743-
# Verify packet counters if constraints were provided
745+
# Verify packet counters if constraints were provided.
746+
# Skip for WebRTC (impl=0) peers -- the WebRTC ICE stack doesn't emit TEST_ICE_ctr_* lines.
744747
if expected_counters is not None:
745-
for peer, thread in [ ( 'server', server ), ( 'client', client ) ]:
748+
for peer, thread, impl in [ ( 'server', server, _srv_impl ), ( 'client', client, _cli_impl ) ]:
749+
if impl == 0:
750+
continue
746751
for name, (lo, hi) in expected_counters.items():
747752
val = thread.counters.get( name, 0 )
748753
if lo is not None and val < lo:
@@ -899,7 +904,32 @@ def _check_subset( received, gathered, receiver, gatherer ):
899904
print( "Test: no-mock interop, %s" % desc )
900905
print( "=================================================================" )
901906
ClientServerTest( [], [], expected_route='local', stun=None, turn=None,
902-
server_ice_impl=srv_impl, client_ice_impl=cli_impl )
907+
server_ice_impl=srv_impl, client_ice_impl=cli_impl,
908+
expected_counters={ 'allocate_send': (0, 0) } )
909+
910+
# Real-network, relay-only via a TURN server bound to the real LAN IP.
911+
# The TURN server is on a private address, which is unusual but should be handled
912+
# identically to any other TURN server from the ICE client's perspective.
913+
if not g_failed and turn_lan is not None:
914+
print( "=================================================================" )
915+
print( "Test: no-mock, relay via LAN TURN (%s:%d)" % (g_turn_lan_ip, _TURN_LAN_PORT) )
916+
print( "=================================================================" )
917+
turn_lan_addr = '%s:%d' % (g_turn_lan_ip, _TURN_LAN_PORT)
918+
relay_args = [ '--ice-enable', str(_ICE_ENABLE_RELAY),
919+
'--turn-username', _TURN_USERNAME, '--turn-password', _TURN_PASSWORD ]
920+
ClientServerTest( relay_args, relay_args,
921+
expected_route='relay', ice_impl=1,
922+
stun=None, turn=turn_lan_addr,
923+
expected_counters={
924+
# Each interface does 2 allocate sends (unauthenticated 401 + authenticated
925+
# success). We don't cap the max because the number of real adapters varies
926+
# by machine.
927+
'allocate_send': (2, None),
928+
'allocate_retx': (0, 0), # server responds promptly; no retransmits
929+
'srflx_send': (0, 0), # relay-only mode suppresses STUN discovery
930+
'send_ind_send': (1, None), # data sent out through the relay
931+
'data_ind_recv': (1, None), # data received through the relay
932+
} )
903933

904934
# Run the expected-failure tests
905935
if not g_failed:

0 commit comments

Comments
 (0)