Skip to content

Commit

Permalink
Update watch stream client codes
Browse files Browse the repository at this point in the history
  • Loading branch information
krapie committed Dec 2, 2023
1 parent 9ae695d commit 3ebef65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
23 changes: 17 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,16 +431,22 @@ func (c *Client) Watch(
return nil, err
}

pbResp := stream.Msg()
if err != nil {
return nil, err
for stream.Receive() {
pbResp := stream.Msg()
if err != nil {
return nil, err
}
if _, err := handleResponse(pbResp, doc); err != nil {
return nil, err
}
break
}
if _, err := handleResponse(pbResp, doc); err != nil {
return nil, err
if err = stream.Err(); err != nil {
return nil, connect.NewError(connect.CodeUnknown, err)
}

go func() {
for {
for stream.Receive() {
pbResp := stream.Msg()
if err != nil {
rch <- WatchResponse{Err: err}
Expand All @@ -459,6 +465,11 @@ func (c *Client) Watch(

rch <- *resp
}
if err = stream.Err(); err != nil {
rch <- WatchResponse{Err: err}
close(rch)
return
}
}()

// TODO(hackerwins): We need to revise the implementation of the watch
Expand Down
7 changes: 5 additions & 2 deletions server/rpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,11 @@ func TestSDKRPCServerBackend(t *testing.T) {
assert.NoError(t, err)

// check if stream is open
_ = watchResp.Msg()
assert.NoError(t, err)
for watchResp.Receive() {
resp := watchResp.Msg()
assert.NotNil(t, resp)
break
}

//// wait for MaxConnectionAge + MaxConnectionAgeGrace
//time.Sleep(helper.RPCMaxConnectionAge + helper.RPCMaxConnectionAgeGrace)
Expand Down

0 comments on commit 3ebef65

Please sign in to comment.