25
25
26
26
def clean_processes (processes ):
27
27
for p in processes :
28
- if ( not hasattr ( p , 'exitcode' ) or p . exitcode is None ) and ( not hasattr ( p , 'returncode' ) or p . returncode is None ) :
28
+ if getattr ( p , 'exitcode' , None ) is None and getattr ( p , 'returncode' , None ) is None :
29
29
# ask nicely (to try and catch the children)
30
30
try :
31
31
p .terminate () # SIGTERM
@@ -53,7 +53,9 @@ def __enter__(self):
53
53
# NOTE empty filename support is a hack to support
54
54
# the current test_enet
55
55
if self .filename :
56
- run_process ([CLANG_CC , test_file (self .filename ), '-o' , 'server' , '-DSOCKK=%d' % self .target_port ] + clang_native .get_clang_native_args () + self .args , env = clang_native .get_clang_native_env ())
56
+ cmd = [CLANG_CC , test_file (self .filename ), '-o' , 'server' , '-DSOCKK=%d' % self .target_port ] + clang_native .get_clang_native_args () + self .args
57
+ print (cmd )
58
+ run_process (cmd , env = clang_native .get_clang_native_env ())
57
59
process = Popen ([os .path .abspath ('server' )])
58
60
self .processes .append (process )
59
61
@@ -81,6 +83,7 @@ def __enter__(self):
81
83
raise Exception ('[Websockify failed to start up in a timely manner]' )
82
84
83
85
print ('[Websockify on process %s]' % str (self .processes [- 2 :]))
86
+ return self
84
87
85
88
def __exit__ (self , * args , ** kwargs ):
86
89
# try to kill the websockify proxy gracefully
@@ -114,6 +117,7 @@ def __enter__(self):
114
117
115
118
process = Popen (config .NODE_JS + ['server.js' ])
116
119
self .processes .append (process )
120
+ return self
117
121
118
122
def __exit__ (self , * args , ** kwargs ):
119
123
# clean up any processes we started
@@ -133,6 +137,7 @@ def __enter__(self):
133
137
print ('Running background server: ' + str (self .args ))
134
138
process = Popen (self .args )
135
139
self .processes .append (process )
140
+ return self
136
141
137
142
def __exit__ (self , * args , ** kwargs ):
138
143
clean_processes (self .processes )
@@ -187,8 +192,7 @@ def test_sockets_echo_pthreads(self):
187
192
self .test_sockets_echo (['-sUSE_PTHREADS' , '-sPROXY_TO_PTHREAD' ])
188
193
189
194
def test_sdl2_sockets_echo (self ):
190
- harness = CompiledServerHarness ('sdl2_net_server.c' , ['-sUSE_SDL=2' , '-sUSE_SDL_NET=2' ], 49164 )
191
- with harness :
195
+ with CompiledServerHarness ('sdl2_net_server.c' , ['-sUSE_SDL=2' , '-sUSE_SDL_NET=2' ], 49164 ) as harness :
192
196
self .btest_exit ('sdl2_net_client.c' , args = ['-sUSE_SDL=2' , '-sUSE_SDL_NET=2' , '-DSOCKK=%d' % harness .listen_port ])
193
197
194
198
def test_sockets_async_echo (self ):
@@ -274,11 +278,8 @@ def test_enet(self):
274
278
self .run_process ([path_from_root ('emmake' ), 'make' ])
275
279
enet = [self .in_dir ('enet' , '.libs' , 'libenet.a' ), '-I' + self .in_dir ('enet' , 'include' )]
276
280
277
- for harness in [
278
- CompiledServerHarness (test_file ('sockets/test_enet_server.c' ), enet , 49210 )
279
- ]:
280
- with harness :
281
- self .btest_exit (test_file ('sockets/test_enet_client.c' ), args = enet + ['-DSOCKK=%d' % harness .listen_port ])
281
+ with CompiledServerHarness (test_file ('sockets/test_enet_server.c' ), enet , 49210 ) as harness :
282
+ self .btest_exit (test_file ('sockets/test_enet_client.c' ), args = enet + ['-DSOCKK=%d' % harness .listen_port ])
282
283
283
284
def test_nodejs_sockets_echo (self ):
284
285
# This test checks that sockets work when the client code is run in Node.js
@@ -304,15 +305,12 @@ def test_nodejs_sockets_echo(self):
304
305
# server because as long as the subprotocol list contains binary it will configure itself to accept binary
305
306
# This test also checks that the connect url contains the correct subprotocols.
306
307
print ("\n Testing compile time WebSocket configuration.\n " )
307
- for harness in [
308
- WebsockifyServerHarness (test_file ('sockets/test_sockets_echo_server.c' ), [], 59166 )
309
- ]:
310
- with harness :
311
- self .run_process ([EMCC , '-Werror' , test_file ('sockets/test_sockets_echo_client.c' ), '-o' , 'client.js' , '-sSOCKET_DEBUG' , '-sWEBSOCKET_SUBPROTOCOL="base64, binary"' , '-DSOCKK=59166' ])
308
+ with WebsockifyServerHarness (test_file ('sockets/test_sockets_echo_server.c' ), [], 59166 ):
309
+ self .run_process ([EMCC , '-Werror' , test_file ('sockets/test_sockets_echo_client.c' ), '-o' , 'client.js' , '-sSOCKET_DEBUG' , '-sWEBSOCKET_SUBPROTOCOL="base64, binary"' , '-DSOCKK=59166' ])
312
310
313
- out = self .run_js ('client.js' )
314
- self .assertContained ('do_msg_read: read 14 bytes' , out )
315
- self .assertContained (['connect: ws://127.0.0.1:59166, base64,binary' , 'connect: ws://127.0.0.1:59166/, base64,binary' ], out )
311
+ out = self .run_js ('client.js' )
312
+ self .assertContained ('do_msg_read: read 14 bytes' , out )
313
+ self .assertContained (['connect: ws://127.0.0.1:59166, base64,binary' , 'connect: ws://127.0.0.1:59166/, base64,binary' ], out )
316
314
317
315
# Test against a Websockified server with runtime WebSocket configuration. We specify both url and subprotocol.
318
316
# In this test we have *deliberately* used the wrong port '-DSOCKK=12345' to configure the echo_client.c, so
@@ -326,15 +324,12 @@ def test_nodejs_sockets_echo(self):
326
324
}
327
325
};
328
326
''' )
329
- for harness in [
330
- WebsockifyServerHarness (test_file ('sockets/test_sockets_echo_server.c' ), [], 59168 )
331
- ]:
332
- with harness :
333
- self .run_process ([EMCC , '-Werror' , test_file ('sockets/test_sockets_echo_client.c' ), '-o' , 'client.js' , '--pre-js=websocket_pre.js' , '-sSOCKET_DEBUG' , '-DSOCKK=12345' ])
334
-
335
- out = self .run_js ('client.js' )
336
- self .assertContained ('do_msg_read: read 14 bytes' , out )
337
- self .assertContained ('connect: ws://localhost:59168/testA/testB, text,base64,binary' , out )
327
+ with WebsockifyServerHarness (test_file ('sockets/test_sockets_echo_server.c' ), [], 59168 ) as harness :
328
+ self .run_process ([EMCC , '-Werror' , test_file ('sockets/test_sockets_echo_client.c' ), '-o' , 'client.js' , '--pre-js=websocket_pre.js' , '-sSOCKET_DEBUG' , '-DSOCKK=12345' ])
329
+
330
+ out = self .run_js ('client.js' )
331
+ self .assertContained ('do_msg_read: read 14 bytes' , out )
332
+ self .assertContained ('connect: ws://localhost:59168/testA/testB, text,base64,binary' , out )
338
333
339
334
# Test Emscripten WebSockets API to send and receive text and binary messages against an echo server.
340
335
# N.B. running this test requires 'npm install ws' in Emscripten root directory
0 commit comments