From 71824474df8f05a41225f712a954e7251c4746b5 Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Fri, 2 Feb 2018 09:38:56 -0800 Subject: [PATCH] snapshot: fix "TestSnapshotV3RestoreMultiMemberAdd" Membership reconfiguration may not be applied when the new member joins. Also pass all endpoints to check restore data in case of leader election or network faults. Signed-off-by: Gyuho Lee --- pkg/testutil/var.go | 1 + snapshot/member_test.go | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/pkg/testutil/var.go b/pkg/testutil/var.go index 753532b9c..0c4c9fc6e 100644 --- a/pkg/testutil/var.go +++ b/pkg/testutil/var.go @@ -17,5 +17,6 @@ package testutil import "time" var ( + ApplyTimeout = time.Second RequestTimeout = 3 * time.Second ) diff --git a/snapshot/member_test.go b/snapshot/member_test.go index 832858dfd..23ca52af1 100644 --- a/snapshot/member_test.go +++ b/snapshot/member_test.go @@ -59,6 +59,9 @@ func TestSnapshotV3RestoreMultiMemberAdd(t *testing.T) { t.Fatal(err) } + // wait for membership reconfiguration apply + time.Sleep(testutil.ApplyTimeout) + cfg := embed.NewConfig() cfg.Name = "3" cfg.InitialClusterToken = testClusterTkn @@ -102,16 +105,21 @@ func TestSnapshotV3RestoreMultiMemberAdd(t *testing.T) { if len(mresp.Members) != 4 { t.Fatalf("expected 4 members, got %+v", mresp) } - for i := range kvs { - var gresp *clientv3.GetResponse - ctx, cancel = context.WithTimeout(context.Background(), testutil.RequestTimeout) - gresp, err = cli2.Get(ctx, kvs[i].k) - cancel() - if err != nil { - t.Fatal(err) + + // make sure restored cluster has kept all data on recovery + var gresp *clientv3.GetResponse + ctx, cancel = context.WithTimeout(context.Background(), testutil.RequestTimeout) + gresp, err = cli2.Get(ctx, "foo", clientv3.WithPrefix()) + cancel() + if err != nil { + t.Fatal(err) + } + for i := range gresp.Kvs { + if string(gresp.Kvs[i].Key) != kvs[i].k { + t.Fatalf("#%d: key expected %s, got %s", i, kvs[i].k, string(gresp.Kvs[i].Key)) } - if string(gresp.Kvs[0].Value) != kvs[i].v { - t.Fatalf("#%d: value expected %s, got %s", i, kvs[i].v, string(gresp.Kvs[0].Value)) + if string(gresp.Kvs[i].Value) != kvs[i].v { + t.Fatalf("#%d: value expected %s, got %s", i, kvs[i].v, string(gresp.Kvs[i].Value)) } } }