Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
2507680d
Commit
2507680d
authored
Sep 26, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ok fixed queue test
parent
943c3df4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
7 deletions
+15
-7
peer/queue/queue_test.go
peer/queue/queue_test.go
+15
-7
No files found.
peer/queue/queue_test.go
View file @
2507680d
...
...
@@ -2,6 +2,7 @@ package queue
import
(
"fmt"
"sync"
"testing"
"time"
...
...
@@ -72,18 +73,21 @@ func newPeerTime(t time.Time) *peer.Peer {
}
func
TestSyncQueue
(
t
*
testing
.
T
)
{
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
4
)
ctx
:=
context
.
Background
(
)
pq
:=
NewXORDistancePQ
(
u
.
Key
(
"11140beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a31"
))
cq
:=
NewChanQueue
(
ctx
,
pq
)
wg
:=
sync
.
WaitGroup
{}
max
:=
10000
0
max
:=
10000
consumerN
:=
10
countsIn
:=
make
([]
int
,
consumerN
*
2
)
countsOut
:=
make
([]
int
,
consumerN
)
produce
:=
func
(
p
int
)
{
tick
:=
time
.
Tick
(
time
.
Millisecond
)
defer
wg
.
Done
()
tick
:=
time
.
Tick
(
time
.
Microsecond
*
100
)
for
i
:=
0
;
i
<
max
;
i
++
{
select
{
case
tim
:=
<-
tick
:
...
...
@@ -96,10 +100,15 @@ func TestSyncQueue(t *testing.T) {
}
consume
:=
func
(
c
int
)
{
defer
wg
.
Done
()
for
{
select
{
case
<-
cq
.
DeqChan
:
countsOut
[
c
]
++
if
countsOut
[
c
]
>=
max
*
2
{
return
}
case
<-
ctx
.
Done
()
:
return
}
...
...
@@ -108,14 +117,13 @@ func TestSyncQueue(t *testing.T) {
// make n * 2 producers and n consumers
for
i
:=
0
;
i
<
consumerN
;
i
++
{
wg
.
Add
(
3
)
go
produce
(
i
)
go
produce
(
consumerN
+
i
)
go
consume
(
i
)
}
select
{
case
<-
ctx
.
Done
()
:
}
wg
.
Wait
()
sum
:=
func
(
ns
[]
int
)
int
{
total
:=
0
...
...
@@ -126,6 +134,6 @@ func TestSyncQueue(t *testing.T) {
}
if
sum
(
countsIn
)
!=
sum
(
countsOut
)
{
t
.
Errorf
(
"didnt get all of them out: %d/%d"
,
countsOut
,
countsIn
)
t
.
Errorf
(
"didnt get all of them out: %d/%d"
,
sum
(
countsOut
)
,
sum
(
countsIn
)
)
}
}
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