@@ -41,18 +41,41 @@ def run_test(test_folder, parsec_socket):
41
41
sock .listen (1 )
42
42
43
43
while True :
44
+ print ("Waiting for connections" , flush = True )
44
45
connection , client_addr = sock .accept ()
45
46
try :
47
+ print ("Connection received from {}" .format (client_addr ), flush = True )
48
+ # Optionally reduce the default connection timeout
49
+ # connection.settimeout(10)
46
50
received_data = connection .recv (4096 )
47
- b64_received_data = base64 .b64encode (received_data ).decode ("ascii" )
48
- if b64_received_data in test_cases :
49
- (name , test_case ) = test_cases [b64_received_data ]
50
- print ("Received expected request for test case {}" .format (name ))
51
- bin_response = base64 .b64decode (test_case .test_data .response )
52
- connection .sendall (bin_response )
53
- else :
54
- print ("Received unexpected request {}" .format (b64_received_data ))
51
+ all_received_data = bytearray ()
52
+ # Read the socket in cycle until we either
53
+ # - receive a correct command or
54
+ # - fail to receive any data
55
+ while received_data :
56
+ all_received_data += received_data
57
+ b64_received_data = base64 .b64encode (all_received_data ).decode ("ascii" )
58
+ if b64_received_data in test_cases :
59
+ (name , test_case ) = test_cases [b64_received_data ]
60
+ print (
61
+ "Received expected request for test case {}" .format (name ),
62
+ flush = True ,
63
+ )
64
+ bin_response = base64 .b64decode (test_case .test_data .response )
65
+ connection .sendall (bin_response )
66
+ break
67
+
68
+ print (
69
+ "Received unexpected request {}" .format (b64_received_data ),
70
+ flush = True ,
71
+ )
72
+ print ("Continue receiving" , flush = True )
73
+ received_data = connection .recv (4096 )
74
+
75
+ if not received_data :
76
+ print ("No correct command received. No more data to read" , flush = True )
55
77
finally :
78
+ print ("Closing connection" , flush = True )
56
79
connection .close ()
57
80
58
81
0 commit comments