Skip to content

Commit

Permalink
Fix: assertion bug for asynchronous test for getty (#1248)
Browse files Browse the repository at this point in the history
* fix dead lock

* Temporarily fix error occurred in getty unit test

* fix testClient_AsyncCall assertion bug
  • Loading branch information
justxuewei authored Jun 8, 2021
1 parent ff3c563 commit 12261de
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions remoting/getty/getty_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func testGetUser61(t *testing.T, c *Client) {

func testClient_AsyncCall(t *testing.T, client *Client) {
user := &User{}
lock := sync.Mutex{}
wg := sync.WaitGroup{}
request := remoting.NewRequest("2.0.2")
invocation := createInvocation("GetUser0", nil, nil, []interface{}{"4", nil, "username"},
[]reflect.Value{reflect.ValueOf("4"), reflect.ValueOf(nil), reflect.ValueOf("username")})
Expand All @@ -327,13 +327,13 @@ func testClient_AsyncCall(t *testing.T, client *Client) {
r := response.(remoting.AsyncCallbackResponse)
rst := *r.Reply.(*remoting.Response).Result.(*protocol.RPCResult)
assert.Equal(t, User{Id: "4", Name: "username"}, *(rst.Rest.(*User)))
lock.Unlock()
wg.Done()
}
lock.Lock()
wg.Add(1)
err := client.Request(request, 3*time.Second, rsp)
assert.NoError(t, err)
assert.Equal(t, User{}, *user)
time.Sleep(1 * time.Second)
wg.Wait()
}

func InitTest(t *testing.T) (*Server, *common.URL) {
Expand Down Expand Up @@ -450,6 +450,8 @@ func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User
}

func (u *UserProvider) GetUser0(id string, k *User, name string) (User, error) {
// fix testClient_AsyncCall assertion
time.Sleep(1 * time.Second)
return User{Id: id, Name: name}, nil
}

Expand Down

0 comments on commit 12261de

Please sign in to comment.