also looking at this
Unify discovery and programmatic test execution
#23
12 files
+656
-169
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | const std = ; |
| 2 | 2 | const suite = ; |
| 3 | 3 | const reporter = ; |
| 4 | const pipeline = ; | |
| 4 | 5 | const compat = ; |
| 5 | 6 | |
| 6 | 7 | /// Options for bounded parallel test execution. |
| @@ -10,6 +11,7 @@ pub const ParallelOptions = struct { | ||
| 10 | 11 | n_jobs: ?usize = null, |
| 11 | 12 | enabled: bool = false, |
| 12 | 13 | filter: ?[]const u8 = null, |
| 14 | timeout_ms: ?u64 = null, | |
| 13 | 15 | }; |
| 14 | 16 | |
| 15 | 17 | pub const ParallelError = error{ |
| @@ -31,6 +33,7 @@ const WorkerContext = struct { | ||
| 31 | 33 | tests: []const *suite.TestCase, |
| 32 | 34 | next_index: std.atomic.Value(usize) = std.atomic.Value(usize).init(0), |
| 33 | 35 | error_mutex: compat.Mutex = .{}, |
| 36 | policy: pipeline.ExecutionPolicy, | |
| 34 | 37 | |
| 35 | 38 | fn worker(self: *WorkerContext) void { |
| 36 | 39 | while (true) { |
| @@ -90,8 +93,15 @@ const WorkerContext = struct { | ||
| 90 | 93 | test_case.error_message = std.fmt.allocPrint(self.allocator, format, args) catch "Out of memory"; |
| 91 | 94 | } |
| 92 | 95 | |
| 93 | fn finishTiming(_: *WorkerContext, test_case: *suite.TestCase, start_time: i128) void { | |
| 96 | fn finishTiming(self: *WorkerContext, test_case: *suite.TestCase, start_time: i128) void { | |
| 94 | 97 | test_case.execution_time_ns = @intCast(compat.nanoTimestamp() - start_time); |
| 98 | if (test_case.status == .passed and self.policy.timedOut(test_case.execution_time_ns)) { | |
| 99 | self.fail( | |
| 100 | test_case, | |
| 101 | "Test exceeded timeout of {d}ms", | |
| 102 | .{self.policy.timeout_ms.?}, | |
| 103 | ); | |
| 104 | } | |
| 95 | 105 | } |
| 96 | 106 | }; |
| 97 | 107 | |
| @@ -167,6 +177,10 @@ const RunContext = struct { | ||
| 167 | 177 | .allocator = self.allocator, |
| 168 | 178 | .test_suite = test_suite, |
| 169 | 179 | .tests = tests, |
| 180 | .policy = .{ | |
| 181 | .filter = self.options.filter, | |
| 182 | .timeout_ms = self.options.timeout_ms, | |
| 183 | }, | |
| 170 | 184 | }; |
| 171 | 185 | const count = @min(self.worker_limit, tests.len); |
| 172 | 186 | var threads: std.ArrayList(std.Thread) = .empty; |