Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
4e33314f
Commit
4e33314f
authored
Dec 24, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
b74bca96
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
17 deletions
+29
-17
go/internal/xtracing/tracetest/example_test.go
go/internal/xtracing/tracetest/example_test.go
+29
-17
No files found.
go/internal/xtracing/tracetest/example_test.go
View file @
4e33314f
...
@@ -87,24 +87,26 @@ func routeEvent(event interface{}) (stream string) {
...
@@ -87,24 +87,26 @@ func routeEvent(event interface{}) (stream string) {
return
strings
.
ToLower
(
who
[
:
i
])
return
strings
.
ToLower
(
who
[
:
i
])
}
}
// setupTraceEvents sets up tracing and routing.
// verify calls tracetest.Verify on f with first preparing tracing setup and event delivery.
// it is used in the prologue of tests.
// It also verifies that tracetest catches errors as expected. // TODO
func
setupTraceEvents
(
t
*
tracetest
.
T
)
{
func
verify
(
t
*
testing
.
T
,
f
func
(
t
*
tracetest
.
T
))
{
// setup tracing to deliver trace events to t.
tracetest
.
Verify
(
t
,
func
(
t
*
tracetest
.
T
)
{
pg
:=
setupTracing
(
t
)
// setup tracing to deliver trace events to t.
t
.
Cleanup
(
pg
.
Done
)
pg
:=
setupTracing
(
t
)
// tell t to which stream an event should go.
t
.
Cleanup
(
pg
.
Done
)
t
.
SetEventRouter
(
routeEvent
)
// tell t to which stream an event should go.
t
.
SetEventRouter
(
routeEvent
)
// run test code
f
(
t
)
})
}
}
// TestExample demonstrates how to use tracetest to verify concurrent system with 2 threads.
// Test2ThreadsOK demonstrates verifying 2 threads that execute independently.
func
TestExample
(
t
*
testing
.
T
)
{
// There is no concurreny problem here.
tracetest
.
Verify
(
t
,
func
(
t
*
tracetest
.
T
)
{
func
Test2ThreadsOK
(
t
*
testing
.
T
)
{
// setup tracing to deliver trace events to t and route them appropriately.
verify
(
t
,
func
(
t
*
tracetest
.
T
)
{
setupTraceEvents
(
t
)
// run the workload
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
defer
wg
.
Wait
()
defer
wg
.
Wait
()
wg
.
Add
(
2
)
wg
.
Add
(
2
)
...
@@ -117,11 +119,14 @@ func TestExample(t *testing.T) {
...
@@ -117,11 +119,14 @@ func TestExample(t *testing.T) {
go
func
()
{
// thread2
go
func
()
{
// thread2
defer
wg
.
Done
()
defer
wg
.
Done
()
hi
(
"T2·C"
)
hello
(
"T2·C"
)
hi
(
"T2·D"
)
}()
}()
// assert that events come as expected
// assert that events come as expected
t
.
Expect
(
"t2"
,
eventHi
(
"T2·C"
))
// in checks t2 vs t1 order does not matter
t
.
Expect
(
"t2"
,
eventHello
(
"T2·C"
))
t
.
Expect
(
"t2"
,
eventHi
(
"T2·D"
))
t
.
Expect
(
"t1"
,
eventHi
(
"T1·A"
))
t
.
Expect
(
"t1"
,
eventHi
(
"T1·A"
))
t
.
Expect
(
"t1"
,
eventHello
(
"T1·B"
))
t
.
Expect
(
"t1"
,
eventHello
(
"T1·B"
))
...
@@ -131,3 +136,10 @@ func TestExample(t *testing.T) {
...
@@ -131,3 +136,10 @@ func TestExample(t *testing.T) {
//t1.Expect(eventHi("X·A"))
//t1.Expect(eventHi("X·A"))
})
})
}
}
// XXX
func
TestDeadlock
(
t
*
testing
.
T
)
{
verify
(
t
,
func
(
t
*
tracetest
.
T
)
{
})
}
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