Skip to content

[Bug]: Intermittent test failures with tests using time-machine #15942

@diox

Description

@diox

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Some of our tests are intermittently failing since the switch from freezegun to time-machine (#15892).

It looks like we have those failures when we use travel(datetime.now()) and then check the timestamp, because of microseconds. test_process_event_email_change() is one we've seen fail repeatedly (approximately 1 in 10 times), and the following modification makes it fail consistently on my machine:

    @mock.patch('olympia.accounts.views.primary_email_change_event.delay')
    def test_process_event_email_change(self, event_mock):
        now = datetime.now().replace(microsecond=975982)
        with time_machine.travel(now.timestamp(), tick=False):
            FxaNotificationView().process_event(
                self.FXA_ID,
                FxaNotificationView.FXA_PROFILE_CHANGE_EVENT,
                {'email': 'new-email@example.com'},
            )
            event_mock.assert_called_with(
                self.FXA_ID, now.timestamp(), 'new-email@example.com'
            )

Fails with:

/usr/local/lib/python3.12/unittest/mock.py:949: in assert_called_with
    raise AssertionError(_error_message()) from cause
E   AssertionError: expected call not found.
E   Expected: delay('ABCDEF012345689', 1764162587.975982, 'new-email@example.com')
E     Actual: delay('ABCDEF012345689', 1764162587.9759817, 'new-email@example.com')

What did you expect to happen?

No intermittent failures

┆Issue is synchronized with this Jira Task

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions