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-dms3-provider
Commits
596dc499
Commit
596dc499
authored
Apr 06, 2020
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: handle closed queue
When the queue closes, return instead of providing empty CIDs.
parent
3a98ef95
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
simple/provider.go
simple/provider.go
+6
-1
simple/provider_test.go
simple/provider_test.go
+31
-0
No files found.
simple/provider.go
View file @
596dc499
...
...
@@ -85,7 +85,12 @@ func (p *Provider) handleAnnouncements() {
select
{
case
<-
p
.
ctx
.
Done
()
:
return
case
c
:=
<-
p
.
queue
.
Dequeue
()
:
case
c
,
ok
:=
<-
p
.
queue
.
Dequeue
()
:
if
!
ok
{
// queue closed.
return
}
p
.
doProvide
(
c
)
}
}
...
...
simple/provider_test.go
View file @
596dc499
...
...
@@ -84,6 +84,37 @@ func TestAnnouncement(t *testing.T) {
t
.
Fatal
(
"Timeout waiting for cids to be provided."
)
}
}
prov
.
Close
()
select
{
case
cp
:=
<-
r
.
provided
:
t
.
Fatal
(
"did not expect to provide CID: "
,
cp
)
case
<-
time
.
After
(
time
.
Second
*
1
)
:
}
}
func
TestClose
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
defer
ctx
.
Done
()
ds
:=
sync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
queue
,
err
:=
q
.
NewQueue
(
ctx
,
"test"
,
ds
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
r
:=
mockContentRouting
()
prov
:=
NewProvider
(
ctx
,
queue
,
r
)
prov
.
Run
()
prov
.
Close
()
select
{
case
cp
:=
<-
r
.
provided
:
t
.
Fatal
(
"did not expect to provide anything, provided: "
,
cp
)
case
<-
time
.
After
(
time
.
Second
*
1
)
:
}
}
func
TestAnnouncementTimeout
(
t
*
testing
.
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