test_java_websockets.py (1771:94cf6c5fafbd) test_java_websockets.py (1819:9344a39fb02e)
1import struct
2import time
3
4import pytest
5from unit.applications.lang.java import TestApplicationJava
6from unit.applications.websockets import TestApplicationWebsocket
7from unit.option import option
8

--- 13 unchanged lines hidden (view full) ---

22
23 def close_connection(self, sock):
24 assert self.recvall(sock, read_timeout=0.1) == b'', 'empty soc'
25
26 self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
27
28 self.check_close(sock)
29
1import struct
2import time
3
4import pytest
5from unit.applications.lang.java import TestApplicationJava
6from unit.applications.websockets import TestApplicationWebsocket
7from unit.option import option
8

--- 13 unchanged lines hidden (view full) ---

22
23 def close_connection(self, sock):
24 assert self.recvall(sock, read_timeout=0.1) == b'', 'empty soc'
25
26 self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
27
28 self.check_close(sock)
29
30 def check_close(self, sock, code=1000, no_close=False):
31 frame = self.ws.frame_read(sock)
30 def check_close(self, sock, code=1000, no_close=False, frame=None):
31 if frame == None:
32 frame = self.ws.frame_read(sock)
32
33 assert frame['fin'] == True, 'close fin'
34 assert frame['opcode'] == self.ws.OP_CLOSE, 'close opcode'
35 assert frame['code'] == code, 'close code'
36
37 if not no_close:
38 sock.close()
39

--- 817 unchanged lines hidden (view full) ---

857 # 5_15
858
859 _, sock, _ = self.ws.upgrade()
860
861 self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment1', fin=False)
862 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2', fin=True)
863 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment3', fin=False)
864 self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment4', fin=True)
33
34 assert frame['fin'] == True, 'close fin'
35 assert frame['opcode'] == self.ws.OP_CLOSE, 'close opcode'
36 assert frame['code'] == code, 'close code'
37
38 if not no_close:
39 sock.close()
40

--- 817 unchanged lines hidden (view full) ---

858 # 5_15
859
860 _, sock, _ = self.ws.upgrade()
861
862 self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment1', fin=False)
863 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2', fin=True)
864 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment3', fin=False)
865 self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment4', fin=True)
865 self.check_close(sock, 1002)
866
866
867 frame = self.ws.frame_read(sock)
868
869 if frame['opcode'] == self.ws.OP_TEXT:
870 self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
871 frame = None
872
873 self.check_close(sock, 1002, frame=frame)
874
867 # 5_16
868
869 _, sock, _ = self.ws.upgrade()
870
871 for i in range(0, 2):
872 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment1', fin=False)
873 self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment2', fin=False)
874 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment3', fin=True)

--- 525 unchanged lines hidden ---
875 # 5_16
876
877 _, sock, _ = self.ws.upgrade()
878
879 for i in range(0, 2):
880 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment1', fin=False)
881 self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment2', fin=False)
882 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment3', fin=True)

--- 525 unchanged lines hidden ---