Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
8e270922
Commit
8e270922
authored
Jan 22, 2016
by
Jan Chaloupka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit test for JitterUntil
parent
3fa29098
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
wait_test.go
pkg/util/wait/wait_test.go
+59
-0
No files found.
pkg/util/wait/wait_test.go
View file @
8e270922
...
...
@@ -56,6 +56,65 @@ func TestUntilReturnsImmediately(t *testing.T) {
}
}
func
TestJitterUntil
(
t
*
testing
.
T
)
{
ch
:=
make
(
chan
struct
{})
// if a channel is closed JitterUntil never calls function f
// and returns imidiatelly
close
(
ch
)
JitterUntil
(
func
()
{
t
.
Fatal
(
"should not have been invoked"
)
},
0
,
1.0
,
ch
)
ch
=
make
(
chan
struct
{})
called
:=
make
(
chan
struct
{})
go
func
()
{
JitterUntil
(
func
()
{
called
<-
struct
{}{}
},
0
,
1.0
,
ch
)
close
(
called
)
}()
<-
called
close
(
ch
)
<-
called
}
func
TestJitterUntilReturnsImmediately
(
t
*
testing
.
T
)
{
now
:=
time
.
Now
()
ch
:=
make
(
chan
struct
{})
JitterUntil
(
func
()
{
close
(
ch
)
},
30
*
time
.
Second
,
1.0
,
ch
)
if
now
.
Add
(
25
*
time
.
Second
)
.
Before
(
time
.
Now
())
{
t
.
Errorf
(
"JitterUntil did not return immediately when the stop chan was closed inside the func"
)
}
}
func
TestJitterUntilNegativeFactor
(
t
*
testing
.
T
)
{
now
:=
time
.
Now
()
ch
:=
make
(
chan
struct
{})
called
:=
make
(
chan
struct
{})
received
:=
make
(
chan
struct
{})
go
func
()
{
JitterUntil
(
func
()
{
called
<-
struct
{}{}
<-
received
},
time
.
Second
,
-
30.0
,
ch
)
}()
// first loop
<-
called
received
<-
struct
{}{}
// second loop
<-
called
close
(
ch
)
received
<-
struct
{}{}
// it should take at most 2 seconds + some overhead, not 3
if
now
.
Add
(
3
*
time
.
Second
)
.
Before
(
time
.
Now
())
{
t
.
Errorf
(
"JitterUntil did not returned after predefined period with negative jitter factor when the stop chan was closed inside the func"
)
}
}
func
TestExponentialBackoff
(
t
*
testing
.
T
)
{
opts
:=
Backoff
{
Factor
:
1.0
,
Steps
:
3
}
...
...
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