Skip to content

Commit

Permalink
Add Test for Session Expired
Browse files Browse the repository at this point in the history
  • Loading branch information
QuangTung97 committed Apr 4, 2024
1 parent 74133e7 commit d65a798
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
93 changes: 93 additions & 0 deletions client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,9 @@ func clearZKData(c *Client) {
panic(err)
}
c.Delete(p, resp.Stat.Version, func(resp DeleteResponse, err error) {
if err != nil {
fmt.Println("[ERROR] clearZKData:", err, p)
}
wg.Done()
})
})
Expand Down Expand Up @@ -1606,6 +1609,35 @@ func TestClientIntegration_Delete_Empty_Node(t *testing.T) {
}, errors)
}

func TestClientIntegration_Delete_Node_With_Children(t *testing.T) {
c := mustNewClient(t)

var errors []error
c.Create("/workers01", nil, 0, WorldACL(PermAll), func(resp CreateResponse, err error) {
errors = append(errors, err)
})

c.Create("/workers01/data", nil, 0, WorldACL(PermAll), func(resp CreateResponse, err error) {
errors = append(errors, err)
})

c.Delete("/workers01", 0, func(resp DeleteResponse, err error) {
errors = append(errors, err)
})
c.Delete("/workers01/data", 0, func(resp DeleteResponse, err error) {
errors = append(errors, err)
})

c.Close()

assert.Equal(t, []error{
nil,
nil,
ErrNotEmpty,
nil,
}, errors)
}

func TestClientIntegration_WithInvalidPath(t *testing.T) {
t.Run("get", func(t *testing.T) {
c := mustNewClient(t)
Expand Down Expand Up @@ -1847,3 +1879,64 @@ func TestClientIntegration_Create_And_Watch_For_Its_Own_Deletion(t *testing.T) {
assert.Equal(t, []error{nil, nil}, errors)
})
}

func newClientIntegrationWithoutPing() *Client {
ch := make(chan struct{}, 1)

opts := []Option{
WithSessionEstablishedCallback(func(c *Client) {
select {
case ch <- struct{}{}:
default:
}
}),
}

c, err := newClientInternal([]string{"localhost"}, 12*time.Second, opts...)
if err != nil {
panic(err)
}

c.wg.Add(2)

go func() {
defer c.wg.Done()
c.connectAndRunTCPHandlers()
}()

go func() {
defer c.wg.Done()
c.runHandler()
}()

<-ch

clearZKData(c)

return c
}

func TestClientIntegration__Session_Expired(t *testing.T) {
t.Skip()

c := newClientIntegrationWithoutPing()

time.Sleep(1 * time.Second)
c.recvTimeout.Store(int64(30 * time.Second))
c.sendPingRequest()
log.Println("[TEST] Sent Ping")

time.Sleep(16 * time.Second)

var errors []error
c.Create("/workers01", nil, 0, WorldACL(PermAll), func(resp CreateResponse, err error) {
log.Println("[TEST] Handle Create Resp:", err)
errors = append(errors, err)
})

c.Close()

assert.Equal(t, []error{
nil,
}, errors)
}
2 changes: 1 addition & 1 deletion todolist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*) Add CI Pipeline for Integration Tests
*) Batching Read & Write to TCP
*) Batching Read & Write to TCP (Need to do or not?)
*) Stress Tests with Race Detector
*) Add Multi-Ops Transactions

0 comments on commit d65a798

Please sign in to comment.