Skip to content

Commit

Permalink
test: fix the test failures in e2e/warning_logging_test.go
Browse files Browse the repository at this point in the history
1. Fixed the test failures which are caused by recent test framework rafactoring;
2. renamed the file to promote_experimental_flag_test.go.

Signed-off-by: Benjamin Wang <wachao@vmware.com>
  • Loading branch information
ahrtr committed Nov 18, 2022
1 parent b6916d6 commit f141f43
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/stretchr/testify/assert"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/e2e"
)

func TestWarningApplyDuration(t *testing.T) {
e2e.BeforeTest(t)

epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, &e2e.EtcdProcessClusterConfig{
ClusterSize: 1,
//Set very small duration to trigger warning
WarningUnaryRequestDuration: time.Microsecond,
})
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
e2e.WithClusterSize(1),
e2e.WithWarningUnaryRequestDuration(time.Microsecond),
)
if err != nil {
t.Fatalf("could not start etcd process cluster (%v)", err)
}
Expand All @@ -43,7 +42,7 @@ func TestWarningApplyDuration(t *testing.T) {
}
})

cc, err := e2e.NewEtcdctl(epc.Cfg, epc.EndpointsV3())
cc, err := e2e.NewEtcdctl(epc.Cfg.Client, epc.EndpointsV3())
require.NoError(t, err)
err = cc.Put(context.TODO(), "foo", "bar", config.PutOptions{})
assert.NoError(t, err, "error on put")
Expand All @@ -57,11 +56,10 @@ func TestWarningApplyDuration(t *testing.T) {
func TestExperimentalWarningApplyDuration(t *testing.T) {
e2e.BeforeTest(t)

epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, &e2e.EtcdProcessClusterConfig{
ClusterSize: 1,
//Set very small duration to trigger warning
ExperimentalWarningUnaryRequestDuration: time.Microsecond,
})
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
e2e.WithClusterSize(1),
e2e.WithExperimentalWarningUnaryRequestDuration(time.Microsecond),
)
if err != nil {
t.Fatalf("could not start etcd process cluster (%v)", err)
}
Expand All @@ -71,7 +69,7 @@ func TestExperimentalWarningApplyDuration(t *testing.T) {
}
})

cc, err := e2e.NewEtcdctl(epc.Cfg, epc.EndpointsV3())
cc, err := e2e.NewEtcdctl(epc.Cfg.Client, epc.EndpointsV3())
require.NoError(t, err)
err = cc.Put(context.TODO(), "foo", "bar", config.PutOptions{})
assert.NoError(t, err, "error on put")
Expand All @@ -83,11 +81,11 @@ func TestExperimentalWarningApplyDuration(t *testing.T) {
func TestBothWarningApplyDurationFlagsFail(t *testing.T) {
e2e.BeforeTest(t)

_, err := e2e.NewEtcdProcessCluster(context.TODO(), t, &e2e.EtcdProcessClusterConfig{
ClusterSize: 1,
WarningUnaryRequestDuration: time.Second,
ExperimentalWarningUnaryRequestDuration: time.Second,
})
_, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
e2e.WithClusterSize(1),
e2e.WithWarningUnaryRequestDuration(time.Second),
e2e.WithExperimentalWarningUnaryRequestDuration(time.Second),
)
if err == nil {
t.Fatal("Expected process to fail")
}
Expand Down
10 changes: 10 additions & 0 deletions tests/framework/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ func WithGoFailEnabled(enabled bool) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.GoFailEnabled = enabled }
}

func WithWarningUnaryRequestDuration(time time.Duration) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.WarningUnaryRequestDuration = time }
}

// WithExperimentalWarningUnaryRequestDuration sets a value for `-experimental-warning-unary-request-duration`.
// TODO(ahrtr): remove this function when the corresponding experimental flag is decommissioned.
func WithExperimentalWarningUnaryRequestDuration(time time.Duration) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.ExperimentalWarningUnaryRequestDuration = time }
}

func WithCompactionBatchLimit(limit int) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.CompactionBatchLimit = limit }
}
Expand Down

0 comments on commit f141f43

Please sign in to comment.