diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-03-17 15:22:48 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-03-17 15:22:48 -0700 |
commit | 4f0e8c3aed0ce2e4606c5c8facacfbd3c015d375 (patch) | |
tree | 94cdf2df79d6d8ddc428d659eb180555775b8768 /tests | |
parent | 46bf009284405d352e6c9682829b4e0895b7c17f (diff) | |
parent | 4cc63f3c60ea9cc2e366671cb40de2e929c83244 (diff) |
Merge pull request #2020 from fadams/improve-websocket-config-options
Provide compile time and run time options for WebSocket URL and subproto...
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_sockets.py | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/tests/test_sockets.py b/tests/test_sockets.py index 3a5555ed..f1bdc320 100644 --- a/tests/test_sockets.py +++ b/tests/test_sockets.py @@ -414,21 +414,54 @@ class sockets(BrowserCore): sockets_include = '-I'+path_from_root('tests', 'sockets') - # Websockify-proxied servers can't run dgram tests harnesses = [ - # Websockify doesn't seem to like ws.WebSocket clients TODO check if this is a ws issue or Websockify issue - #(WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 49160), 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=1'], 49162), 1) + (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'], 59162), 0), + (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. for harness, datagram in harnesses: 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, '-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('client.js', engine=NODE_JS, full_output=True) + self.assertContained('do_msg_read: read 14 bytes', out) + + # 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 + # This test also checks that the connect url contains the correct subprotocols. + print "\nTesting compile time WebSocket configuration.\n" + for harness in [ + WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 59166) + ]: + with harness: + 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('client.js', engine=NODE_JS, full_output=True) + self.assertContained('do_msg_read: read 14 bytes', out) + self.assertContained('connect: ws://127.0.0.1:59166, base64,binary', out) + + # 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 + # the connection would fail without us specifying a valid WebSocket URL in the configuration. + print "\nTesting runtime WebSocket configuration.\n" + for harness in [ + WebsockifyServerHarness(os.path.join('sockets', 'test_sockets_echo_server.c'), [sockets_include], 59168) + ]: + with harness: + open(os.path.join(self.get_dir(), 'websocket_pre.js'), 'w').write(''' + var Module = { + websocket: { + url: 'ws://localhost:59168/testA/testB', + subprotocol: 'text, base64, binary', + } + }; + ''') - self.assertContained('do_msg_read: read 14 bytes', run_js(path_from_root('tests', 'sockets', 'client.js'), engine=NODE_JS)) + 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() - # 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')) + out = run_js('client.js', engine=NODE_JS, full_output=True) + self.assertContained('do_msg_read: read 14 bytes', out) + self.assertContained('connect: ws://localhost:59168/testA/testB, text,base64,binary', out) |