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

Refactor int64 timeout to time.Duration #1035

Merged
merged 6 commits into from
Sep 18, 2023
Merged

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Sep 14, 2023

What?

This PR fixes a problem where the timeout was an int64 making it difficult to workout whether that was in seconds or milliseconds. This change enforces us to work with time.Duration when it comes to the default and navigation timeouts.

Why?

This prevents confusion as to whether timeout (which was a int64) was in milliseconds or seconds.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

@ankur22 ankur22 changed the base branch from main to fix/940-propagate-timeout September 14, 2023 17:34
inancgumus
inancgumus previously approved these changes Sep 18, 2023
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

Nice catch, thanks for this! WDYT about the following?

Should we update this part of the code (WaitForEvent), too? And make it millisecond-based for consistency throughout our API?

timeout = b.browser.browserOpts.Timeout * time.Second //nolint:durationcheck

Maybe not related to this PR, but I guess we have a bug in WaitForEvent:

timeout = b.browser.browserOpts.Timeout * time.Second //nolint:durationcheck

It multiplies 30 * time.Second with time.Second (might be problematic if that option is the default):

DefaultTimeout time.Duration = 30 * time.Second

@ankur22
Copy link
Collaborator Author

ankur22 commented Sep 18, 2023

Should we update this part of the code (WaitForEvent), too? And make it millisecond-based for consistency throughout our API?

I like that idea, and yeah, maybe best for another PR. Happy to take that on after i've got these few timeout PRs merged in 👍

@ankur22 ankur22 changed the title Fix/use time duration timeout Refactor int64 timeout to time.Duration Sep 18, 2023
@ankur22 ankur22 mentioned this pull request Sep 18, 2023
3 tasks
Base automatically changed from fix/940-propagate-timeout to main September 18, 2023 10:19
@ankur22 ankur22 dismissed inancgumus’s stale review September 18, 2023 10:19

The base branch was changed.

The timeout is assumed to be in milliseconds when the user sets it
using the provided APIs on browserContext and page. The issue is that
internally it's assumed to be seconds.

This commit fixes that for the default navigation so it's always
assumed to be milliseconds.
The timeout is assumed to be in milliseconds when the user sets it
using the provided APIs on browserContext and page. The issue is that
internally it's assumed to be seconds.

This commit fixes that for the default timeout so it's always
assumed to be milliseconds.
We should try to work with time duration across most of the codebase.
The only place where it could be an int64 is when the module receives
a millisecond value in int64.
time.Duration should be used throughout the codebase instead of int64.
This change ensures that in64 is quickly converted to a time.Duration
which means we have to care less about whether the in64 is in seconds
or milliseconds etc.
We should be working with time.Duration throughout the code base
instead of trying to work out what int64 means. This change aligns the
default timeout to this aim.
We can reduce the sleep time on the timeout integration tests since
the timeout is now not being confused between milliseconds and seconds.
@ankur22 ankur22 force-pushed the fix/use-time-duration-timeout branch from 22ca963 to 1826aaf Compare September 18, 2023 10:22
Copy link
Collaborator

@ka3de ka3de left a comment

Choose a reason for hiding this comment

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

LGTM.

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.

3 participants