diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2019-10-23 16:26:06 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2019-10-23 16:26:06 +0300 |
commit | 47436e9be5f41898ba873064fb358d0fe2decd06 (patch) | |
tree | f87bf04ed4ce5bc455b5d86d248d819e46047922 /test/unit | |
parent | f878b6eea51c7885ba10ad72f7f0d9edc83c04c6 (diff) | |
download | unit-47436e9be5f41898ba873064fb358d0fe2decd06.tar.gz unit-47436e9be5f41898ba873064fb358d0fe2decd06.tar.bz2 |
Tests: improved handshake for websocket tests.
Diffstat (limited to '')
-rw-r--r-- | test/unit/applications/websockets.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py index 50ff2797..5f78498c 100644 --- a/test/unit/applications/websockets.py +++ b/test/unit/applications/websockets.py @@ -1,3 +1,4 @@ +import re import random import base64 import struct @@ -32,11 +33,7 @@ class TestApplicationWebsocket(TestApplicationProto): def upgrade(self): key = self.key() - - if self.preinit: - self.get() - - resp, sock = self.get( + _, sock = self.get( headers={ 'Host': 'localhost', 'Upgrade': 'websocket', @@ -45,10 +42,21 @@ class TestApplicationWebsocket(TestApplicationProto): 'Sec-WebSocket-Protocol': 'chat', 'Sec-WebSocket-Version': 13, }, - read_timeout=1, + no_recv=True, start=True, ) + resp = '' + while select.select([sock], [], [], 30)[0]: + resp += sock.recv(4096).decode() + + if ( + re.search('101 Switching Protocols', resp) + and resp[-4:] == '\r\n\r\n' + ): + resp = self._resp_to_dict(resp) + break + return (resp, sock, key) def apply_mask(self, data, mask): |