Enable failpoint by default in integration tests

Signed-off-by: Chao Chen <chaochn@amazon.com>
This commit is contained in:
Chao Chen
2023-06-15 15:30:34 -07:00
parent 9c659eb4e0
commit 6d79b86219
10 changed files with 50 additions and 2 deletions

View File

@ -19,10 +19,13 @@ import (
"testing"
grpc_logsettable "github.com/grpc-ecosystem/go-grpc-middleware/logging/settable"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zapgrpc"
"go.uber.org/zap/zaptest"
gofail "go.etcd.io/gofail/runtime"
"go.etcd.io/etcd/client/pkg/v3/testutil"
"go.etcd.io/etcd/client/pkg/v3/verify"
clientv3 "go.etcd.io/etcd/client/v3"
@ -39,6 +42,12 @@ func init() {
type testOptions struct {
goLeakDetection bool
skipInShort bool
failpoint *failpoint
}
type failpoint struct {
name string
payload string
}
func newTestOptions(opts ...TestOption) *testOptions {
@ -60,6 +69,11 @@ func WithoutSkipInShort() TestOption {
return func(opt *testOptions) { opt.skipInShort = false }
}
// WithFailpoint registers a go fail point
func WithFailpoint(name, payload string) TestOption {
return func(opt *testOptions) { opt.failpoint = &failpoint{name: name, payload: payload} }
}
// BeforeTestExternal initializes test context and is targeted for external APIs.
// In general the `integration` package is not targeted to be used outside of
// etcd project, but till the dedicated package is developed, this is
@ -84,6 +98,16 @@ func BeforeTest(t testutil.TB, opts ...TestOption) {
testutil.RegisterLeakDetection(t)
}
if options.failpoint != nil && len(options.failpoint.name) != 0 {
if len(gofail.List()) == 0 {
t.Skip("please run 'make gofail-enable' before running the test")
}
require.NoError(t, gofail.Enable(options.failpoint.name, options.failpoint.payload))
t.Cleanup(func() {
require.NoError(t, gofail.Disable(options.failpoint.name))
})
}
previousWD, err := os.Getwd()
if err != nil {
t.Fatal(err)