Skip to content

[py] Use monotonic clock for waits, fixes #10544#10550

Merged
diemol merged 2 commits intoSeleniumHQ:trunkfrom
Kache:wait-using-monotonic-clock
Apr 21, 2022
Merged

[py] Use monotonic clock for waits, fixes #10544#10550
diemol merged 2 commits intoSeleniumHQ:trunkfrom
Kache:wait-using-monotonic-clock

Conversation

@Kache
Copy link
Copy Markdown
Contributor

@Kache Kache commented Apr 14, 2022

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Use monotonic clock for waits, fixes #10544

Motivation and Context

WebDriverWait uses time.time(), which displays system clock time and is non-monotonic:

end_time = time.time() + self._timeout

It should instead use time.monotonic(), which is "not affected by system clock updates"

https://docs.python.org/3.7/library/time.html#time.monotonic
https://www.webucator.com/article/python-clocks-explained/
https://en.wikipedia.org/wiki/Monotonic_function

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 14, 2022

CLA assistant check
All committers have signed the CLA.

@Kache
Copy link
Copy Markdown
Contributor Author

Kache commented Apr 14, 2022

image

Copy link
Copy Markdown
Member

@symonk symonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; to my knowledge its OS agnostic? monotonic_ns() is likely unnecessary for the use case here. Thanks. ( Will require someone other than me to allow CI to run I think)

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 19, 2022

Codecov Report

Merging #10550 (d64bcf5) into trunk (49fa97d) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##            trunk   #10550   +/-   ##
=======================================
  Coverage   45.02%   45.02%           
=======================================
  Files          85       85           
  Lines        5508     5508           
  Branches      268      268           
=======================================
  Hits         2480     2480           
  Misses       2760     2760           
  Partials      268      268           
Impacted Files Coverage Δ
py/selenium/webdriver/support/wait.py 36.53% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 49fa97d...d64bcf5. Read the comment docs.

Copy link
Copy Markdown
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing, @symonk!

@diemol diemol merged commit 90901cb into SeleniumHQ:trunk Apr 21, 2022
elgatov pushed a commit to elgatov/selenium that referenced this pull request Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: WebDriverWait uses a non-monotonic clock, time.time()

5 participants