tests/framework/integration: Fail nesting early

Currently there are a handful of tests within etcd that silently fail
because LeakDetection will skip the test before it manages to hit this
check.

Here we move the check to the beginning of the process to highlight
these cases earlier, and to avoid them accidentally presenting as leaks.
This commit is contained in:
Danielle Lancashire 2022-03-15 18:56:19 +00:00
parent c83b1ad9ba
commit 7cc00ec981

View File

@ -72,6 +72,10 @@ func BeforeTest(t testutil.TB, opts ...TestOption) {
t.Helper() t.Helper()
options := newTestOptions(opts...) options := newTestOptions(opts...)
if insideTestContext {
t.Fatal("already in test context. BeforeTest was likely already called")
}
if options.skipInShort { if options.skipInShort {
testutil.SkipTestIfShortMode(t, "Cannot create clusters in --short tests") testutil.SkipTestIfShortMode(t, "Cannot create clusters in --short tests")
} }
@ -93,10 +97,6 @@ func BeforeTest(t testutil.TB, opts ...TestOption) {
os.Chdir(previousWD) os.Chdir(previousWD)
}) })
if insideTestContext {
t.Fatal("already in test context. BeforeTest was likely already called")
}
grpc_logger.Set(zapgrpc.NewLogger(zaptest.NewLogger(t).Named("grpc"))) grpc_logger.Set(zapgrpc.NewLogger(zaptest.NewLogger(t).Named("grpc")))
insideTestContext = true insideTestContext = true