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

Use same time source for waiting and measuring #7905

Conversation

marcphilipp
Copy link
Contributor

The test now uses the same time source to measure simulated working
times the build operation executor uses to measure the durations of
build operations. Thus, this commit should fix the flakiness on Windows
were System.currentTimeMillis() is not as reliable as on other
operating systems.

The test now uses the same time source to measure simulated working
times the build operation executor uses to measure the durations of
build operations. Thus, this commit should fix the flakiness on Windows
were `System.currentTimeMillis()` is not as reliable as on other
operating systems.
@marcphilipp marcphilipp self-assigned this Dec 4, 2018
@marcphilipp marcphilipp added from:member a:chore Minor issue without significant impact in:tooling-api labels Dec 4, 2018
def elapsed
while ((elapsed = org.gradle.internal.time.Time.currentTimeMillis() - start) < $durationMillis) {
Thread.sleep($durationMillis - elapsed)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem very right.

Suppose start = 100, then after Thread.sleep(100), when elapsed = org.gradle.internal.time.Time.currentTimeMillis() - start is calculated, current time might be 200, 300, 1000, or more, i.e. If the thread happens to wait for a long time between Thread.sleep($durationMillis) and (elapsed = org.gradle.internal.time.Time.currentTimeMillis() - start), elapsed might be very large, then $durationMillis - elapsed is negative. Thread.sleep says

* @throws  IllegalArgumentException
     *          if the value of {@code millis} is negative

Can't we just replace original code to

long start = org.gradle.internal.time.Time.currentTimeMillis()
while (org.gradle.internal.time.Time.currentTimeMillis() - start < $sleepMillis) {
    Thread.sleep($sleepMillis)
}

if System.currentTimeMillis() implementation is not accurate on Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

durationMillis - elapsed is never negative because the while loop is only entered/repeated if elapsed < durationMillis.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah... sorry I was wrong. Then no questions.

while (System.currentTimeMillis() - start < $sleepDurationMillis) {
Thread.sleep(${sleepDurationMillis / 2})
}
${simulateWork(sleepDurationMillis)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, shouldn't this be sleepDurationMillis / 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please ignore the original / 2. That was a spurious attempt to avoid waiting twice as long as intended.

Copy link
Collaborator

@blindpirate blindpirate left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for fixing the flakiness!

@marcphilipp marcphilipp merged commit d10e26a into master Dec 4, 2018
@marcphilipp marcphilipp deleted the marc/fixes/ProjectConfigurationProgressEventCrossVersionSpec branch December 4, 2018 13:35
@marcphilipp
Copy link
Contributor Author

We'll see if it actually fixes it. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:chore Minor issue without significant impact in:tooling-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants