提交 8d113a10 编写于 作者: V Valentina Armenise

[JENKINS-30084] address feedbacks

上级 7ea21bbf
...@@ -879,7 +879,7 @@ public class Queue extends ResourceController implements Saveable { ...@@ -879,7 +879,7 @@ public class Queue extends ResourceController implements Saveable {
/** /**
* Gets the snapshot of all {@link BlockedItem}s. * Gets the snapshot of all {@link BlockedItem}s.
*/ */
public List<BlockedItem> getBlockedItems() { protected List<BlockedItem> getBlockedItems() {
return new ArrayList<BlockedItem>(snapshot.blockedProjects); return new ArrayList<BlockedItem>(snapshot.blockedProjects);
} }
...@@ -1583,17 +1583,20 @@ public class Queue extends ResourceController implements Saveable { ...@@ -1583,17 +1583,20 @@ public class Queue extends ResourceController implements Saveable {
ConsistentHash<Node> hash = new ConsistentHash<Node>(NODE_HASH); ConsistentHash<Node> hash = new ConsistentHash<Node>(NODE_HASH);
hash.addAll(hashSource); hash.addAll(hashSource);
Label lbl = p.getAssignedLabel();
for (Node n : hash.list(p.task.getFullDisplayName())) { for (Node n : hash.list(p.task.getFullDisplayName())) {
final Computer c = n.toComputer(); final Computer c = n.toComputer();
if (c == null || c.isOffline()) { if (c == null || c.isOffline()) {
continue; continue;
} }
if (lbl!=null && !lbl.contains(n)) {
continue;
}
if (n.canTake(p) != null) { if (n.canTake(p) != null) {
continue; continue;
} }
return new Runnable() { return new Runnable() {
@Override @Override public void run() {
public void run() {
c.startFlyWeightTask(new WorkUnitContext(p).createWorkUnit(p.task)); c.startFlyWeightTask(new WorkUnitContext(p).createWorkUnit(p.task));
makePending(p); makePending(p);
......
...@@ -814,31 +814,42 @@ public class QueueTest { ...@@ -814,31 +814,42 @@ public class QueueTest {
matrixProject.setAxes(new AxisList( matrixProject.setAxes(new AxisList(
new Axis("axis", "a", "b") new Axis("axis", "a", "b")
)); ));
Label label = LabelExpression.get("aws-linux-dummy"); Label label = LabelExpression.get("aws-linux-dummy");
DummyCloudImpl dummyCloud = new DummyCloudImpl(r, 0); DummyCloudImpl dummyCloud = new DummyCloudImpl(r, 0);
dummyCloud.label = label; dummyCloud.label = label;
PropertyImpl property = new PropertyImpl(); BlockDownstreamProjectExecution property = new BlockDownstreamProjectExecution();
dummyCloud.getNodeProperties().add(property); dummyCloud.getNodeProperties().add(property);
r.jenkins.clouds.add(dummyCloud); r.jenkins.clouds.add(dummyCloud);
matrixProject.setAssignedLabel(label); matrixProject.setAssignedLabel(label);
FreeStyleProject upstreamProject = r.createFreeStyleProject("upstream"); FreeStyleProject upstreamProject = r.createFreeStyleProject("upstream");
upstreamProject.getBuildersList().add(new SleepBuilder(10000));
upstreamProject.setDisplayName("upstream");
//let's assume the flyweighttask has an upstream project and that must be blocked //let's assume the flyweighttask has an upstream project and that must be blocked
// when the upstream project is running // when the upstream project is running
matrixProject.addTrigger(new ReverseBuildTrigger("upstream", Result.SUCCESS)); matrixProject.addTrigger(new ReverseBuildTrigger("upstream", Result.SUCCESS));
matrixProject.setBlockBuildWhenUpstreamBuilding(true); matrixProject.setBlockBuildWhenUpstreamBuilding(true);
//we schedule the project but we pretend no executors are available thus //we schedule the project but we pretend no executors are available thus
//the flyweight task is in the buildable queue without being executed //the flyweight task is in the buildable queue without being executed
matrixProject.scheduleBuild2(0); QueueTaskFuture downstream = matrixProject.scheduleBuild2(0);
if (downstream == null) {
throw new Exception("the flyweight task could not be scheduled, thus the test will be interrupted");
}
//let s wait for the Queue instance to be updated //let s wait for the Queue instance to be updated
while (Queue.getInstance().getBuildableItems().size() != 1) { while (Queue.getInstance().getBuildableItems().size() != 1) {
Thread.sleep(10); Thread.sleep(10);
} }
//in this state the build is not blocked, it's just waiting for an available executor //in this state the build is not blocked, it's just waiting for an available executor
assertFalse(Queue.getInstance().getItems()[0].isBlocked()); assertFalse(Queue.getInstance().getItems()[0].isBlocked());
//we start the upstream project that should block the downstream one //we start the upstream project that should block the downstream one
upstreamProject.getBuildersList().add(new SleepBuilder(10000));
upstreamProject.setDisplayName("upstream");
QueueTaskFuture upstream = upstreamProject.scheduleBuild2(0); QueueTaskFuture upstream = upstreamProject.scheduleBuild2(0);
if (upstream == null) {
throw new Exception("the upstream task could not be scheduled, thus the test will be interrupted");
}
//let s wait for the Upstream to enter the buildable Queue //let s wait for the Upstream to enter the buildable Queue
boolean enteredTheQueue = false; boolean enteredTheQueue = false;
while (!enteredTheQueue) { while (!enteredTheQueue) {
...@@ -856,8 +867,8 @@ public class QueueTest { ...@@ -856,8 +867,8 @@ public class QueueTest {
assertTrue(Queue.getInstance().getItems()[0].isBlocked()); assertTrue(Queue.getInstance().getItems()[0].isBlocked());
assertTrue(Queue.getInstance().getBlockedItems().get(0).task.getDisplayName().equals(matrixProject.displayName)); assertTrue(Queue.getInstance().getBlockedItems().get(0).task.getDisplayName().equals(matrixProject.displayName));
r.assertBuildStatusSuccess(upstream);
//once the upstream is completed, the downstream can join the buildable queue again. //once the upstream is completed, the downstream can join the buildable queue again.
r.assertBuildStatusSuccess(upstream);
while (Queue.getInstance().getBuildableItems().isEmpty()) { while (Queue.getInstance().getBuildableItems().isEmpty()) {
Thread.sleep(10); Thread.sleep(10);
} }
...@@ -868,7 +879,7 @@ public class QueueTest { ...@@ -868,7 +879,7 @@ public class QueueTest {
//let's make sure that the downstram project is not started before the upstream --> we want to simulate //let's make sure that the downstram project is not started before the upstream --> we want to simulate
// the case: buildable-->blocked-->buildable // the case: buildable-->blocked-->buildable
public static class PropertyImpl extends NodeProperty<Slave> { public static class BlockDownstreamProjectExecution extends NodeProperty<Slave> {
@Override @Override
public CauseOfBlockage canTake(Queue.BuildableItem item) { public CauseOfBlockage canTake(Queue.BuildableItem item) {
if (item.task.getName().equals("downstream")) { if (item.task.getName().equals("downstream")) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册