diff mbox series

[v2] main: Run multiple branch tests in parallel

Message ID 20190606071750.18146-1-ajd@linux.ibm.com
State Accepted
Delegated to: Russell Currey
Headers show
Series [v2] main: Run multiple branch tests in parallel | expand

Commit Message

Andrew Donnellan June 6, 2019, 7:17 a.m. UTC
Spawn multiple Jenkins tests for different branches in parallel for the
same patch.

This is very very simplistic but should significantly enhance Jenkins
utilisation.

Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>

---
v1->v2:
- cargo fmt
---
 src/main.rs | 46 +++++++++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 17 deletions(-)

Comments

Russell Currey Oct. 21, 2019, 11:01 p.m. UTC | #1
On Thu, 2019-06-06 at 17:17 +1000, Andrew Donnellan wrote:
> Spawn multiple Jenkins tests for different branches in parallel for
> the
> same patch.
> 
> This is very very simplistic but should significantly enhance Jenkins
> utilisation.
> 
> Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>

Thanks, applied to master as eb81b1fc0b41b3390747737b4d974b57d1f4e243
diff mbox series

Patch

diff --git a/src/main.rs b/src/main.rs
index 5ec0c37b2d7f..02c5e5574e0d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -208,6 +208,9 @@  fn test_patch(
     push_opts.remote_callbacks(push_callbacks);
 
     let mut successfully_applied = false;
+
+    let mut test_threads = vec![];
+
     for branch_name in project.branches.clone() {
         let tag = format!("{}_{}", tag, branch_name);
         info!("Configuring local branch for {}.", tag);
@@ -285,30 +288,39 @@  fn test_patch(
         let base = commit.id().to_string();
 
         // We've set up a remote branch, time to kick off tests
-        let test = thread::Builder::new()
-            .name(tag.to_string())
-            .spawn(move || {
-                run_tests(
-                    &settings,
-                    client,
-                    &project,
-                    &tag,
-                    &branch_name,
-                    &base,
-                    hefty_tests,
-                )
-            })
-            .unwrap();
-        results.append(&mut test.join().unwrap());
+        let test = thread::Builder::new().name(tag.to_string()).spawn(move || {
+            run_tests(
+                &settings,
+                client,
+                &project,
+                &tag,
+                &branch_name,
+                &base,
+                hefty_tests,
+            )
+        });
 
-        // Delete the remote branch now it's not needed any more
-        git::push_to_remote(&mut remote, &branch, true, &mut push_opts).unwrap();
+        match test {
+            Ok(thread) => test_threads.push((thread, branch)),
+            Err(e) => {
+                error!("Error spawning thread: {}", e);
+                git::push_to_remote(&mut remote, &branch, true, &mut push_opts).unwrap();
+            }
+        }
 
         if !test_all_branches {
             break;
         }
     }
 
+    // Wait for results
+    for (thread, branch) in test_threads {
+        results.append(&mut thread.join().unwrap());
+
+        // Delete the remote branch now it's not needed any more
+        git::push_to_remote(&mut remote, &branch, true, &mut push_opts).unwrap();
+    }
+
     if !successfully_applied {
         results.push(TestResult {
             state: TestState::Fail,