diff --git a/test/src/test/groovy/hudson/matrix/MatrixProjectTest.groovy b/test/src/test/groovy/hudson/matrix/MatrixProjectTest.groovy index 85f0db0b1e68d80652882a0979f722c87c0e54b8..5a85b06ada6678d246c68f6b93d4a303767afb04 100644 --- a/test/src/test/groovy/hudson/matrix/MatrixProjectTest.groovy +++ b/test/src/test/groovy/hudson/matrix/MatrixProjectTest.groovy @@ -25,6 +25,8 @@ package hudson.matrix import hudson.model.Cause import hudson.model.Result +import hudson.slaves.DumbSlave +import hudson.slaves.RetentionStrategy import hudson.tasks.Ant import hudson.tasks.ArtifactArchiver import hudson.tasks.Fingerprinter @@ -62,6 +64,8 @@ import java.util.ArrayList; import hudson.model.Action; import java.util.concurrent.CountDownLatch + +import static hudson.model.Node.Mode.EXCLUSIVE import static org.junit.Assert.* import org.junit.Assume import org.junit.Rule @@ -487,4 +491,32 @@ public class MatrixProjectTest { assertNotNull(c.getBuildByNumber(1)); } + /** + * Given a small master and a big exclusive slave, the fair scheduling would prefer running the flyweight job + * in the slave. But if the scheduler honors the EXCLUSIVE flag, then we should see it built on the master. + * + * Since there's a chance that the fair scheduling just so happens to pick up the master by chance, + * we try multiple jobs to reduce the chance of that happening. + */ + @Bug(5076) + @Test + public void dontRunOnExclusiveSlave() { + def projects = (0..10).collect { + def m = j.createMatrixProject() + def axes = new AxisList(); + axes.add(new TextAxis("p", "only")); + m.axes = axes + return m; + } + + def s = new DumbSlave("big", "this is a big slave", j.createTmpDir().path, "20", EXCLUSIVE, "", j.createComputerLauncher(null), RetentionStrategy.NOOP); + j.jenkins.addNode(s); + + s.toComputer().connect(false).get(); // connect this guy + + projects.each { p -> + def b = j.assertBuildStatusSuccess(p.scheduleBuild2(2)) + assertSame(b.builtOn, j.jenkins) + } + } }