Fixed test_sockets.py so that it uses temp directory correctly and cleans up automatically. Changed server port ranges to minimise chance of port collisions
This commit is contained in:
Родитель
3638861ee0
Коммит
4cc63f3c60
|
@ -414,63 +414,53 @@ class sockets(BrowserCore):
|
||||||
sockets_include = '-I'+path_from_root('tests', 'sockets')
|
sockets_include = '-I'+path_from_root('tests', 'sockets')
|
||||||
|
|
||||||
harnesses = [
|
harnesses = [
|
||||||
(WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 49160), 0),
|
(WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 59160), 0),
|
||||||
(CompiledServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include, '-DTEST_DGRAM=0'], 49161), 0),
|
(CompiledServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include, '-DTEST_DGRAM=0'], 59162), 0),
|
||||||
(CompiledServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include, '-DTEST_DGRAM=1'], 49162), 1)
|
(CompiledServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include, '-DTEST_DGRAM=1'], 59164), 1)
|
||||||
]
|
]
|
||||||
|
|
||||||
# Basic test of node client against both a Websockified and compiled echo server.
|
# Basic test of node client against both a Websockified and compiled echo server.
|
||||||
for harness, datagram in harnesses:
|
for harness, datagram in harnesses:
|
||||||
with harness:
|
with harness:
|
||||||
Popen([PYTHON, EMCC, path_from_root('tests', 'sockets', 'test_sockets_echo_client.c'), '-o', path_from_root('tests', 'sockets', 'client.js'), '-DSOCKK=%d' % harness.listen_port, '-DTEST_DGRAM=%d' % datagram, '-DREPORT_RESULT=int dummy'], stdout=PIPE, stderr=PIPE).communicate()
|
Popen([PYTHON, EMCC, path_from_root('tests', 'sockets', 'test_sockets_echo_client.c'), '-o', 'client.js', '-DSOCKK=%d' % harness.listen_port, '-DTEST_DGRAM=%d' % datagram, '-DREPORT_RESULT=int dummy'], stdout=PIPE, stderr=PIPE).communicate()
|
||||||
|
|
||||||
out = run_js(path_from_root('tests', 'sockets', 'client.js'), engine=NODE_JS, full_output=True)
|
out = run_js('client.js', engine=NODE_JS, full_output=True)
|
||||||
self.assertContained('do_msg_read: read 14 bytes', out)
|
self.assertContained('do_msg_read: read 14 bytes', out)
|
||||||
|
|
||||||
# Tidy up files that might have been created by this test.
|
|
||||||
try_delete(path_from_root('tests', 'sockets', 'client.js'))
|
|
||||||
try_delete(path_from_root('tests', 'sockets', 'client.js.map'))
|
|
||||||
|
|
||||||
# Test against a Websockified server with compile time configured WebSocket subprotocol. We use a Websockified
|
# 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
|
# server because as long as the subprotocol list contains binary it will configure itself to accept binary
|
||||||
# This test also checks that the connect url contains the correct subprotocols.
|
# This test also checks that the connect url contains the correct subprotocols.
|
||||||
|
print "\nTesting compile time WebSocket configuration.\n"
|
||||||
for harness in [
|
for harness in [
|
||||||
WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 49160)
|
WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 59166)
|
||||||
]:
|
]:
|
||||||
with harness:
|
with harness:
|
||||||
Popen([PYTHON, EMCC, path_from_root('tests', 'sockets', 'test_sockets_echo_client.c'), '-o', path_from_root('tests', 'sockets', 'client.js'), '-s', 'SOCKET_DEBUG=1', '-s', 'WEBSOCKET_SUBPROTOCOL="base64, binary"', '-DSOCKK=49160', '-DREPORT_RESULT=int dummy'], stdout=PIPE, stderr=PIPE).communicate()
|
Popen([PYTHON, EMCC, path_from_root('tests', 'sockets', 'test_sockets_echo_client.c'), '-o', 'client.js', '-s', 'SOCKET_DEBUG=1', '-s', 'WEBSOCKET_SUBPROTOCOL="base64, binary"', '-DSOCKK=59166', '-DREPORT_RESULT=int dummy'], stdout=PIPE, stderr=PIPE).communicate()
|
||||||
|
|
||||||
out = run_js(path_from_root('tests', 'sockets', 'client.js'), engine=NODE_JS, full_output=True)
|
out = run_js('client.js', engine=NODE_JS, full_output=True)
|
||||||
self.assertContained('do_msg_read: read 14 bytes', out)
|
self.assertContained('do_msg_read: read 14 bytes', out)
|
||||||
self.assertContained('connect: ws://127.0.0.1:49160, base64,binary', out)
|
self.assertContained('connect: ws://127.0.0.1:59166, base64,binary', out)
|
||||||
|
|
||||||
# Tidy up files that might have been created by this test.
|
|
||||||
try_delete(path_from_root('tests', 'sockets', 'client.js'))
|
|
||||||
try_delete(path_from_root('tests', 'sockets', 'client.js.map'))
|
|
||||||
|
|
||||||
# Test against a Websockified server with runtime WebSocket configuration. We specify both url and subprotocol.
|
# 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
|
# In this test we have *deliberately* used the wrong port '-DSOCKK=12345' to configure the echo_client.c, so
|
||||||
# the connection would fail without us specifying a valid WebSocket URL in the configuration.
|
# the connection would fail without us specifying a valid WebSocket URL in the configuration.
|
||||||
|
print "\nTesting runtime WebSocket configuration.\n"
|
||||||
for harness in [
|
for harness in [
|
||||||
WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 49163)
|
WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 59168)
|
||||||
]:
|
]:
|
||||||
with harness:
|
with harness:
|
||||||
open(os.path.join(self.get_dir(), 'websocket_pre.js'), 'w').write('''
|
open(os.path.join(self.get_dir(), 'websocket_pre.js'), 'w').write('''
|
||||||
var Module = {
|
var Module = {
|
||||||
websocket: {
|
websocket: {
|
||||||
url: 'ws://localhost:49163/testA/testB',
|
url: 'ws://localhost:59168/testA/testB',
|
||||||
subprotocol: 'text, base64, binary',
|
subprotocol: 'text, base64, binary',
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
''')
|
''')
|
||||||
|
|
||||||
Popen([PYTHON, EMCC, path_from_root('tests', 'sockets', 'test_sockets_echo_client.c'), '-o', path_from_root('tests', 'sockets', 'client.js'), '--pre-js', 'websocket_pre.js', '-s', 'SOCKET_DEBUG=1', '-DSOCKK=12345', '-DREPORT_RESULT=int dummy'], stdout=PIPE, stderr=PIPE).communicate()
|
Popen([PYTHON, EMCC, path_from_root('tests', 'sockets', 'test_sockets_echo_client.c'), '-o', 'client.js', '--pre-js', 'websocket_pre.js', '-s', 'SOCKET_DEBUG=1', '-DSOCKK=12345', '-DREPORT_RESULT=int dummy'], stdout=PIPE, stderr=PIPE).communicate()
|
||||||
|
|
||||||
out = run_js(path_from_root('tests', 'sockets', 'client.js'), engine=NODE_JS, full_output=True)
|
out = run_js('client.js', engine=NODE_JS, full_output=True)
|
||||||
self.assertContained('do_msg_read: read 14 bytes', out)
|
self.assertContained('do_msg_read: read 14 bytes', out)
|
||||||
self.assertContained('connect: ws://localhost:49163/testA/testB, text,base64,binary', out)
|
self.assertContained('connect: ws://localhost:59168/testA/testB, text,base64,binary', out)
|
||||||
|
|
||||||
# Tidy up files that might have been created by this test.
|
|
||||||
try_delete(path_from_root('tests', 'sockets', 'client.js'))
|
|
||||||
try_delete(path_from_root('tests', 'sockets', 'client.js.map'))
|
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче