Skip to content

Commit 200bb49

Browse files
committed
testutils: add SetVModule
Most callers of this from tests only intend to set the vmodule for their test rather than for all tests in the test package/bazel shard. Epic: none Release note: None
1 parent e7cb6d4 commit 200bb49

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pkg/testutils/trace.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ package testutils
77

88
import (
99
"regexp"
10+
"testing"
1011

12+
"github.com/cockroachdb/cockroach/pkg/util/log"
1113
"github.com/cockroachdb/errors"
1214
)
1315

@@ -36,3 +38,21 @@ func MatchInOrder(s string, res ...string) error {
3638
}
3739
return nil
3840
}
41+
42+
// SetVModule sets the logging vmodule. The returned func should be deferred by
43+
// the caller to reset the vmodule at the end of the test
44+
//
45+
// defer testutils.SetVModules(t, "some_file=3")()
46+
//
47+
// Not safe for concurrent use.
48+
func SetVModule(t testing.TB, vmodule string) func() {
49+
prevVModule := log.GetVModule()
50+
if err := log.SetVModule(vmodule); err != nil {
51+
t.Fatalf("failed to set vmodule: %s", err.Error())
52+
}
53+
return func() {
54+
if err := log.SetVModule(prevVModule); err != nil {
55+
t.Fatalf("failed to set vmodule: %s", err.Error())
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)