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
8ed04cfe
Commit
8ed04cfe
authored
Sep 19, 2014
by
Juan Batiz-Benet
Committed by
Brian Tiger Chow
Sep 22, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed test
parent
315e121e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
13 deletions
+24
-13
peer/queue/queue_test.go
peer/queue/queue_test.go
+24
-13
No files found.
peer/queue/queue_test.go
View file @
8ed04cfe
...
@@ -76,15 +76,18 @@ func TestSyncQueue(t *testing.T) {
...
@@ -76,15 +76,18 @@ func TestSyncQueue(t *testing.T) {
pq
:=
NewXORDistancePQ
(
u
.
Key
(
"11140beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a31"
))
pq
:=
NewXORDistancePQ
(
u
.
Key
(
"11140beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a31"
))
cq
:=
NewChanQueue
(
ctx
,
pq
)
cq
:=
NewChanQueue
(
ctx
,
pq
)
countIn
:=
0
countOut
:=
0
produce
:=
func
()
{
max
:=
100000
consumerN
:=
10
countsIn
:=
make
([]
int
,
consumerN
*
2
)
countsOut
:=
make
([]
int
,
consumerN
)
produce
:=
func
(
p
int
)
{
tick
:=
time
.
Tick
(
time
.
Millisecond
)
tick
:=
time
.
Tick
(
time
.
Millisecond
)
for
{
for
i
:=
0
;
i
<
max
;
i
++
{
select
{
select
{
case
tim
:=
<-
tick
:
case
tim
:=
<-
tick
:
countIn
++
count
s
In
[
p
]
++
cq
.
EnqChan
<-
newPeerTime
(
tim
)
cq
.
EnqChan
<-
newPeerTime
(
tim
)
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
return
return
...
@@ -92,29 +95,37 @@ func TestSyncQueue(t *testing.T) {
...
@@ -92,29 +95,37 @@ func TestSyncQueue(t *testing.T) {
}
}
}
}
consume
:=
func
()
{
consume
:=
func
(
c
int
)
{
for
{
for
{
select
{
select
{
case
<-
cq
.
DeqChan
:
case
<-
cq
.
DeqChan
:
countOut
++
count
s
Out
[
c
]
++
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
return
return
}
}
}
}
}
}
for
i
:=
0
;
i
<
10
;
i
++
{
// make n * 2 producers and n consumers
go
produce
()
for
i
:=
0
;
i
<
consumerN
;
i
++
{
go
produce
()
go
produce
(
i
)
go
consume
()
go
produce
(
consumerN
+
i
)
go
consume
(
i
)
}
}
select
{
select
{
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
}
}
if
countIn
!=
countOut
{
sum
:=
func
(
ns
[]
int
)
int
{
t
.
Errorf
(
"didnt get them all out: %d/%d"
,
countOut
,
countIn
)
total
:=
0
for
_
,
n
:=
range
ns
{
total
+=
n
}
return
total
}
}
if
sum
(
countsIn
)
!=
sum
(
countsOut
)
{
t
.
Errorf
(
"didnt get all of them out: %d/%d"
,
countsOut
,
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