Skip to content

Commit 603c888

Browse files
committed
roachtest: add global monitor test
This change adds a test to ensure if the global monitor encounters an error that the error is handled correctly and the test failed. It also ensures that the framework does not panic, in the event of a monitor error. Epic: None Release note: None
1 parent eae1e78 commit 603c888

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

pkg/cmd/roachtest/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ go_test(
9898
"main_test.go",
9999
"test_filter_test.go",
100100
"test_impl_test.go",
101+
"test_monitor_test.go",
101102
"test_registry_test.go",
102103
"test_test.go",
103104
"zip_util_test.go",
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
package main
7+
8+
import (
9+
"context"
10+
"testing"
11+
"time"
12+
13+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster"
14+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
15+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/registry"
16+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/spec"
17+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
18+
"github.com/cockroachdb/cockroach/pkg/util/stop"
19+
"github.com/cockroachdb/errors"
20+
"github.com/stretchr/testify/require"
21+
)
22+
23+
type stubTestMonitorError struct{}
24+
25+
func (s *stubTestMonitorError) ExpectProcessDead(
26+
nodes option.NodeListOption, opts ...option.OptionFunc,
27+
) {
28+
}
29+
30+
func (s *stubTestMonitorError) ExpectProcessAlive(
31+
nodes option.NodeListOption, opts ...option.OptionFunc,
32+
) {
33+
}
34+
35+
func (s *stubTestMonitorError) WaitForNodeDeath() error {
36+
return errors.New("test error")
37+
}
38+
39+
func TestGlobalMonitorError(t *testing.T) {
40+
newTestMonitor = func(_ context.Context, t test.Test, c *clusterImpl) *testMonitorImpl {
41+
return &testMonitorImpl{
42+
monitor: &stubTestMonitorError{},
43+
t: t,
44+
}
45+
}
46+
47+
ctx := context.Background()
48+
stopper := stop.NewStopper()
49+
defer stopper.Stop(ctx)
50+
cr := newClusterRegistry()
51+
runner := newUnitTestRunner(cr, stopper)
52+
53+
var buf syncedBuffer
54+
copt := defaultClusterOpt()
55+
lopt := defaultLoggingOpt(&buf)
56+
57+
mockTest := registry.TestSpec{
58+
Name: `mock test`,
59+
Owner: OwnerUnitTest,
60+
Cluster: spec.MakeClusterSpec(0),
61+
CompatibleClouds: registry.AllExceptAWS,
62+
Suites: registry.Suites(registry.Nightly),
63+
CockroachBinary: registry.StandardCockroach,
64+
Monitor: true,
65+
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
66+
select {
67+
case <-ctx.Done():
68+
return
69+
case <-time.After(5 * time.Minute):
70+
return
71+
}
72+
},
73+
}
74+
err := runner.Run(ctx, []registry.TestSpec{mockTest}, 1, /* count */
75+
defaultParallelism, copt, testOpts{}, lopt)
76+
require.Error(t, err)
77+
}

0 commit comments

Comments
 (0)