Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
2e295b51
Commit
2e295b51
authored
Dec 09, 2015
by
Abiola Ibrahim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use channel instead for a synchronous interval.
parent
59dbea76
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
5 deletions
+13
-5
middleware/markdown/watcher_test.go
middleware/markdown/watcher_test.go
+13
-5
No files found.
middleware/markdown/watcher_test.go
View file @
2e295b51
...
...
@@ -13,14 +13,14 @@ func TestWatcher(t *testing.T) {
interval
:=
time
.
Millisecond
*
100
i
:=
0
out
:=
""
syncChan
:=
make
(
chan
struct
{})
stopChan
:=
TickerFunc
(
interval
,
func
()
{
i
++
out
+=
fmt
.
Sprint
(
i
)
syncChan
<-
struct
{}{}
})
// wait little more because of concurrency
time
.
Sleep
(
interval
*
12
)
stopChan
<-
struct
{}{}
if
!
strings
.
HasPrefix
(
out
,
expected
)
{
sleepInSync
(
8
,
syncChan
,
stopChan
)
if
out
!=
expected
{
t
.
Fatalf
(
"Expected to have prefix %v, found %v"
,
expected
,
out
)
}
out
=
""
...
...
@@ -31,8 +31,9 @@ func TestWatcher(t *testing.T) {
mu
.
Lock
()
out
+=
fmt
.
Sprint
(
i
)
mu
.
Unlock
()
syncChan
<-
struct
{}{}
})
time
.
Sleep
(
interval
*
15
)
sleepInSync
(
9
,
syncChan
,
stopChan
)
mu
.
Lock
()
res
:=
out
mu
.
Unlock
()
...
...
@@ -40,3 +41,10 @@ func TestWatcher(t *testing.T) {
t
.
Fatalf
(
"expected (%v) must be a proper prefix of out(%v)."
,
expected
,
out
)
}
}
func
sleepInSync
(
times
int
,
syncChan
chan
struct
{},
stopChan
chan
struct
{})
{
for
i
:=
0
;
i
<
times
;
i
++
{
<-
syncChan
}
stopChan
<-
struct
{}{}
}
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