good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
jrpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
jrpc
Commits
157b5514
Commit
157b5514
authored
Jun 3, 2023
by
a
Browse files
Options
Downloads
Patches
Plain Diff
pass more tests
parent
eeef1e4f
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!15
Draft: V2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/jrpctest/suites.go
+64
-1
64 additions, 1 deletion
pkg/jrpctest/suites.go
with
64 additions
and
1 deletion
pkg/jrpctest/suites.go
+
64
−
1
View file @
157b5514
...
@@ -148,11 +148,74 @@ func RunBasicTestSuite(t *testing.T, args BasicTestSuiteArgs) {
...
@@ -148,11 +148,74 @@ func RunBasicTestSuite(t *testing.T, args BasicTestSuiteArgs) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
})
})
makeTest
(
"context cancel"
,
func
(
t
*
testing
.
T
,
server
*
jrpc
.
Server
,
client
jrpc
.
Conn
)
{
maxContextCancelTimeout
:=
300
*
time
.
Millisecond
// The actual test starts here.
var
(
wg
sync
.
WaitGroup
nreqs
=
10
ncallers
=
10
)
caller
:=
func
(
index
int
)
{
defer
wg
.
Done
()
for
i
:=
0
;
i
<
nreqs
;
i
++
{
var
(
ctx
context
.
Context
cancel
func
()
timeout
=
time
.
Duration
(
rand
.
Int63n
(
int64
(
maxContextCancelTimeout
)))
)
if
index
<
ncallers
/
2
{
// For half of the callers, create a context without deadline
// and cancel it later.
ctx
,
cancel
=
context
.
WithCancel
(
context
.
Background
())
time
.
AfterFunc
(
timeout
,
cancel
)
}
else
{
// For the other half, create a context with a deadline instead. This is
// different because the context deadline is used to set the socket write
// 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.
err
:=
jrpc
.
CallInto
(
ctx
,
client
,
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
()
}
}
wg
.
Add
(
ncallers
)
for
i
:=
0
;
i
<
ncallers
;
i
++
{
go
caller
(
i
)
}
wg
.
Wait
()
})
}
type
ServerRemaker
func
(
address
string
)
(
*
jrpc
.
Server
,
ClientMaker
,
func
())
type
ReconnectTestSuiteArgs
struct
{
ServerMaker
ServerMaker
}
func
RunReconnectSuite
(
t
*
testing
.
T
,
args
BasicTestSuiteArgs
)
{
server
,
dialer
,
cn
:=
args
.
ServerMaker
()
defer
cn
()
defer
server
.
Stop
()
client
:=
dialer
()
defer
client
.
Close
()
}
}
// This test checks that requests made through Call can be canceled by canceling
// This test checks that requests made through Call can be canceled by canceling
// the context.
// the context.
func
C
ancelTester
(
t
*
testing
.
T
,
server
*
jrpc
.
Server
,
client
jrpc
.
Conn
)
{
func
c
ancelTester
(
t
*
testing
.
T
,
server
*
jrpc
.
Server
,
client
jrpc
.
Conn
)
{
maxContextCancelTimeout
:=
300
*
time
.
Millisecond
maxContextCancelTimeout
:=
300
*
time
.
Millisecond
// The actual test starts here.
// The actual test starts here.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment