From 9d6022f51640c661f68a7e228d5a4307f4b6b3dd Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Tue, 23 May 2017 16:08:00 -0700 Subject: [PATCH] integration: fix leasing concurrent put test, add some error tests --- clientv3/integration/leasing_test.go | 54 ++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/clientv3/integration/leasing_test.go b/clientv3/integration/leasing_test.go index 909897dbab6..e90c7c90e82 100644 --- a/clientv3/integration/leasing_test.go +++ b/clientv3/integration/leasing_test.go @@ -305,8 +305,8 @@ func TestLeasingConcurrentPut(t *testing.T) { if err != nil { t.Fatal(err) } - - if _, err := clus.Client(0).Get(context.TODO(), "k"); err != nil { + // force key into leasing key cache + if _, err := lkv.Get(context.TODO(), "k"); err != nil { t.Fatal(err) } @@ -695,3 +695,53 @@ func TestLeasingTxnNonOwnerPut(t *testing.T) { t.Errorf(`expected value "def", got %+v`, gresp) } } + +func TestLeasingOwnerPutError(t *testing.T) { + defer testutil.AfterTest(t) + clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1}) + defer clus.Terminate(t) + + lkv, err := leasing.NewleasingKV(clus.Client(0), "pfx/") + if err != nil { + t.Fatal(err) + } + if _, err := lkv.Get(context.TODO(), "k"); err != nil { + t.Fatal(err) + } + clus.Members[0].Stop(t) + if resp, err := lkv.Put(context.TODO(), "k", "v"); err == nil { + t.Fatalf("expected error, got response %+v", resp) + } +} + +func TestLeasingOwnerDeleteError(t *testing.T) { + defer testutil.AfterTest(t) + clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1}) + defer clus.Terminate(t) + + lkv, err := leasing.NewleasingKV(clus.Client(0), "pfx/") + if err != nil { + t.Fatal(err) + } + if _, err := lkv.Get(context.TODO(), "k"); err != nil { + t.Fatal(err) + } + clus.Members[0].Stop(t) + if resp, err := lkv.Delete(context.TODO(), "k"); err == nil { + t.Fatalf("expected error, got response %+v", resp) + } +} + +func TestLeasingNonOwnerPutError(t *testing.T) { + defer testutil.AfterTest(t) + clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1}) + defer clus.Terminate(t) + lkv, err := leasing.NewleasingKV(clus.Client(0), "pfx/") + if err != nil { + t.Fatal(err) + } + clus.Members[0].Stop(t) + if resp, err := lkv.Put(context.TODO(), "k", "v"); err == nil { + t.Fatalf("expected error, got response %+v", resp) + } +}