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
2855a6d5
Commit
2855a6d5
authored
Dec 24, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
89e06498
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
7 deletions
+39
-7
go/internal/xtracing/tracetest/example_test.go
go/internal/xtracing/tracetest/example_test.go
+39
-7
No files found.
go/internal/xtracing/tracetest/example_test.go
View file @
2855a6d5
...
...
@@ -32,6 +32,7 @@ import (
"strings"
"sync"
"testing"
"time"
"lab.nexedi.com/kirr/go123/tracing"
"lab.nexedi.com/kirr/neo/go/internal/xtracing/tracetest"
...
...
@@ -138,7 +139,7 @@ func Test2ThreadsOK(t *testing.T) {
})
}
// TestDeadlock demonstrates deadlock
scenario
.
// TestDeadlock demonstrates deadlock
detection
.
func
TestDeadlock
(
t
*
testing
.
T
)
{
verify
(
t
,
func
(
t
*
tracetest
.
T
)
{
var
wg
sync
.
WaitGroup
...
...
@@ -156,6 +157,33 @@ func TestDeadlock(t *testing.T) {
},
"-tracetest.deadtime=0.5s"
)
}
// TestRace demonstrates detection of logical race.
func
TestRace
(
t
*
testing
.
T
)
{
verify
(
t
,
func
(
t
*
tracetest
.
T
)
{
var
wg
sync
.
WaitGroup
defer
wg
.
Wait
()
wg
.
Add
(
2
)
// 2 threads should synchronize with each other and do step A before B.
// They do not properly synchronize though, and just happen to
// usually emit events in expected order due to sleep in T2.
// Tracetest detects that.
go
func
()
{
// thread1
defer
wg
.
Done
()
hi
(
"x·A"
)
}()
go
func
()
{
// thread2
defer
wg
.
Done
()
time
.
Sleep
(
100
*
time
.
Millisecond
)
hi
(
"x·B"
)
}()
t
.
Expect
(
"x"
,
eventHi
(
"x·A"
))
t
.
Expect
(
"x"
,
eventHi
(
"x·B"
))
})
}
// XXX race bug with sleep caught only by delay injection
...
...
@@ -271,18 +299,22 @@ var testExpectMap = map[string]testExpect{
"TestDeadlock"
:
{
1
,
`--- FAIL: TestDeadlock (<TIME>)
example_test.go:15
5
: t2: recv: deadlock waiting for *tracetest_test.eventHi
example_test.go:15
5
: test shutdown: #streams: 2, #(pending events): 1
example_test.go:15
6
: t2: recv: deadlock waiting for *tracetest_test.eventHi
example_test.go:15
6
: test shutdown: #streams: 2, #(pending events): 1
t1 <- tracetest_test.eventHi T1·A
# t2
tracetest.go:<LINE>: t1: send: canceled (test failed)
`
},
"TestRace"
:
{
1
,
`xxx
`
},
"TestExpectType"
:
{
1
,
`--- FAIL: TestExpectType (<TIME>)
example_test.go:
177
: t1: expect: tracetest_test.eventHello: got tracetest_test.eventHi T1·A
example_test.go:
177
: test shutdown: #streams: 1, #(pending events): 0
example_test.go:
205
: t1: expect: tracetest_test.eventHello: got tracetest_test.eventHi T1·A
example_test.go:
205
: test shutdown: #streams: 1, #(pending events): 0
# t1
tracetest.go:<LINE>: t1: send: unexpected event type
...
...
@@ -290,14 +322,14 @@ var testExpectMap = map[string]testExpect{
"TestExpectValue"
:
{
1
,
`--- FAIL: TestExpectValue (<TIME>)
example_test.go:
193
: t1: expect: tracetest_test.eventHi:
example_test.go:
221
: t1: expect: tracetest_test.eventHi:
want: T1·B
have: T1·A
diff:
-"T1·B"
+"T1·A"
example_test.go:
193
: test shutdown: #streams: 1, #(pending events): 0
example_test.go:
221
: test shutdown: #streams: 1, #(pending events): 0
# t1
tracetest.go:<LINE>: t1: send: unexpected event data
...
...
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