From 7f3a568983470016bf99baafb4db47c8223c0494 Mon Sep 17 00:00:00 2001
From: Flu0r1ne <flur01ne@flu0r1ne.net>
Date: Sun, 5 Sep 2021 13:38:27 -0500
Subject: Preserve original ordering

---
 fs.go       | 1 +
 runner.go   | 3 +++
 testcase.go | 9 +++++++++
 3 files changed, 13 insertions(+)

diff --git a/fs.go b/fs.go
index 04a3522..b76f182 100644
--- a/fs.go
+++ b/fs.go
@@ -77,6 +77,7 @@ func collectUnits(root string, cfgs []AdapterConfig) []TestCase {
 
   for i := range tcs {
     tcs[i].Cname = Cname(root, tcs[i].Path)
+    tcs[i].readIdx = i
   }
 
   return tcs
diff --git a/runner.go b/runner.go
index 9c1e385..15f08ae 100644
--- a/runner.go
+++ b/runner.go
@@ -4,6 +4,7 @@ import (
 	"log"
 	"os"
         "path"
+        "sort"
 )
 
 type Runner struct {
@@ -128,6 +129,8 @@ func (r Runner) Evaluate(tcs []TestCase) []TestResult {
   for range testSets {
     results = append(results, (<-c)...)
   }
+
+  sort.Sort(ByReadIdx(results))
   
   safeCd(r.dirs.Config())
 
diff --git a/testcase.go b/testcase.go
index 19f1e58..d1db292 100644
--- a/testcase.go
+++ b/testcase.go
@@ -45,8 +45,17 @@ type TestCase struct {
   Cname  string
   
   Config TestCaseConfig
+  
+  // Reorder according to original read order after concurrent operation
+  readIdx     int
 }
 
 func (tc TestCase) AdapterConfig() InheritableConfig {
   return tc.Config.adapters_[*tc.Config.Adapter]
 }
+
+type ByReadIdx []TestResult
+
+func (a ByReadIdx) Len() int           { return len(a) }
+func (a ByReadIdx) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
+func (a ByReadIdx) Less(i, j int) bool { return a[i].Tc.readIdx < a[j].Tc.readIdx }
-- 
cgit v1.2.3