Skip to content

Commit

Permalink
[JENKINS-18861] added test for LatestBuilds.
Browse files Browse the repository at this point in the history
.
  • Loading branch information
ssogabe committed Aug 12, 2013
1 parent ec0a531 commit a644fad
Showing 1 changed file with 46 additions and 0 deletions.
@@ -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.

Copy link
@jglick

jglick Aug 12, 2013

Member

BTW the advantage of assertMaxLoads is that in case of failure the stack trace shows you why the first excess build was loaded.

public void run() {
List<Run> builds = latest.getFinishedBuilds();
}
});
assertTrue(actual <= numbuilds);

}

}

0 comments on commit a644fad

Please sign in to comment.