From 27783bbb71dd88e1ee84c9158612c9d5c514aefe Mon Sep 17 00:00:00 2001 From: Jonathan Bell Date: Wed, 16 Aug 2023 20:42:52 +0000 Subject: [PATCH] Add logging for timing of each test target + attempt to force jest to run tests in band --- src/TestInfo.py | 8 +++++++- src/test_JS_repo_lib.py | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/TestInfo.py b/src/TestInfo.py index c5bec7e..7d99c9f 100644 --- a/src/TestInfo.py +++ b/src/TestInfo.py @@ -40,9 +40,11 @@ class TestInfo: } # extra args, their position in the arg list, and any post-processing required # post-processing is a function that takes 2 arguments: input file and output file + # CAUTION: DO NOT PUT ANY MORE ARGS AFTER PLACEHOLDER_OUTPUT_FILE_NAME. THE CODE THAT + # PARSES THE OUTPUT RELIES ON THIS BEING THE *LAST* ARGUMENT VERBOSE_TESTS_EXTRA_ARGS = { "jest": { - "args": " --verbose --json --outputFile=$PLACEHOLDER_OUTPUT_FILE_NAME$", + "args": " --verbose --json -i --outputFile=$PLACEHOLDER_OUTPUT_FILE_NAME$", "position": -1, "post_processing": TestOutputProc.parse_jest_json_to_csv }, @@ -116,6 +118,8 @@ def __init__(self, success, error_stream, output_stream, manager, VERBOSE_MODE): self.timed_out = False self.VERBOSE_MODE = VERBOSE_MODE self.test_verbosity_output = None + self.startTime = 0 + self.endTime = 0 def set_test_command( self, test_command): self.test_command = test_command @@ -189,6 +193,8 @@ def get_json_rep( self): if self.test_verbosity_output: json_rep["test_verbosity_output"] = self.test_verbosity_output json_rep["timed_out"] = self.timed_out + json_rep["start_time"] = self.startTime + json_rep["end_time"] = self.endTime return( json_rep) def __str__(self): diff --git a/src/test_JS_repo_lib.py b/src/test_JS_repo_lib.py index abb7fbd..8113f1e 100644 --- a/src/test_JS_repo_lib.py +++ b/src/test_JS_repo_lib.py @@ -2,6 +2,7 @@ import subprocess import json import os +import time from TestInfo import * def run_command( commands, timeout=None): @@ -114,8 +115,13 @@ def run_tests( manager, pkg_json, crawler, repo_name, cur_dir="."): for test_rep_index in range(crawler.TEST_COMMAND_REPEATS): test_rep_id = "" if crawler.TEST_COMMAND_REPEATS == 1 else "testrep_" + str(test_rep_index) print("Running rep " + str(test_rep_index) + " of " + str(crawler.TEST_COMMAND_REPEATS - 1) + ": " + manager + t) + # time how long the next line takes + startTime = time.time() error, output, retcode = run_command( manager + t, crawler.TEST_TIMEOUT) + endTime = time.time() test_info = TestInfo( (retcode == 0), error, output, manager, crawler.VERBOSE_MODE) + test_info.startTime = startTime + test_info.endTime = endTime test_info.set_test_command( pkg_json.get("scripts", {})[t]) test_info.compute_test_infras() test_info.compute_nested_test_commands( test_scripts)