Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilise the time-based tests with asyncio sleeps/timeouts #212

Open
kopf-archiver bot opened this issue Aug 18, 2020 · 1 comment · May be fixed by #881
Open

Stabilise the time-based tests with asyncio sleeps/timeouts #212

kopf-archiver bot opened this issue Aug 18, 2020 · 1 comment · May be fixed by #881
Labels
archive automation CI/CD: testing, linting, releasing automatically

Comments

@kopf-archiver
Copy link

kopf-archiver bot commented Aug 18, 2020

An issue by nolar at 2019-10-23 17:05:06+00:00
Original URL: zalando-incubator/kopf#212
 

Expected Behavior

The tests with timing use the explicit hard-coded time shifts, and do not fail based of luck or lack of luck.

Actual Behavior

The tests with timing fail randomly since the execution duration varies on a case by case basis.

Example:

Notes

The tests with timings currently use minimised sleep/wait durations and timeouts — to make the whole test-run fast enough. However, this sometimes reaches the measurement error (the code itself takes little but noticeable time).

As a good solution, the sleeps/timeouts should be increased to values far above the code execution durations, and the tests should explicitly shift the time on demand beyond those increased sleeps/timeouts.

There is a tool called freezegun to time-travel during the tests. It does not cover the asyncio sleeps/waits, however. Here is an issue for freezegun: spulec/freezegun#290

Here is a proposed hack to mock asyncio.sleep() and loop.time() methods: https://stackoverflow.com/a/57748106/857383.

Any hack suitable for Kopf-specific testing (not necessary a generic all-purpose solution) would be fine.

@achimnol
Copy link

After hitting this, I just implemented a simple virtual clock for asyncio. Just FYI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archive automation CI/CD: testing, linting, releasing automatically
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant