diff options
author | Yves Duhem <yves.duhem@mongodb.com> | 2018-01-16 11:09:10 -0500 |
---|---|---|
committer | Yves Duhem <yves.duhem@mongodb.com> | 2018-01-16 11:09:13 -0500 |
commit | 07031843f1868a956b28f9e0e4d546cce4badfbf (patch) | |
tree | b9d780be98b3377853c063cc0862a171a04addee /buildscripts | |
parent | 0bb9226dcedc4bcb98ce97f10f1262da3905d71b (diff) | |
download | mongo-07031843f1868a956b28f9e0e4d546cce4badfbf.tar.gz |
SERVER-32614 Remove usage of non-threadsafe strptime()
Diffstat (limited to 'buildscripts')
-rwxr-xr-x | buildscripts/test_failures.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/buildscripts/test_failures.py b/buildscripts/test_failures.py index ea9ce31f9b2..29bd25a2d7b 100755 --- a/buildscripts/test_failures.py +++ b/buildscripts/test_failures.py @@ -518,21 +518,12 @@ class TestHistory(object): Returns a ReportEntry() tuple representing the 'test_result' dictionary. """ - def parse_date(date_str): - """ - Returns a datetime.date() instance representing the specified yyyy-mm-dd date string. - - Note that any time component of 'date_str', including the timezone, is ignored. - """ - - return datetime.datetime.strptime(date_str.split("T")[0], "%Y-%m-%d").date() - # For individual test executions, we intentionally use the "start_time" of the test as both # its 'start_date' and 'end_date' to avoid complicating how the test history is potentially # summarized by time. By the time the test has started, the Evergreen task has already been # assigned to a particular machine and is using a specific set of binaries, so there's # unlikely to be a significance to when the test actually finishes. - start_date = end_date = parse_date(test_result["start_time"]) + start_date = end_date = _parse_date(test_result["start_time"]) return ReportEntry( test=self._normalize_test_file(test_result["test_file"]), @@ -600,6 +591,17 @@ class TestHistory(object): } +def _parse_date(date_str): + """ + Returns a datetime.date instance representing the specified yyyy-mm-dd date string. + + Note that any time component of 'date_str', including the timezone, is ignored. + """ + # We do not use strptime() because it is not thread safe (https://bugs.python.org/issue7980). + year, month, day = date_str.split("T")[0].split("-") + return datetime.date(int(year), int(month), int(day)) + + class JSONResponseError(Exception): """An exception raised when failing to decode the JSON from an Evergreen response.""" @@ -697,7 +699,7 @@ def main(): try: setattr(options, option_dest, - datetime.datetime.strptime(option_value, "%Y-%m-%d").date()) + _parse_date(option_value)) except ValueError: parser.print_help(file=sys.stderr) print(file=sys.stderr) |