Skip to content

Commit a958350

Browse files
committed
Add stateful suite support
Introduces stateful test suites where tests depend on each other and execute sequentially. If any test fails in a stateful suite, all subsequent tests are automatically skipped and marked as failed. Handler processes are closed after stateful suites to force re-spawn and prevent state leaks to the remaining tests.
1 parent 6e01955 commit a958350

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

cmd/runner/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ func main() {
7575
totalPassed += result.PassedTests
7676
totalFailed += result.FailedTests
7777
totalTests += result.TotalTests
78+
79+
// Close handler after stateful suites to prevent state leaks.
80+
// A new handler process will be spawned on-demand when the next request is sent.
81+
if suite.Stateful {
82+
testRunner.CloseHandler()
83+
}
7884
}
7985

8086
fmt.Printf("\n" + strings.Repeat("=", 60) + "\n")

runner/runner.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,30 @@ func (tr *TestRunner) RunTestSuite(ctx context.Context, suite TestSuite) TestRes
106106
TotalTests: len(suite.Tests),
107107
}
108108

109+
skipTests := false
110+
109111
for _, test := range suite.Tests {
110-
testResult := tr.runTest(ctx, test)
112+
var testResult SingleTestResult
113+
114+
if !skipTests {
115+
testResult = tr.runTest(ctx, test)
116+
} else {
117+
// In stateful suites, if any previous test failed, fail all subsequent tests
118+
testResult = SingleTestResult{
119+
TestID: test.Request.ID,
120+
Passed: false,
121+
Message: "Skipped due to previous test failure in stateful suite",
122+
}
123+
}
124+
111125
result.TestResults = append(result.TestResults, testResult)
112126
if testResult.Passed {
113127
result.PassedTests++
114128
} else {
115129
result.FailedTests++
130+
if suite.Stateful {
131+
skipTests = true
132+
}
116133
}
117134
}
118135

runner/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ type TestSuite struct {
1616
Name string `json:"name"`
1717
Description string `json:"description,omitempty"`
1818
Tests []TestCase `json:"tests"`
19+
20+
// Stateful indicates that tests in this suite depend on each other and must
21+
// execute sequentially. If any test fails in a stateful suite, all subsequent
22+
// tests are automatically skipped and considered as failed. Use this for test
23+
// suites where later tests depend on the success of earlier tests
24+
// (e.g., setup -> operation -> verification).
25+
Stateful bool `json:"stateful,omitempty"`
1926
}
2027

2128
// Request represents a request sent to the handler

0 commit comments

Comments
 (0)