Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
b1efff65
Unverified
Commit
b1efff65
authored
Mar 12, 2020
by
Felix Lange
Committed by
GitHub
Mar 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rpc: improve cancel test (#20752)
This is supposed to fix the occasional failures in TestCancel* on Travis CI.
parent
0bdb21f0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
8 deletions
+15
-8
client_test.go
rpc/client_test.go
+9
-7
server_test.go
rpc/server_test.go
+1
-1
testservice_test.go
rpc/testservice_test.go
+5
-0
No files found.
rpc/client_test.go
View file @
b1efff65
...
@@ -179,7 +179,7 @@ func testClientCancel(transport string, t *testing.T) {
...
@@ -179,7 +179,7 @@ func testClientCancel(transport string, t *testing.T) {
var
(
var
(
wg
sync
.
WaitGroup
wg
sync
.
WaitGroup
nreqs
=
10
nreqs
=
10
ncallers
=
6
ncallers
=
10
)
)
caller
:=
func
(
index
int
)
{
caller
:=
func
(
index
int
)
{
defer
wg
.
Done
()
defer
wg
.
Done
()
...
@@ -200,14 +200,16 @@ func testClientCancel(transport string, t *testing.T) {
...
@@ -200,14 +200,16 @@ func testClientCancel(transport string, t *testing.T) {
// deadline.
// deadline.
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
ctx
,
cancel
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
}
}
// Now perform a call with the context.
// Now perform a call with the context.
// The key thing here is that no call will ever complete successfully.
// The key thing here is that no call will ever complete successfully.
sleepTime
:=
maxContextCancelTimeout
+
20
*
time
.
Millisecond
err
:=
client
.
CallContext
(
ctx
,
nil
,
"test_block"
)
err
:=
client
.
CallContext
(
ctx
,
nil
,
"test_sleep"
,
sleepTime
)
switch
{
if
err
!=
nil
{
case
err
==
nil
:
log
.
Debug
(
fmt
.
Sprint
(
"got expected error:"
,
err
))
_
,
hasDeadline
:=
ctx
.
Deadline
()
}
else
{
t
.
Errorf
(
"no error for call with %v wait time (deadline: %v)"
,
timeout
,
hasDeadline
)
t
.
Errorf
(
"no error for call with %v wait time"
,
timeout
)
// default:
// t.Logf("got expected error with %v wait time: %v", timeout, err)
}
}
cancel
()
cancel
()
}
}
...
...
rpc/server_test.go
View file @
b1efff65
...
@@ -45,7 +45,7 @@ func TestServerRegisterName(t *testing.T) {
...
@@ -45,7 +45,7 @@ func TestServerRegisterName(t *testing.T) {
t
.
Fatalf
(
"Expected service calc to be registered"
)
t
.
Fatalf
(
"Expected service calc to be registered"
)
}
}
wantCallbacks
:=
7
wantCallbacks
:=
8
if
len
(
svc
.
callbacks
)
!=
wantCallbacks
{
if
len
(
svc
.
callbacks
)
!=
wantCallbacks
{
t
.
Errorf
(
"Expected %d callbacks for service 'service', got %d"
,
wantCallbacks
,
len
(
svc
.
callbacks
))
t
.
Errorf
(
"Expected %d callbacks for service 'service', got %d"
,
wantCallbacks
,
len
(
svc
.
callbacks
))
}
}
...
...
rpc/testservice_test.go
View file @
b1efff65
...
@@ -77,6 +77,11 @@ func (s *testService) Sleep(ctx context.Context, duration time.Duration) {
...
@@ -77,6 +77,11 @@ func (s *testService) Sleep(ctx context.Context, duration time.Duration) {
time
.
Sleep
(
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
)
{
func
(
s
*
testService
)
Rets
()
(
string
,
error
)
{
return
""
,
nil
return
""
,
nil
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment