提交 52f9172c 编写于 作者: O Oliver Gondža

[JENKINS-30705] Reset cache for exact results in unittest

上级 e1cdc2a6
...@@ -123,11 +123,13 @@ public class NodeTest { ...@@ -123,11 +123,13 @@ public class NodeTest {
Node node = j.createOnlineSlave(); Node node = j.createOnlineSlave();
node.setLabelString("label1 label2"); node.setLabelString("label1 label2");
FreeStyleProject project = j.createFreeStyleProject(); FreeStyleProject project = j.createFreeStyleProject();
project.setAssignedLabel(j.jenkins.getLabel("label1")); final Label label = j.jenkins.getLabel("label1");
project.setAssignedLabel(label);
label.reset(); // Make sure cached value is not used
TagCloud<LabelAtom> cloud = node.getLabelCloud(); TagCloud<LabelAtom> cloud = node.getLabelCloud();
for(int i =0; i< cloud.size(); i ++){ for(int i =0; i< cloud.size(); i ++){
TagCloud.Entry e = cloud.get(i); TagCloud.Entry e = cloud.get(i);
if(e.item.equals(j.jenkins.getLabel("label1"))){ if(e.item.equals(label)){
assertEquals("Label label1 should have one tied project.", 1, e.weight, 0); assertEquals("Label label1 should have one tied project.", 1, e.weight, 0);
} }
else{ else{
...@@ -256,7 +258,9 @@ public class NodeTest { ...@@ -256,7 +258,9 @@ public class NodeTest {
Integer labelCount = RunLoadCounter.assertMaxLoads(mavenProject, 0, new Callable<Integer>() { Integer labelCount = RunLoadCounter.assertMaxLoads(mavenProject, 0, new Callable<Integer>() {
@Override @Override
public Integer call() throws Exception { public Integer call() throws Exception {
return j.jenkins.getLabel("label1").getTiedJobCount(); final Label label = j.jenkins.getLabel("label1");
label.reset(); // Make sure cached value is not used
return label.getTiedJobCount();
} }
}); });
...@@ -291,15 +295,16 @@ public class NodeTest { ...@@ -291,15 +295,16 @@ public class NodeTest {
node1.setLabelString("label1"); node1.setLabelString("label1");
MavenModuleSet project = j.createMavenProject(); MavenModuleSet project = j.createMavenProject();
project.setAssignedLabel(j.jenkins.getLabel("label1")); final Label label = j.jenkins.getLabel("label1");
project.setAssignedLabel(label);
j.assertBuildStatus(Result.FAILURE, project.scheduleBuild2(0).get()); j.assertBuildStatus(Result.FAILURE, project.scheduleBuild2(0).get());
MavenModuleSet project2 = j.createMavenProject(); MavenModuleSet project2 = j.createMavenProject();
project2.setAssignedLabel(j.jenkins.getLabel("label1")); project2.setAssignedLabel(label);
j.assertBuildStatus(Result.FAILURE, project2.scheduleBuild2(0).get()); j.assertBuildStatus(Result.FAILURE, project2.scheduleBuild2(0).get());
assertEquals("Two jobs should be tied to this label.", label.reset(); // Make sure cached value is not used
2, j.jenkins.getLabel("label1").getTiedJobCount()); assertEquals("Two jobs should be tied to this label.", 2, label.getTiedJobCount());
} }
/** /**
...@@ -312,12 +317,13 @@ public class NodeTest { ...@@ -312,12 +317,13 @@ public class NodeTest {
node.setLabelString("label1"); node.setLabelString("label1");
MavenModuleSet project = j.createMavenProject(); MavenModuleSet project = j.createMavenProject();
project.setAssignedLabel(j.jenkins.getLabel("label1")); final Label label = j.jenkins.getLabel("label1");
project.setAssignedLabel(label);
j.assertBuildStatus(Result.FAILURE, project.scheduleBuild2(0).get()); j.assertBuildStatus(Result.FAILURE, project.scheduleBuild2(0).get());
project.setAssignedLabel(null); project.setAssignedLabel(null);
assertEquals("Label1 should have no tied jobs after the job label was removed.", label.reset(); // Make sure cached value is not used
0, j.jenkins.getLabel("label1").getTiedJobCount()); assertEquals("Label1 should have no tied jobs after the job label was removed.", 0, label.getTiedJobCount());
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册