|
| 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