44import static org .junit .jupiter .api .Assertions .assertFalse ;
55import static org .junit .jupiter .api .Assertions .assertTrue ;
66
7- import hudson .model .FreeStyleBuild ;
87import hudson .model .FreeStyleProject ;
98import hudson .model .Run ;
10- import hudson .model .queue .QueueTaskFuture ;
119import java .io .File ;
1210import java .util .List ;
1311import java .util .Set ;
@@ -33,7 +31,8 @@ void setUp(JenkinsRule rule) {
3331
3432 @ Test
3533 void testUpdateResult () throws Exception {
36- String nodeName = "test-node" ;
34+ String nodeName1 = "test-node-1" ;
35+ String nodeName2 = "test-node-2" ;
3736 String jobName = "test-job" ;
3837 jenkinsRule .jenkins .setNumExecutors (2 );
3938
@@ -46,30 +45,44 @@ void testUpdateResult() throws Exception {
4645 Run <?, ?> run2 = project .scheduleBuild2 (0 ).waitForStart ();
4746
4847 // Simulate adding a run to the node index
49- BuildHistoryFileManager .addRunToNodeIndex (nodeName , run1 , storageDir .getAbsolutePath ());
50- BuildHistoryFileManager .addRunToNodeIndex (nodeName , run2 , storageDir .getAbsolutePath ());
51-
52- List <String > indexEntries = BuildHistoryFileManager .readIndexFile (nodeName , storageDir .getAbsolutePath ());
53- assertEquals (2 , indexEntries .size ());
54- assertTrue (indexEntries .get (0 ).contains (jobName +";1;" ), "Index should contain build number" );
55- assertFalse (indexEntries .get (0 ).contains ("SUCCESS" ), "Index should not contain the updated result" );
56- assertTrue (indexEntries .get (1 ).contains (jobName +";2;" ), "Index should contain build number" );
57- assertFalse (indexEntries .get (1 ).contains ("SUCCESS" ), "Index should not contain the updated result" );
48+ BuildHistoryFileManager .addRunToNodeIndex (nodeName1 , run1 , storageDir .getAbsolutePath ());
49+ BuildHistoryFileManager .addRunToNodeIndex (nodeName2 , run2 , storageDir .getAbsolutePath ());
50+
51+ List <String > indexEntries1 = BuildHistoryFileManager .readIndexFile (nodeName1 , storageDir .getAbsolutePath ());
52+ List <String > indexEntries2 = BuildHistoryFileManager .readIndexFile (nodeName2 , storageDir .getAbsolutePath ());
53+ assertEquals (1 , indexEntries1 .size ());
54+ assertEquals (1 , indexEntries2 .size ());
55+ assertTrue (indexEntries1 .get (0 ).contains (jobName +";1;" ), "Index should contain build number" );
56+ assertFalse (indexEntries1 .get (0 ).contains ("SUCCESS" ), "Index should not contain the updated result" );
57+ assertTrue (indexEntries2 .get (0 ).contains (jobName +";2;" ), "Index should contain build number" );
58+ assertFalse (indexEntries2 .get (0 ).contains ("SUCCESS" ), "Index should not contain the updated result" );
5859
5960 jenkinsRule .waitForCompletion (run1 );
6061 jenkinsRule .waitForCompletion (run2 );
6162
6263 // Update the result of the run
63- BuildHistoryFileManager .updateResult (nodeName , run1 , storageDir .getAbsolutePath ());
64- BuildHistoryFileManager .updateResult (nodeName , run2 , storageDir .getAbsolutePath ());
64+ BuildHistoryFileManager .updateResult (nodeName1 , run1 , storageDir .getAbsolutePath ());
65+ BuildHistoryFileManager .updateResult (nodeName2 , run2 , storageDir .getAbsolutePath ());
6566
6667 // Verify that the index file contains the updated result
67- indexEntries = BuildHistoryFileManager .readIndexFile (nodeName , storageDir .getAbsolutePath ());
68- assertEquals (2 , indexEntries .size ());
69- assertTrue (indexEntries .get (0 ).contains (jobName +";1;" ), "Index should contain build number" );
70- assertTrue (indexEntries .get (0 ).contains ("SUCCESS" ), "Index should contain the updated result" );
71- assertTrue (indexEntries .get (1 ).contains (jobName +";2;" ), "Index should contain build number" );
72- assertTrue (indexEntries .get (1 ).contains ("SUCCESS" ), "Index should contain the updated result" );
68+ indexEntries1 = BuildHistoryFileManager .readIndexFile (nodeName1 , storageDir .getAbsolutePath ());
69+ indexEntries2 = BuildHistoryFileManager .readIndexFile (nodeName2 , storageDir .getAbsolutePath ());
70+ assertEquals (1 , indexEntries1 .size ());
71+ assertEquals (1 , indexEntries2 .size ());
72+ assertTrue (indexEntries1 .get (0 ).contains (jobName +";1;" ), "Index should contain build number" );
73+ assertTrue (indexEntries1 .get (0 ).contains ("SUCCESS" ), "Index should contain the updated result" );
74+ assertTrue (indexEntries2 .get (0 ).contains (jobName +";2;" ), "Index should contain build number" );
75+ assertTrue (indexEntries2 .get (0 ).contains ("SUCCESS" ), "Index should contain the updated result" );
76+
77+ // Verify that the index file is not updated when the run was not on that node
78+ BuildHistoryFileManager .updateResult (nodeName2 , run1 , storageDir .getAbsolutePath ());
79+ BuildHistoryFileManager .updateResult (nodeName1 , run2 , storageDir .getAbsolutePath ());
80+ assertEquals (1 , indexEntries1 .size ());
81+ assertEquals (1 , indexEntries2 .size ());
82+ assertTrue (indexEntries1 .get (0 ).contains (jobName +";1;" ), "Index should contain build number" );
83+ assertTrue (indexEntries1 .get (0 ).contains ("SUCCESS" ), "Index should contain the updated result" );
84+ assertTrue (indexEntries2 .get (0 ).contains (jobName +";2;" ), "Index should contain build number" );
85+ assertTrue (indexEntries2 .get (0 ).contains ("SUCCESS" ), "Index should contain the updated result" );
7386 }
7487
7588 @ Test
0 commit comments