Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Commit

Permalink
tests for idempotent Close and deadlock avoidance
Browse files Browse the repository at this point in the history
  • Loading branch information
James DeFelice committed Feb 9, 2018
1 parent 50b46e7 commit dd6d4dd
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions zk/zk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,37 @@ func TestCreate(t *testing.T) {
}
}

func TestOpsAfterCloseDontDeadlock(t *testing.T) {
ts, err := StartTestCluster(1, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
t.Fatal(err)
}
defer ts.Stop()
zk, _, err := ts.ConnectAll()
if err != nil {
t.Fatalf("Connect returned error: %+v", err)
}
zk.Close()

path := "/gozk-test"

ch := make(chan struct{})
go func() {
defer close(ch)
for range make([]struct{}, 30) {
if _, err := zk.Create(path, []byte{1, 2, 3, 4}, 0, WorldACL(PermAll)); err == nil {
t.Fatal("Create did not return error")
}
}
}()
select {
case <-ch:
// expected
case <-time.After(10 * time.Second):
t.Fatal("ZK connection deadlocked when executing ops after a Close operation")
}
}

func TestMulti(t *testing.T) {
ts, err := StartTestCluster(1, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
Expand Down Expand Up @@ -667,6 +698,16 @@ func TestRequestFail(t *testing.T) {
}
}

func TestIdempotentClose(t *testing.T) {
zk, _, err := Connect([]string{"127.0.0.1:32444"}, time.Second*15)
if err != nil {
t.Fatal(err)
}
// multiple calls to Close() should not panic
zk.Close()
zk.Close()
}

func TestSlowServer(t *testing.T) {
ts, err := StartTestCluster(1, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
Expand Down

0 comments on commit dd6d4dd

Please sign in to comment.