Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: improve cancel test #20752

Merged
merged 2 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func testClientCancel(transport string, t *testing.T) {
var (
wg sync.WaitGroup
nreqs = 10
ncallers = 6
ncallers = 10
)
caller := func(index int) {
defer wg.Done()
Expand All @@ -200,14 +200,16 @@ func testClientCancel(transport string, t *testing.T) {
// deadline.
ctx, cancel = context.WithTimeout(context.Background(), timeout)
}

// Now perform a call with the context.
// The key thing here is that no call will ever complete successfully.
sleepTime := maxContextCancelTimeout + 20*time.Millisecond
err := client.CallContext(ctx, nil, "test_sleep", sleepTime)
if err != nil {
log.Debug(fmt.Sprint("got expected error:", err))
} else {
t.Errorf("no error for call with %v wait time", timeout)
err := client.CallContext(ctx, nil, "test_block")
switch {
case err == nil:
_, hasDeadline := ctx.Deadline()
t.Errorf("no error for call with %v wait time (deadline: %v)", timeout, hasDeadline)
// default:
// t.Logf("got expected error with %v wait time: %v", timeout, err)
}
cancel()
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestServerRegisterName(t *testing.T) {
t.Fatalf("Expected service calc to be registered")
}

wantCallbacks := 7
wantCallbacks := 8
if len(svc.callbacks) != wantCallbacks {
t.Errorf("Expected %d callbacks for service 'service', got %d", wantCallbacks, len(svc.callbacks))
}
Expand Down
5 changes: 5 additions & 0 deletions rpc/testservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func (s *testService) Sleep(ctx context.Context, duration time.Duration) {
time.Sleep(duration)
}

func (s *testService) Block(ctx context.Context) error {
<-ctx.Done()
return errors.New("context canceled in testservice_block")
}

func (s *testService) Rets() (string, error) {
return "", nil
}
Expand Down