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
d4512699
Commit
d4512699
authored
Oct 08, 2014
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eventer: add test for concurrent Post/Register
This test reports the race condition when run using "go test -race".
parent
7c9508ed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
1 deletion
+48
-1
eventer_test.go
eventer/eventer_test.go
+48
-1
No files found.
eventer/eventer_test.go
View file @
d4512699
package
eventer
import
"testing"
import
(
"math/rand"
"testing"
"time"
)
func
TestChannel
(
t
*
testing
.
T
)
{
eventer
:=
New
()
...
...
@@ -64,3 +68,46 @@ func TestOn(t *testing.T) {
t
.
Error
(
"Expected function event with data 'hello world'. Got"
,
data
)
}
}
func
TestConcurrentUsage
(
t
*
testing
.
T
)
{
rand
.
Seed
(
time
.
Now
()
.
Unix
())
eventer
:=
New
()
stop
:=
make
(
chan
struct
{})
recv
:=
make
(
chan
int
)
poster
:=
func
()
{
for
{
select
{
case
<-
stop
:
return
default
:
eventer
.
Post
(
"test"
,
"hi"
)
}
}
}
listener
:=
func
(
i
int
)
{
time
.
Sleep
(
time
.
Duration
(
rand
.
Intn
(
99
))
*
time
.
Millisecond
)
c
:=
eventer
.
Register
(
"test"
)
// wait for the first event
<-
c
recv
<-
i
// keep receiving to prevent deadlock
for
{
select
{
case
<-
stop
:
return
case
<-
c
:
}
}
}
nlisteners
:=
200
go
poster
()
for
i
:=
0
;
i
<
nlisteners
;
i
++
{
go
listener
(
i
)
}
// wait until everyone has been served
for
i
:=
0
;
i
<
nlisteners
;
i
++
{
<-
recv
}
close
(
stop
)
}
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