Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion test/test_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@

npm_checked = False

EMTEST_SKIP_PYTHON_DEV_PACKAGES = int(os.getenv('EMTEST_SKIP_PYTHON_DEV_PACKAGES', '0'))


def requires_python_dev_packages(func):
assert callable(func)

@common.wraps(func)
def decorated(self, *args, **kwargs):
if EMTEST_SKIP_PYTHON_DEV_PACKAGES:
return self.skipTest('python websockify based tests are disabled by EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')
return func(self, *args, **kwargs)

return decorated


def clean_processes(processes):
for p in processes:
Expand Down Expand Up @@ -61,7 +75,10 @@ def __enter__(self):
process = Popen([os.path.abspath('server')])
self.processes.append(process)

import websockify # type: ignore
try:
import websockify # type: ignore
except ModuleNotFoundError:
raise Exception('Unable to import module websockify. Run "python3 -m pip install websockify" or set environment variable EMTEST_SKIP_PYTHON_DEV_PACKAGES=1 to skip this test.') from None

# start the websocket proxy
print('running websockify on %d, forward to tcp %d' % (self.listen_port, self.target_port), file=sys.stderr)
Expand Down Expand Up @@ -184,6 +201,9 @@ def test_sockets_echo(self, harness_class, port, args):
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:
self.skipTest('requires native clang')

if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES:
self.skipTest('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')

with harness_class(test_file('sockets/test_sockets_echo_server.c'), args, port) as harness:
self.btest_exit('sockets/test_sockets_echo_client.c', cflags=['-DSOCKK=%d' % harness.listen_port] + args)

Expand All @@ -205,6 +225,8 @@ def test_sdl2_sockets_echo(self):
def test_sockets_async_echo(self, harness_class, port, args):
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:
self.skipTest('requires native clang')
if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES:
self.skipTest('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')

args.append('-DTEST_ASYNC=1')
with harness_class(test_file('sockets/test_sockets_echo_server.c'), args, port) as harness:
Expand All @@ -223,6 +245,8 @@ def test_sockets_async_bad_port(self):
def test_sockets_echo_bigdata(self, harness_class, port, args):
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:
self.skipTest('requires native clang')
if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES:
self.skipTest('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')
sockets_include = '-I' + test_file('sockets')

# generate a large string literal to use as our message
Expand All @@ -238,6 +262,7 @@ def test_sockets_echo_bigdata(self, harness_class, port, args):
self.btest_exit('test_sockets_echo_bigdata.c', cflags=[sockets_include, '-DSOCKK=%d' % harness.listen_port] + args)

@no_windows('This test is Unix-specific.')
@requires_python_dev_packages
def test_sockets_partial(self):
for harness in [
WebsockifyServerHarness(test_file('sockets/test_sockets_partial_server.c'), [], 49180),
Expand All @@ -247,6 +272,7 @@ def test_sockets_partial(self):
self.btest_exit('sockets/test_sockets_partial_client.c', assert_returncode=165, cflags=['-DSOCKK=%d' % harness.listen_port])

@no_windows('This test is Unix-specific.')
@requires_python_dev_packages
def test_sockets_select_server_down(self):
for harness in [
WebsockifyServerHarness(test_file('sockets/test_sockets_select_server_down_server.c'), [], 49190, do_server_check=False),
Expand All @@ -256,6 +282,7 @@ def test_sockets_select_server_down(self):
self.btest_exit('sockets/test_sockets_select_server_down_client.c', cflags=['-DSOCKK=%d' % harness.listen_port])

@no_windows('This test is Unix-specific.')
@requires_python_dev_packages
def test_sockets_select_server_closes_connection_rw(self):
for harness in [
WebsockifyServerHarness(test_file('sockets/test_sockets_echo_server.c'), ['-DCLOSE_CLIENT_AFTER_ECHO'], 49200),
Expand Down Expand Up @@ -286,6 +313,8 @@ def test_enet(self):
def test_nodejs_sockets_echo(self, harness_class, port, args):
if harness_class == WebsockifyServerHarness and common.EMTEST_LACKS_NATIVE_CLANG:
self.skipTest('requires native clang')
if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES:
self.skipTest('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1')

# Basic test of node client against both a Websockified and compiled echo server.
with harness_class(test_file('sockets/test_sockets_echo_server.c'), args, port) as harness:
Expand All @@ -296,6 +325,7 @@ def test_nodejs_sockets_connect_failure(self):
self.do_runf('sockets/test_sockets_echo_client.c', 'connect failed: Connection refused', cflags=['-DSOCKK=666'], assert_returncode=NON_ZERO)

@requires_native_clang
@requires_python_dev_packages
def test_nodejs_sockets_echo_subprotocol(self):
# Test against a Websockified server with compile time configured WebSocket subprotocol. We use a Websockified
# server because as long as the subprotocol list contains binary it will configure itself to accept binary
Expand All @@ -308,6 +338,7 @@ def test_nodejs_sockets_echo_subprotocol(self):
self.assertContained(['connect: ws://127.0.0.1:59168, base64,binary', 'connect: ws://127.0.0.1:59168/, base64,binary'], out)

@requires_native_clang
@requires_python_dev_packages
def test_nodejs_sockets_echo_subprotocol_runtime(self):
# Test against a Websockified server with runtime WebSocket configuration. We specify both url and subprotocol.
# In this test we have *deliberately* used the wrong port '-DSOCKK=12345' to configure the echo_client.c, so
Expand Down