Skip to content

Commit

Permalink
chore(e2e): adapt defrag tests for 3.4
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Gosteli <[email protected]>
  • Loading branch information
ghouscht committed Nov 6, 2024
1 parent f309a23 commit 77c7c84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
23 changes: 11 additions & 12 deletions tests/e2e/defrag_no_space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import (
"time"

"github.com/stretchr/testify/require"

"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/e2e"
)

func TestDefragNoSpace(t *testing.T) {
Expand All @@ -46,23 +43,25 @@ func TestDefragNoSpace(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
e2e.BeforeTest(t)

clus, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
e2e.WithClusterSize(1),
e2e.WithGoFailEnabled(true),
clus, err := newEtcdProcessCluster(t,
&etcdProcessClusterConfig{
clusterSize: 1,
debug: true,
goFailEnabled: true,
},
)
require.NoError(t, err)
t.Cleanup(func() { clus.Stop() })

member := clus.Procs[0]
member := clus.procs[0]
etcdctl := member.Etcdctl(clientNonTLS, false, false)

require.NoError(t, member.Failpoints().SetupHTTP(context.Background(), tc.failpoint, fmt.Sprintf(`return("%s")`, tc.err)))
require.ErrorContains(t, member.Etcdctl().Defragment(context.Background(), config.DefragOption{Timeout: time.Minute}), tc.err)
require.ErrorContains(t, etcdctl.Defragment(time.Minute), tc.err)

// Make sure etcd continues to run even after the failed defrag attempt
require.NoError(t, member.Etcdctl().Put(context.Background(), "foo", "bar", config.PutOptions{}))
value, err := member.Etcdctl().Get(context.Background(), "foo", config.GetOptions{})
require.NoError(t, etcdctl.Put("foo", "bar"))
value, err := etcdctl.Get("foo")
require.NoError(t, err)
require.Len(t, value.Kvs, 1)
require.Equal(t, "bar", string(value.Kvs[0].Value))
Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/etcdctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/json"
"fmt"
"strings"
"time"

"go.etcd.io/etcd/clientv3"
)
Expand Down Expand Up @@ -141,6 +142,15 @@ func (ctl *Etcdctl) Compact(rev int64) (*clientv3.CompactResponse, error) {
return nil, spawnWithExpect(args, fmt.Sprintf("compacted revision %v", rev))
}

func (ctl *Etcdctl) Defragment(timeout time.Duration) error {
args := append(ctl.cmdArgs(), "defrag")
if timeout != 0 {
args = append(args, fmt.Sprintf("--command-timeout=%s", timeout))
}

return spawnWithExpect(args, "Finished defragmenting etcd member")
}

func (ctl *Etcdctl) Status() ([]*clientv3.StatusResponse, error) {
var epStatus []*struct {
Endpoint string
Expand Down

0 comments on commit 77c7c84

Please sign in to comment.