-
Notifications
You must be signed in to change notification settings - Fork 146
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
Cleanup tests #177
Merged
Merged
Cleanup tests #177
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a576015
Cleanup tests
cc57948
Add missing trait
499ed2b
Cleanup unused imports
res0nance 65a247c
Cleanup and fix startTime
33d57e5
Merge branch 'test-fixes' of https://github.com/res0nance/branch-api-…
18eaf8e
Fix compile error
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ | |
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.lessThanOrEqualTo; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.hamcrest.Matchers.nullValue; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThat; | ||
|
@@ -169,13 +170,14 @@ public void rateLimitsBlockBuilds(int rate) throws Exception { | |
); | ||
assertThat(master.isInQueue(), is(false)); | ||
assertThat(master.getQueueItem(), nullValue()); | ||
assertThat(master.getBuilds().getLastBuild(), notNullValue()); | ||
long startTime = master.getBuilds().getLastBuild().getTimeInMillis(); | ||
QueueTaskFuture<FreeStyleBuild> future = master.scheduleBuild2(0); | ||
|
||
// let the item get added to the queue | ||
while (!master.isInQueue()) { | ||
Thread.yield(); | ||
} | ||
long startTime = System.currentTimeMillis(); | ||
assertThat(master.isInQueue(), is(true)); | ||
|
||
// while it is in the queue, until queue maintenance takes place, it will not be flagged as blocked | ||
|
@@ -197,11 +199,12 @@ public void rateLimitsBlockBuilds(int rate) throws Exception { | |
assertThat(startCondition.isDone(), is(true)); | ||
// it can take more than the requested delay... that's ok, but it should not be | ||
// more than 500ms longer (i.e. 5 of our Queue.maintain loops above) | ||
final long delay = (long)(60.f * 60.f / rate * 1000); | ||
assertThat("At least the rate implied delay but no more than 500ms longer", | ||
System.currentTimeMillis() - startTime, | ||
allOf( | ||
greaterThanOrEqualTo(60 * 60 / rate * 1000L - 200L), | ||
lessThanOrEqualTo(60 * 60 / rate * 1000L * 500L) | ||
greaterThanOrEqualTo(delay - 200L), | ||
lessThanOrEqualTo(delay + 500L) | ||
) | ||
); | ||
future.get(); | ||
|
@@ -217,7 +220,7 @@ public void rateLimitsConcurrentBuilds() throws Exception { | |
prj.setCriteria(null); | ||
BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches())); | ||
BasicParameterDefinitionBranchProperty p = new BasicParameterDefinitionBranchProperty(); | ||
p.setParameterDefinitions(Collections.<ParameterDefinition>singletonList(new StringParameterDefinition("FOO", "BAR"))); | ||
p.setParameterDefinitions(Collections.singletonList(new StringParameterDefinition("FOO", "BAR"))); | ||
source.setStrategy(new DefaultBranchPropertyStrategy(new BranchProperty[]{ | ||
new RateLimitBranchProperty(rate, "hour", false), | ||
new ConcurrentBuildBranchProperty(), | ||
|
@@ -244,7 +247,7 @@ public void rateLimitsConcurrentBuilds() throws Exception { | |
QueueTaskFuture<FreeStyleBuild> future = master.scheduleBuild2(0); | ||
QueueTaskFuture<FreeStyleBuild> future2 = master.scheduleBuild2(0, (Cause) null, | ||
(Action) new ParametersAction( | ||
Collections.<ParameterValue>singletonList(new StringParameterValue("FOO", "MANCHU")))); | ||
Collections.singletonList(new StringParameterValue("FOO", "MANCHU")))); | ||
assertThat(future, not(is(future2))); | ||
|
||
// let the item get added to the queue | ||
|
@@ -277,7 +280,7 @@ public void rateLimitsConcurrentBuilds() throws Exception { | |
// will pick up more responsively than the default 5s | ||
startCondition = future2.getStartCondition(); | ||
long endTime = startTime + 60*60/rate*1000L*5; // at least 5 times the expected delay | ||
while (!startCondition.isDone() && System.currentTimeMillis() < midTime) { | ||
while (!startCondition.isDone() && System.currentTimeMillis() < endTime) { | ||
Queue.getInstance().maintain(); | ||
Thread.sleep(100); | ||
} | ||
|
@@ -286,11 +289,12 @@ public void rateLimitsConcurrentBuilds() throws Exception { | |
FreeStyleBuild secondBuild = startCondition.get(); | ||
// it can take more than the requested delay... that's ok, but it should not be | ||
// more than 500ms longer (i.e. 5 of our Queue.maintain loops above) | ||
final long delay = (long)(60.f * 60.f / rate * 1000); | ||
assertThat("At least the rate implied delay but no more than 500ms longer", | ||
secondBuild.getStartTimeInMillis() - firstBuild.getStartTimeInMillis(), | ||
allOf( | ||
greaterThanOrEqualTo(60 * 60 / rate * 1000L - 200L), | ||
lessThanOrEqualTo(60 * 60 / rate * 1000L * 500L) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
greaterThanOrEqualTo(delay - 200L), | ||
lessThanOrEqualTo(delay + 500L) | ||
) | ||
); | ||
future.get(); | ||
|
@@ -306,7 +310,7 @@ public void rateLimitsUserBoost() throws Exception { | |
prj.setCriteria(null); | ||
BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches())); | ||
BasicParameterDefinitionBranchProperty p = new BasicParameterDefinitionBranchProperty(); | ||
p.setParameterDefinitions(Collections.<ParameterDefinition>singletonList(new StringParameterDefinition("FOO", "BAR"))); | ||
p.setParameterDefinitions(Collections.singletonList(new StringParameterDefinition("FOO", "BAR"))); | ||
source.setStrategy(new DefaultBranchPropertyStrategy(new BranchProperty[]{ | ||
new RateLimitBranchProperty(1, "hour", true), | ||
p | ||
|
@@ -378,7 +382,7 @@ public void rateLimitsUserBoost() throws Exception { | |
// now we trigger a user build... it should skip the queue | ||
QueueTaskFuture<FreeStyleBuild> future2 = master.scheduleBuild2(0, new Cause.UserIdCause(), | ||
(Action) new ParametersAction( | ||
Collections.<ParameterValue>singletonList(new StringParameterValue("FOO", "MANCHU")))); | ||
Collections.singletonList(new StringParameterValue("FOO", "MANCHU")))); | ||
// now we wait for the start... invoking queue maintain every 100ms so that the queue | ||
// will pick up more responsively than the default 5s | ||
LOGGER.info("Checking user submitted build skips"); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably why it flakes all the time lastBuild is not null so it uses the time of the last build to throttle
branch-api-plugin/src/main/java/jenkins/branch/RateLimitBranchProperty.java
Lines 507 to 530 in a1c604b