From a5760155a1ad6945958481d485d96c2393193e40 Mon Sep 17 00:00:00 2001 From: Raihaan Shouhell Date: Fri, 31 Jan 2020 15:31:31 +0800 Subject: [PATCH 1/5] Cleanup tests --- .../jenkins/branch/BranchNameContributorTest.java | 14 -------------- .../branch/NoTriggerBranchPropertyTest.java | 2 +- .../NoTriggerOrganizationFolderPropertyTest.java | 2 +- ...OrganizationChildHealthMetricsPropertyTest.java | 14 -------------- ...OrganizationChildOrphanedItemsPropertyTest.java | 12 ------------ .../OrganizationChildTriggersPropertyTest.java | 12 ------------ .../OverrideIndexTriggersJobPropertyTest.java | 6 +++--- .../branch/PrimaryBranchHealthMetricTest.java | 14 -------------- .../branch/RateLimitBranchPropertyTest.java | 12 +++++++----- 9 files changed, 12 insertions(+), 76 deletions(-) diff --git a/src/test/java/jenkins/branch/BranchNameContributorTest.java b/src/test/java/jenkins/branch/BranchNameContributorTest.java index 7c3855fe..54cddcd9 100644 --- a/src/test/java/jenkins/branch/BranchNameContributorTest.java +++ b/src/test/java/jenkins/branch/BranchNameContributorTest.java @@ -25,9 +25,7 @@ package jenkins.branch; import hudson.EnvVars; -import hudson.model.Computer; import hudson.model.EnvironmentContributor; -import hudson.model.Executor; import hudson.model.FreeStyleProject; import hudson.model.TopLevelItem; import hudson.util.LogTaskListener; @@ -69,18 +67,6 @@ public void cleanOutAllItems() throws Exception { for (TopLevelItem i : r.getInstance().getItems()) { i.delete(); } - for (Computer comp : r.jenkins.getComputers()) { - for (Executor e : comp.getExecutors()) { - if (e.getCauseOfDeath() != null) { - e.doYank(); - } - } - for (Executor e : comp.getOneOffExecutors()) { - if (e.getCauseOfDeath() != null) { - e.doYank(); - } - } - } } @Test diff --git a/src/test/java/jenkins/branch/NoTriggerBranchPropertyTest.java b/src/test/java/jenkins/branch/NoTriggerBranchPropertyTest.java index 3b87af3e..849ace9c 100644 --- a/src/test/java/jenkins/branch/NoTriggerBranchPropertyTest.java +++ b/src/test/java/jenkins/branch/NoTriggerBranchPropertyTest.java @@ -59,7 +59,7 @@ public void smokes() throws Exception { sampleRepo.git("add", "server"); sampleRepo.git("commit", "--all", "--message=release"); MultiBranchImpl stuff = r.jenkins.createProject(MultiBranchImpl.class, "stuff"); - BranchSource branchSource = new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false)); + BranchSource branchSource = new BranchSource(new GitSCMSource(sampleRepo.toString())); branchSource.setStrategy(new NamedExceptionsBranchPropertyStrategy(new BranchProperty[0], new NamedExceptionsBranchPropertyStrategy.Named[] { new NamedExceptionsBranchPropertyStrategy.Named("release*", new BranchProperty[] {new NoTriggerBranchProperty()}) })); diff --git a/src/test/java/jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java b/src/test/java/jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java index d35b1784..6a125c0e 100644 --- a/src/test/java/jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java +++ b/src/test/java/jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java @@ -67,7 +67,7 @@ public void smokes() throws Exception { assertEquals(".*", prop.getBranches()); top.getProperties().replace(new NoTriggerOrganizationFolderProperty("(?!release.*).*")); top.getProjectFactories().add(new OrganizationFolderTest.MockFactory()); - top.getNavigators().add(new SingleSCMNavigator("stuff", Collections.singletonList(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false)))); + top.getNavigators().add(new SingleSCMNavigator("stuff", Collections.singletonList(new GitSCMSource(sampleRepo.toString())))); r.configRoundtrip(top); prop = top.getProperties().get(NoTriggerOrganizationFolderProperty.class); assertNotNull(prop); diff --git a/src/test/java/jenkins/branch/OrganizationChildHealthMetricsPropertyTest.java b/src/test/java/jenkins/branch/OrganizationChildHealthMetricsPropertyTest.java index 564f36da..ed079cdc 100644 --- a/src/test/java/jenkins/branch/OrganizationChildHealthMetricsPropertyTest.java +++ b/src/test/java/jenkins/branch/OrganizationChildHealthMetricsPropertyTest.java @@ -26,8 +26,6 @@ import com.cloudbees.hudson.plugins.folder.health.FolderHealthMetric; import com.cloudbees.hudson.plugins.folder.health.FolderHealthMetricDescriptor; -import hudson.model.Computer; -import hudson.model.Executor; import hudson.model.TopLevelItem; import hudson.util.DescribableList; import integration.harness.BasicMultiBranchProject; @@ -66,18 +64,6 @@ public void cleanOutAllItems() throws Exception { for (TopLevelItem i : r.getInstance().getItems()) { i.delete(); } - for (Computer comp : r.jenkins.getComputers()) { - for (Executor e : comp.getExecutors()) { - if (e.getCauseOfDeath() != null) { - e.doYank(); - } - } - for (Executor e : comp.getOneOffExecutors()) { - if (e.getCauseOfDeath() != null) { - e.doYank(); - } - } - } } @Test diff --git a/src/test/java/jenkins/branch/OrganizationChildOrphanedItemsPropertyTest.java b/src/test/java/jenkins/branch/OrganizationChildOrphanedItemsPropertyTest.java index 59042562..d58f264e 100644 --- a/src/test/java/jenkins/branch/OrganizationChildOrphanedItemsPropertyTest.java +++ b/src/test/java/jenkins/branch/OrganizationChildOrphanedItemsPropertyTest.java @@ -62,18 +62,6 @@ public void cleanOutAllItems() throws Exception { for (TopLevelItem i : r.getInstance().getItems()) { i.delete(); } - for (Computer comp : r.jenkins.getComputers()) { - for (Executor e : comp.getExecutors()) { - if (e.getCauseOfDeath() != null) { - e.doYank(); - } - } - for (Executor e : comp.getOneOffExecutors()) { - if (e.getCauseOfDeath() != null) { - e.doYank(); - } - } - } } @Test diff --git a/src/test/java/jenkins/branch/OrganizationChildTriggersPropertyTest.java b/src/test/java/jenkins/branch/OrganizationChildTriggersPropertyTest.java index 5d6a6ea5..0952a393 100644 --- a/src/test/java/jenkins/branch/OrganizationChildTriggersPropertyTest.java +++ b/src/test/java/jenkins/branch/OrganizationChildTriggersPropertyTest.java @@ -68,18 +68,6 @@ public void cleanOutAllItems() throws Exception { for (TopLevelItem i : r.getInstance().getItems()) { i.delete(); } - for (Computer comp : r.jenkins.getComputers()) { - for (Executor e : comp.getExecutors()) { - if (e.getCauseOfDeath() != null) { - e.doYank(); - } - } - for (Executor e : comp.getOneOffExecutors()) { - if (e.getCauseOfDeath() != null) { - e.doYank(); - } - } - } } @Test diff --git a/src/test/java/jenkins/branch/OverrideIndexTriggersJobPropertyTest.java b/src/test/java/jenkins/branch/OverrideIndexTriggersJobPropertyTest.java index 76142b63..971bb71f 100644 --- a/src/test/java/jenkins/branch/OverrideIndexTriggersJobPropertyTest.java +++ b/src/test/java/jenkins/branch/OverrideIndexTriggersJobPropertyTest.java @@ -62,7 +62,7 @@ public void overridesDisabledBranch() throws Exception { sampleRepo.git("add", "server"); sampleRepo.git("commit", "--all", "--message=release"); MultiBranchImpl stuff = r.jenkins.createProject(MultiBranchImpl.class, "stuff"); - BranchSource branchSource = new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false)); + BranchSource branchSource = new BranchSource(new GitSCMSource(sampleRepo.toString())); branchSource.setStrategy(new NamedExceptionsBranchPropertyStrategy(new BranchProperty[0], new NamedExceptionsBranchPropertyStrategy.Named[] { new NamedExceptionsBranchPropertyStrategy.Named("release*", new BranchProperty[] {new NoTriggerBranchProperty()}) })); @@ -128,7 +128,7 @@ public void overridesDisabledOrg() throws Exception { assertEquals(".*", prop.getBranches()); top.getProperties().replace(new NoTriggerOrganizationFolderProperty("(?!release.*).*")); top.getProjectFactories().add(new OrganizationFolderTest.MockFactory()); - top.getNavigators().add(new SingleSCMNavigator("stuff", Collections.singletonList(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false)))); + top.getNavigators().add(new SingleSCMNavigator("stuff", Collections.singletonList(new GitSCMSource(sampleRepo.toString())))); r.configRoundtrip(top); prop = top.getProperties().get(NoTriggerOrganizationFolderProperty.class); assertNotNull(prop); @@ -188,7 +188,7 @@ public void overridesEnabled() throws Exception { sampleRepo.git("add", "stuff"); sampleRepo.git("commit", "--all", "--message=master-1"); MultiBranchImpl stuff = r.jenkins.createProject(MultiBranchImpl.class, "stuff"); - BranchSource branchSource = new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false)); + BranchSource branchSource = new BranchSource(new GitSCMSource(sampleRepo.toString())); stuff.getSourcesList().add(branchSource); r.configRoundtrip(stuff); stuff.scheduleBuild2(0).getFuture().get(); diff --git a/src/test/java/jenkins/branch/PrimaryBranchHealthMetricTest.java b/src/test/java/jenkins/branch/PrimaryBranchHealthMetricTest.java index 77fe75c4..822d9149 100644 --- a/src/test/java/jenkins/branch/PrimaryBranchHealthMetricTest.java +++ b/src/test/java/jenkins/branch/PrimaryBranchHealthMetricTest.java @@ -1,7 +1,5 @@ package jenkins.branch; -import hudson.model.Computer; -import hudson.model.Executor; import hudson.model.FreeStyleProject; import hudson.model.TopLevelItem; import integration.harness.BasicMultiBranchProject; @@ -30,18 +28,6 @@ public void cleanOutAllItems() throws Exception { for (TopLevelItem i : r.getInstance().getItems()) { i.delete(); } - for (Computer comp : r.jenkins.getComputers()) { - for (Executor e : comp.getExecutors()) { - if (e.getCauseOfDeath() != null) { - e.doYank(); - } - } - for (Executor e : comp.getOneOffExecutors()) { - if (e.getCauseOfDeath() != null) { - e.doYank(); - } - } - } } @Test diff --git a/src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java b/src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java index 5958c24b..aadd8a0a 100644 --- a/src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java +++ b/src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java @@ -197,11 +197,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(); @@ -277,7 +278,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 +287,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) + greaterThanOrEqualTo(delay - 200L), + lessThanOrEqualTo(delay + 500L) ) ); future.get(); From cc57948b5ec5bf210897589caa2a1180b0e0f1af Mon Sep 17 00:00:00 2001 From: Raihaan Shouhell Date: Fri, 31 Jan 2020 17:13:26 +0800 Subject: [PATCH 2/5] Add missing trait --- .../jenkins/branch/NoTriggerBranchPropertyTest.java | 9 ++++++++- .../NoTriggerOrganizationFolderPropertyTest.java | 5 ++++- .../OverrideIndexTriggersJobPropertyTest.java | 13 ++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/test/java/jenkins/branch/NoTriggerBranchPropertyTest.java b/src/test/java/jenkins/branch/NoTriggerBranchPropertyTest.java index 849ace9c..ee82fba1 100644 --- a/src/test/java/jenkins/branch/NoTriggerBranchPropertyTest.java +++ b/src/test/java/jenkins/branch/NoTriggerBranchPropertyTest.java @@ -33,8 +33,13 @@ import jenkins.branch.harness.MultiBranchImpl; import jenkins.plugins.git.GitSCMSource; import jenkins.plugins.git.GitSampleRepoRule; +import jenkins.plugins.git.traits.BranchDiscoveryTrait; + import org.junit.Test; import static org.junit.Assert.*; + +import java.util.Collections; + import org.junit.Rule; import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; @@ -59,7 +64,9 @@ public void smokes() throws Exception { sampleRepo.git("add", "server"); sampleRepo.git("commit", "--all", "--message=release"); MultiBranchImpl stuff = r.jenkins.createProject(MultiBranchImpl.class, "stuff"); - BranchSource branchSource = new BranchSource(new GitSCMSource(sampleRepo.toString())); + GitSCMSource source = new GitSCMSource(sampleRepo.toString()); + source.setTraits(Collections.singletonList(new BranchDiscoveryTrait())); + BranchSource branchSource = new BranchSource(source); branchSource.setStrategy(new NamedExceptionsBranchPropertyStrategy(new BranchProperty[0], new NamedExceptionsBranchPropertyStrategy.Named[] { new NamedExceptionsBranchPropertyStrategy.Named("release*", new BranchProperty[] {new NoTriggerBranchProperty()}) })); diff --git a/src/test/java/jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java b/src/test/java/jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java index 6a125c0e..82eccff1 100644 --- a/src/test/java/jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java +++ b/src/test/java/jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java @@ -31,6 +31,7 @@ import jenkins.branch.harness.MultiBranchImpl; import jenkins.plugins.git.GitSCMSource; import jenkins.plugins.git.GitSampleRepoRule; +import jenkins.plugins.git.traits.BranchDiscoveryTrait; import jenkins.scm.api.SCMSource; import jenkins.scm.impl.SingleSCMNavigator; import static org.junit.Assert.assertEquals; @@ -67,7 +68,9 @@ public void smokes() throws Exception { assertEquals(".*", prop.getBranches()); top.getProperties().replace(new NoTriggerOrganizationFolderProperty("(?!release.*).*")); top.getProjectFactories().add(new OrganizationFolderTest.MockFactory()); - top.getNavigators().add(new SingleSCMNavigator("stuff", Collections.singletonList(new GitSCMSource(sampleRepo.toString())))); + GitSCMSource source = new GitSCMSource(sampleRepo.toString()); + source.setTraits(Collections.singletonList(new BranchDiscoveryTrait())); + top.getNavigators().add(new SingleSCMNavigator("stuff", Collections.singletonList(source))); r.configRoundtrip(top); prop = top.getProperties().get(NoTriggerOrganizationFolderProperty.class); assertNotNull(prop); diff --git a/src/test/java/jenkins/branch/OverrideIndexTriggersJobPropertyTest.java b/src/test/java/jenkins/branch/OverrideIndexTriggersJobPropertyTest.java index 971bb71f..cbc765cd 100644 --- a/src/test/java/jenkins/branch/OverrideIndexTriggersJobPropertyTest.java +++ b/src/test/java/jenkins/branch/OverrideIndexTriggersJobPropertyTest.java @@ -32,6 +32,7 @@ import jenkins.branch.harness.MultiBranchImpl; import jenkins.plugins.git.GitSCMSource; import jenkins.plugins.git.GitSampleRepoRule; +import jenkins.plugins.git.traits.BranchDiscoveryTrait; import jenkins.scm.api.SCMSource; import jenkins.scm.impl.SingleSCMNavigator; import static org.junit.Assert.assertEquals; @@ -62,7 +63,9 @@ public void overridesDisabledBranch() throws Exception { sampleRepo.git("add", "server"); sampleRepo.git("commit", "--all", "--message=release"); MultiBranchImpl stuff = r.jenkins.createProject(MultiBranchImpl.class, "stuff"); - BranchSource branchSource = new BranchSource(new GitSCMSource(sampleRepo.toString())); + GitSCMSource source = new GitSCMSource(sampleRepo.toString()); + source.setTraits(Collections.singletonList(new BranchDiscoveryTrait())); + BranchSource branchSource = new BranchSource(source); branchSource.setStrategy(new NamedExceptionsBranchPropertyStrategy(new BranchProperty[0], new NamedExceptionsBranchPropertyStrategy.Named[] { new NamedExceptionsBranchPropertyStrategy.Named("release*", new BranchProperty[] {new NoTriggerBranchProperty()}) })); @@ -128,7 +131,9 @@ public void overridesDisabledOrg() throws Exception { assertEquals(".*", prop.getBranches()); top.getProperties().replace(new NoTriggerOrganizationFolderProperty("(?!release.*).*")); top.getProjectFactories().add(new OrganizationFolderTest.MockFactory()); - top.getNavigators().add(new SingleSCMNavigator("stuff", Collections.singletonList(new GitSCMSource(sampleRepo.toString())))); + GitSCMSource source = new GitSCMSource(sampleRepo.toString()); + source.setTraits(Collections.singletonList(new BranchDiscoveryTrait())); + top.getNavigators().add(new SingleSCMNavigator("stuff", Collections.singletonList(source))); r.configRoundtrip(top); prop = top.getProperties().get(NoTriggerOrganizationFolderProperty.class); assertNotNull(prop); @@ -188,7 +193,9 @@ public void overridesEnabled() throws Exception { sampleRepo.git("add", "stuff"); sampleRepo.git("commit", "--all", "--message=master-1"); MultiBranchImpl stuff = r.jenkins.createProject(MultiBranchImpl.class, "stuff"); - BranchSource branchSource = new BranchSource(new GitSCMSource(sampleRepo.toString())); + GitSCMSource source = new GitSCMSource(sampleRepo.toString()); + source.setTraits(Collections.singletonList(new BranchDiscoveryTrait())); + BranchSource branchSource = new BranchSource(source); stuff.getSourcesList().add(branchSource); r.configRoundtrip(stuff); stuff.scheduleBuild2(0).getFuture().get(); From 499ed2bf52b22814434282ceb4a5be0d6f16c5b5 Mon Sep 17 00:00:00 2001 From: res0nance Date: Sun, 2 Feb 2020 14:07:54 +0800 Subject: [PATCH 3/5] Cleanup unused imports --- .../jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java | 1 - .../branch/OrganizationChildOrphanedItemsPropertyTest.java | 2 -- .../jenkins/branch/OrganizationChildTriggersPropertyTest.java | 2 -- 3 files changed, 5 deletions(-) diff --git a/src/test/java/jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java b/src/test/java/jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java index 82eccff1..70529108 100644 --- a/src/test/java/jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java +++ b/src/test/java/jenkins/branch/NoTriggerOrganizationFolderPropertyTest.java @@ -32,7 +32,6 @@ import jenkins.plugins.git.GitSCMSource; import jenkins.plugins.git.GitSampleRepoRule; import jenkins.plugins.git.traits.BranchDiscoveryTrait; -import jenkins.scm.api.SCMSource; import jenkins.scm.impl.SingleSCMNavigator; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/src/test/java/jenkins/branch/OrganizationChildOrphanedItemsPropertyTest.java b/src/test/java/jenkins/branch/OrganizationChildOrphanedItemsPropertyTest.java index d58f264e..1b013597 100644 --- a/src/test/java/jenkins/branch/OrganizationChildOrphanedItemsPropertyTest.java +++ b/src/test/java/jenkins/branch/OrganizationChildOrphanedItemsPropertyTest.java @@ -25,8 +25,6 @@ package jenkins.branch; import com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy; -import hudson.model.Computer; -import hudson.model.Executor; import hudson.model.TopLevelItem; import integration.harness.BasicMultiBranchProject; import integration.harness.BasicMultiBranchProjectFactory; diff --git a/src/test/java/jenkins/branch/OrganizationChildTriggersPropertyTest.java b/src/test/java/jenkins/branch/OrganizationChildTriggersPropertyTest.java index 0952a393..e995a67b 100644 --- a/src/test/java/jenkins/branch/OrganizationChildTriggersPropertyTest.java +++ b/src/test/java/jenkins/branch/OrganizationChildTriggersPropertyTest.java @@ -25,8 +25,6 @@ package jenkins.branch; import com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger; -import hudson.model.Computer; -import hudson.model.Executor; import hudson.model.TopLevelItem; import hudson.triggers.Trigger; import hudson.triggers.TriggerDescriptor; From 65a247c7db9e83bbef3e893a4559761ba8474193 Mon Sep 17 00:00:00 2001 From: Raihaan Shouhell Date: Thu, 6 Feb 2020 18:45:56 +0800 Subject: [PATCH 4/5] Cleanup and fix startTime --- .../jenkins/branch/RateLimitBranchPropertyTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java b/src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java index aadd8a0a..e1fed35c 100644 --- a/src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java +++ b/src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java @@ -68,6 +68,7 @@ import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.isNotNull; public class RateLimitBranchPropertyTest { /** @@ -169,13 +170,14 @@ public void rateLimitsBlockBuilds(int rate) throws Exception { ); assertThat(master.isInQueue(), is(false)); assertThat(master.getQueueItem(), nullValue()); + assertThat(master.getBuilds().getLastBuild(), isNotNull()); + long startTime = master.getBuilds().getLastBuild().getTimeInMillis(); QueueTaskFuture 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 @@ -218,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.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(), @@ -245,7 +247,7 @@ public void rateLimitsConcurrentBuilds() throws Exception { QueueTaskFuture future = master.scheduleBuild2(0); QueueTaskFuture future2 = master.scheduleBuild2(0, (Cause) null, (Action) new ParametersAction( - Collections.singletonList(new StringParameterValue("FOO", "MANCHU")))); + Collections.singletonList(new StringParameterValue("FOO", "MANCHU")))); assertThat(future, not(is(future2))); // let the item get added to the queue @@ -308,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.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 @@ -380,7 +382,7 @@ public void rateLimitsUserBoost() throws Exception { // now we trigger a user build... it should skip the queue QueueTaskFuture future2 = master.scheduleBuild2(0, new Cause.UserIdCause(), (Action) new ParametersAction( - Collections.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"); From 18eaf8e05e0625d940663dcde6bf568ba9374120 Mon Sep 17 00:00:00 2001 From: Raihaan Shouhell Date: Thu, 6 Feb 2020 19:09:41 +0800 Subject: [PATCH 5/5] Fix compile error --- src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java b/src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java index e1fed35c..6907b437 100644 --- a/src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java +++ b/src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java @@ -65,10 +65,10 @@ 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; -import static org.mockito.ArgumentMatchers.isNotNull; public class RateLimitBranchPropertyTest { /** @@ -170,7 +170,7 @@ public void rateLimitsBlockBuilds(int rate) throws Exception { ); assertThat(master.isInQueue(), is(false)); assertThat(master.getQueueItem(), nullValue()); - assertThat(master.getBuilds().getLastBuild(), isNotNull()); + assertThat(master.getBuilds().getLastBuild(), notNullValue()); long startTime = master.getBuilds().getLastBuild().getTimeInMillis(); QueueTaskFuture future = master.scheduleBuild2(0);