Skip to content

Commit

Permalink
Merge pull request etcd-io#6 from heyitsanthony/error-tests
Browse files Browse the repository at this point in the history
integration: fix leasing concurrent put test, add some error tests
  • Loading branch information
visheshnp authored May 23, 2017
2 parents ab7844f + 9d6022f commit ce0828d
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions clientv3/integration/leasing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
}

0 comments on commit ce0828d

Please sign in to comment.