Skip to content

Commit

Permalink
Patch utcnow in retry delay test (#18343)
Browse files Browse the repository at this point in the history
* Remove sleep from retry delay test

* Change to use freezegun

* Approximate smallest timedelta without numpy

* Use pre-defined smallest timedelta

It turns out `datetime.datetime.resolution` is already defined as the smallest possible timedelta (one microsecond). Attempting to create a timedelta with microseconds in the interval (0.5, 1) simply results in microseconds being rounded up to 1.
  • Loading branch information
edwardwang888 authored Oct 1, 2021
1 parent 8dfb6a7 commit 4f9b097
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tests/models/test_taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import datetime
import os
import signal
import time
import urllib
from tempfile import NamedTemporaryFile
from typing import List, Optional, Union, cast
Expand Down Expand Up @@ -489,7 +488,8 @@ def test_task_retry_wipes_next_fields(self, session, dag_maker):
assert ti.next_kwargs is None
assert ti.state == State.UP_FOR_RETRY

def test_retry_delay(self, dag_maker):
@freeze_time('2021-09-19 04:56:35', as_kwarg='frozen_time')
def test_retry_delay(self, dag_maker, frozen_time=None):
"""
Test that retry delays are respected
"""
Expand Down Expand Up @@ -517,11 +517,12 @@ def run_with_error(ti):
assert ti.try_number == 2

# second run -- still up for retry because retry_delay hasn't expired
frozen_time.tick(delta=datetime.timedelta(seconds=3))
run_with_error(ti)
assert ti.state == State.UP_FOR_RETRY

# third run -- failed
time.sleep(3)
frozen_time.tick(delta=datetime.datetime.resolution)
run_with_error(ti)
assert ti.state == State.FAILED

Expand Down

0 comments on commit 4f9b097

Please sign in to comment.