6
6
import json
7
7
import os
8
8
import pathlib
9
+ import socket
9
10
import sys
10
11
import traceback
11
12
import unittest
12
13
from types import TracebackType
13
14
from typing import Dict , List , Optional , Tuple , Type , Union
14
15
16
+ from pythonFiles .testing_tools import process_json_util
17
+
15
18
directory_path = pathlib .Path (__file__ ).parent .parent / "lib" / "python"
16
19
# Add the path to pythonFiles to sys.path to find testing_tools.socket_manager.
17
20
PYTHON_FILES = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
28
31
29
32
def parse_execution_cli_args (
30
33
args : List [str ],
31
- ) -> Tuple [int , Union [str , None ], List [ str ] ]:
34
+ ) -> Tuple [int , Union [str , None ]]:
32
35
"""Parse command-line arguments that should be processed by the script.
33
36
34
37
So far this includes the port number that it needs to connect to, the uuid passed by the TS side,
@@ -42,10 +45,9 @@ def parse_execution_cli_args(
42
45
arg_parser = argparse .ArgumentParser ()
43
46
arg_parser .add_argument ("--port" , default = DEFAULT_PORT )
44
47
arg_parser .add_argument ("--uuid" )
45
- arg_parser .add_argument ("--testids" , nargs = "+" )
46
48
parsed_args , _ = arg_parser .parse_known_args (args )
47
49
48
- return (int (parsed_args .port ), parsed_args .uuid , parsed_args . testids )
50
+ return (int (parsed_args .port ), parsed_args .uuid )
49
51
50
52
51
53
ErrorType = Union [
@@ -258,8 +260,57 @@ def send_run_data(raw_data, port, uuid):
258
260
argv = sys .argv [1 :]
259
261
index = argv .index ("--udiscovery" )
260
262
261
- START_DIR , pattern , top_level_dir = parse_unittest_args (argv [index + 1 :])
263
+ start_dir , pattern , top_level_dir = parse_unittest_args (argv [index + 1 :])
264
+
265
+ run_test_ids_port = os .environ .get ("RUN_TEST_IDS_PORT" )
266
+ run_test_ids_port_int = (
267
+ int (run_test_ids_port ) if run_test_ids_port is not None else 0
268
+ )
262
269
263
- # Perform test execution.
264
- PORT , UUID , testids = parse_execution_cli_args (argv [:index ])
265
- payload = run_tests (START_DIR , testids , pattern , top_level_dir , UUID )
270
+ # get data from socket
271
+ test_ids_from_buffer = []
272
+ try :
273
+ client_socket = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
274
+ client_socket .connect (("localhost" , run_test_ids_port_int ))
275
+ buffer = b""
276
+
277
+ while True :
278
+ # Receive the data from the client
279
+ data = client_socket .recv (1024 * 1024 )
280
+ if not data :
281
+ break
282
+
283
+ # Append the received data to the buffer
284
+ buffer += data
285
+
286
+ try :
287
+ # Try to parse the buffer as JSON
288
+ test_ids_from_buffer = process_json_util .process_rpc_json (
289
+ buffer .decode ("utf-8" )
290
+ )
291
+ # Clear the buffer as complete JSON object is received
292
+ buffer = b""
293
+
294
+ # Process the JSON data
295
+ break
296
+ except json .JSONDecodeError :
297
+ # JSON decoding error, the complete JSON object is not yet received
298
+ continue
299
+ except socket .error as e :
300
+ print (f"Error: Could not connect to runTestIdsPort: { e } " )
301
+ print ("Error: Could not connect to runTestIdsPort" )
302
+
303
+ port , uuid = parse_execution_cli_args (argv [:index ])
304
+ if test_ids_from_buffer :
305
+ # Perform test execution.
306
+ payload = run_tests (
307
+ start_dir , test_ids_from_buffer , pattern , top_level_dir , uuid
308
+ )
309
+ else :
310
+ cwd = os .path .abspath (start_dir )
311
+ status = TestExecutionStatus .error
312
+ payload : PayloadDict = {
313
+ "cwd" : cwd ,
314
+ "status" : status ,
315
+ "error" : "No test ids received from buffer" ,
316
+ }
0 commit comments