Skip to content

Commit

Permalink
Merge pull request #132 from matthewdale/fix-datetime-now
Browse files Browse the repository at this point in the history
Always specify UTC timezone to prevent a DST offset bug.
  • Loading branch information
matthewdale authored Apr 20, 2022
2 parents a55be51 + f0d40c0 commit 730e742
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
44 changes: 24 additions & 20 deletions astrolabe/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,30 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging, datetime, time as _time, gzip
import os, io, re
from time import sleep, monotonic
from urllib.parse import urlencode
import datetime
import logging
import os
import re
import time as _time
from datetime import timezone
from time import monotonic, sleep

from pymongo import MongoClient
from tabulate import tabulate
import junitparser
import yaml

from .utils import mongo_client
from atlasclient import AtlasApiError, JSONObject
from astrolabe.commands import (
get_one_organization_by_name, ensure_project, ensure_admin_user,
ensure_connect_from_anywhere)
from astrolabe.exceptions import PollingTimeoutError
from atlasclient.exceptions import AtlasClientError
from astrolabe.exceptions import AstrolabeTestCaseError
from astrolabe.poller import BooleanCallablePoller
from astrolabe.utils import (
assert_subset, get_cluster_name, get_test_name_from_spec_file,
DriverWorkloadSubprocessRunner, SingleTestXUnitLogger,
get_logs, parse_iso8601_time)
from .timer import Timer
from tabulate import tabulate

from astrolabe.commands import (ensure_admin_user,
ensure_connect_from_anywhere, ensure_project,
get_one_organization_by_name)
from astrolabe.exceptions import PollingTimeoutError
from astrolabe.utils import (DriverWorkloadSubprocessRunner,
SingleTestXUnitLogger, assert_subset,
get_cluster_name, get_test_name_from_spec_file, parse_iso8601_time)

from .timer import Timer
from .utils import mongo_client

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -195,7 +194,12 @@ def run(self, persist_cluster=False, startup_time=1):
timer = Timer()
timer.start()
timeout = 300
start_time = datetime.datetime.now()

# The timestamps returned by the "admin" API are UTC timestamps, so record the
# start time in the UTC timezone. All datetimes must be "offset-aware" so they
# can be compared.
start_time = datetime.datetime.now(timezone.utc)

# Account for possible clock drift between our system and
# evergreen infrastructure
_time.sleep(5)
Expand Down
6 changes: 5 additions & 1 deletion astrolabe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,8 @@ def allowed_gai_family():
def parse_iso8601_time(str):
if str[-1] != 'Z':
raise ValueError('Only times ending in Z are supported')
return datetime.datetime.fromisoformat(str[:-1])

# Parse the ISO 8601 format timestamp. We need to keep the timezone offset so that all datetimes
# are "offset-aware" and can be compared. The fromisoformat() parser doesn't support the "Z"
# suffix, so replace it with the UTC time zone offset "+00:00", which the parser does support.
return datetime.datetime.fromisoformat(str.replace("Z", "+00:00"))

0 comments on commit 730e742

Please sign in to comment.