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

[JENKINS-48770] Quiet period is in milliseconds #3591

Merged
merged 3 commits into from Aug 23, 2018

Conversation

fcojfernandez
Copy link
Contributor

See JENKINS-48770.

Detected a regression in how the Quiet Period value from the UI was used. This issue and PR try to fix it.

Proposed changelog entries

  • JENKINS-48770: Fix regression in Quiet Period value that was considering the value as milliseconds instead of seconds

Submitter checklist

  • JIRA issue is well described
  • Changelog entry appropriate for the audience affected by the change (users or developer, depending on the change). Examples
    * Use the Internal: prefix if the change has no user-visible impact (API, test frameworks, etc.)
  • Appropriate autotests or explanation to why this change has no tests
  • For dependency updates: links to external changelogs and, if possible, full diffs

Desired reviewers

@reviewbybees @oleg-nenashev @daniel-beck @batmat

if (delay==null) delay=new TimeDuration(getJob().getQuietPeriod());
if (delay==null)
// time set in UI is in seconds. Changing it into milliseconds
delay=new TimeDuration(getJob().getQuietPeriod() * 1000);
Copy link
Member

Choose a reason for hiding this comment

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

It may not be super useful here, but when converting time units, I usually like to use the TimeUnit enum to convert. Makes it less necessary to comment on the units since it's obvious based on the code then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not used to do it, but I like the idea.

Copy link
Member

Choose a reason for hiding this comment

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

+1, there're a lot of examples in case you are looking for it in the core @fcojfernandez. https://github.com/jenkinsci/jenkins/search?q=TimeUnit&unscoped_q=TimeUnit

For instance, to convert 5 seconds into milliseconds:

assertTrue(diff < TimeUnit.SECONDS.toMillis(5));

@daniel-beck
Copy link
Member

Appropriate autotests or explanation to why this change has no tests

PR lacks both. Given that this was a regression, shouldn't there be tests preventing repeated problems down the road?

@jeffret-b jeffret-b self-requested a review August 16, 2018 17:30
Copy link
Contributor

@jeffret-b jeffret-b left a comment

Choose a reason for hiding this comment

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

I agree with others that it would be nice to have tests verifying the correct behavior. I haven't looked at it enough to figure out how feasible that might be or how they might be implemented.

Also, it would be kind of nice to reduce the duplication, perhaps refactoring to create a common method or two. At a minimum perhaps that might be easily testable.

@fcojfernandez
Copy link
Contributor Author

@jeffret-b @daniel-beck new test added

@Issue("JENKINS-48770")
public void doBuildQuietPeriodInSeconds() throws Exception {
final int projectQuietPeriodInSeconds = 10;
final int projectQuietPeriodInMillis = projectQuietPeriodInSeconds * 1000;
Copy link
Member

Choose a reason for hiding this comment

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

Ironically, no use of TimeUnit here.

Assert.assertEquals(0, project.getBuilds().size());
Thread.sleep(projectQuietPeriodInMillis / 2);
Assert.assertEquals(0, project.getBuilds().size());
Thread.sleep(projectQuietPeriodInMillis / 2 + timeToExecuteProject);
Copy link
Member

Choose a reason for hiding this comment

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

This test seems really long (execution duration of ~15 seconds) for what it accomplishes. I wonder whether it couldn't be sped up.

Copy link
Member

Choose a reason for hiding this comment

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

Queue items tell you how long they're in the queue for. So just set the quiet period to 50 (seconds), trigger a build, ask the Queue.WaitingItem#timestamp whether it'll wait for at least another 45000 millis, and then just abort it?

(If it's not a WaitingItem something else will have gone wrong. Typically LeftItem, meaning the build has already started.)

Copy link
Member

@daniel-beck daniel-beck left a comment

Choose a reason for hiding this comment

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

Looks reasonable, assuming the test fails pre-fix.

@fcojfernandez
Copy link
Contributor Author

@daniel-beck any chance for this PR to be merged or is something else missing before that?

Copy link
Contributor

@jeffret-b jeffret-b left a comment

Choose a reason for hiding this comment

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

I'm glad to see the test.

Looks good.

@jeffret-b jeffret-b merged commit c0d9fb7 into jenkinsci:master Aug 23, 2018
olivergondza pushed a commit that referenced this pull request Aug 24, 2018
[JENKINS-48770] Quiet period is in milliseconds

(cherry picked from commit c0d9fb7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants