Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-18861] added test for LatestBuilds.
.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/test/java/hudson/plugins/view/dashboard/builds/LatestBuildsTest.java
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package hudson.plugins.view.dashboard.builds; | ||
|
||
import hudson.model.FreeStyleProject; | ||
import hudson.model.Job; | ||
import hudson.model.Run; | ||
import hudson.plugins.view.dashboard.RunLoadCounter; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.junit.Test; | ||
import org.junit.Rule; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class LatestBuildsTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
public void testAvoidEagerLoading() throws Exception { | ||
final FreeStyleProject p = j.createFreeStyleProject(); | ||
RunLoadCounter.prepare(p); | ||
for (int i = 0; i < 5; i++) { | ||
j.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
} | ||
|
||
int numbuilds = 3; | ||
final LatestBuilds latest = new LatestBuilds("-", numbuilds) { | ||
|
||
@Override | ||
protected List<Job> getDashboardJobs() { | ||
return Collections.singletonList((Job) p); | ||
} | ||
|
||
}; | ||
|
||
int actual = RunLoadCounter.countLoads(p, new Runnable() { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
public void run() { | ||
List<Run> builds = latest.getFinishedBuilds(); | ||
} | ||
}); | ||
assertTrue(actual <= numbuilds); | ||
|
||
} | ||
|
||
} |
BTW the advantage of
assertMaxLoads
is that in case of failure the stack trace shows you why the first excess build was loaded.