summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2021-03-24 11:43:41 +0300
committerMax Romanov <max.romanov@nginx.com>2021-03-24 11:43:41 +0300
commit178f232b3ad36a763b3b5c2e0ef6f26cc1885229 (patch)
tree6b5b968c84ee8779c47d3649d04eb74978ef6108 /test
parentf267dd0a8da280d2a803b61c9a309fe51d60d95a (diff)
downloadunit-178f232b3ad36a763b3b5c2e0ef6f26cc1885229.tar.gz
unit-178f232b3ad36a763b3b5c2e0ef6f26cc1885229.tar.bz2
Tests: fixed racing condition in websocket test 5_15.
Test case: "send a text message split into two fragments, then a continuation frame with FIN = false where there is nothing to continue, then an unfragmented text message, all sent in one chop". The test case investigates immediate connection closing since there is no message to continue. The mirror server may send a response for the first frame before the test сontinuation frame is received by the router. In this case, the test will receive a text frame before the close frame.
Diffstat (limited to 'test')
-rw-r--r--test/test_asgi_websockets.py14
-rw-r--r--test/test_java_websockets.py14
-rw-r--r--test/test_node_websockets.py14
3 files changed, 33 insertions, 9 deletions
diff --git a/test/test_asgi_websockets.py b/test/test_asgi_websockets.py
index 6121fcc5..7218d526 100644
--- a/test/test_asgi_websockets.py
+++ b/test/test_asgi_websockets.py
@@ -30,8 +30,9 @@ class TestASGIWebsockets(TestApplicationPython):
self.check_close(sock)
- def check_close(self, sock, code=1000, no_close=False):
- frame = self.ws.frame_read(sock)
+ def check_close(self, sock, code=1000, no_close=False, frame=None):
+ if frame == None:
+ frame = self.ws.frame_read(sock)
assert frame['fin'] == True, 'close fin'
assert frame['opcode'] == self.ws.OP_CLOSE, 'close opcode'
@@ -930,7 +931,14 @@ class TestASGIWebsockets(TestApplicationPython):
self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2', fin=True)
self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment3', fin=False)
self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment4', fin=True)
- self.check_close(sock, 1002)
+
+ frame = self.ws.frame_read(sock)
+
+ if frame['opcode'] == self.ws.OP_TEXT:
+ self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
+ frame = None
+
+ self.check_close(sock, 1002, frame=frame)
# 5_16
diff --git a/test/test_java_websockets.py b/test/test_java_websockets.py
index 315c496d..df9e0885 100644
--- a/test/test_java_websockets.py
+++ b/test/test_java_websockets.py
@@ -27,8 +27,9 @@ class TestJavaWebsockets(TestApplicationJava):
self.check_close(sock)
- def check_close(self, sock, code=1000, no_close=False):
- frame = self.ws.frame_read(sock)
+ def check_close(self, sock, code=1000, no_close=False, frame=None):
+ if frame == None:
+ frame = self.ws.frame_read(sock)
assert frame['fin'] == True, 'close fin'
assert frame['opcode'] == self.ws.OP_CLOSE, 'close opcode'
@@ -862,7 +863,14 @@ class TestJavaWebsockets(TestApplicationJava):
self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2', fin=True)
self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment3', fin=False)
self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment4', fin=True)
- self.check_close(sock, 1002)
+
+ frame = self.ws.frame_read(sock)
+
+ if frame['opcode'] == self.ws.OP_TEXT:
+ self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
+ frame = None
+
+ self.check_close(sock, 1002, frame=frame)
# 5_16
diff --git a/test/test_node_websockets.py b/test/test_node_websockets.py
index 4f1e5906..d5f79811 100644
--- a/test/test_node_websockets.py
+++ b/test/test_node_websockets.py
@@ -27,8 +27,9 @@ class TestNodeWebsockets(TestApplicationNode):
self.check_close(sock)
- def check_close(self, sock, code=1000, no_close=False):
- frame = self.ws.frame_read(sock)
+ def check_close(self, sock, code=1000, no_close=False, frame=None):
+ if frame == None:
+ frame = self.ws.frame_read(sock)
assert frame['fin'] == True, 'close fin'
assert frame['opcode'] == self.ws.OP_CLOSE, 'close opcode'
@@ -881,7 +882,14 @@ class TestNodeWebsockets(TestApplicationNode):
self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2', fin=True)
self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment3', fin=False)
self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment4', fin=True)
- self.check_close(sock, 1002)
+
+ frame = self.ws.frame_read(sock)
+
+ if frame['opcode'] == self.ws.OP_TEXT:
+ self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
+ frame = None
+
+ self.check_close(sock, 1002, frame=frame)
# 5_16