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
08f136b8
Unverified
Commit
08f136b8
authored
Apr 16, 2016
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RateLimitedQueue TestTryOrdering could fail under load
Remove the possibility of contention in the test by providing a synthetic Now() function.
parent
c5df0bf2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
9 deletions
+42
-9
rate_limited_queue.go
pkg/controller/node/rate_limited_queue.go
+1
-1
rate_limited_queue_test.go
pkg/controller/node/rate_limited_queue_test.go
+41
-8
No files found.
pkg/controller/node/rate_limited_queue.go
View file @
08f136b8
...
@@ -164,7 +164,7 @@ func (q *RateLimitedTimedQueue) Try(fn ActionFunc) {
...
@@ -164,7 +164,7 @@ func (q *RateLimitedTimedQueue) Try(fn ActionFunc) {
for
ok
{
for
ok
{
// rate limit the queue checking
// rate limit the queue checking
if
!
q
.
limiter
.
TryAccept
()
{
if
!
q
.
limiter
.
TryAccept
()
{
glog
.
V
(
10
)
.
Info
(
"Try rate limit
t
ed..."
)
glog
.
V
(
10
)
.
Info
(
"Try rate limited..."
)
// Try again later
// Try again later
break
break
}
}
...
...
pkg/controller/node/rate_limited_queue_test.go
View file @
08f136b8
...
@@ -152,6 +152,19 @@ func TestTry(t *testing.T) {
...
@@ -152,6 +152,19 @@ func TestTry(t *testing.T) {
}
}
func
TestTryOrdering
(
t
*
testing
.
T
)
{
func
TestTryOrdering
(
t
*
testing
.
T
)
{
defer
func
()
{
now
=
time
.
Now
}()
current
:=
time
.
Unix
(
0
,
0
)
delay
:=
0
// the current time is incremented by 1ms every time now is invoked
now
=
func
()
time
.
Time
{
if
delay
>
0
{
delay
--
}
else
{
current
=
current
.
Add
(
time
.
Millisecond
)
}
t
.
Logf
(
"time %d"
,
current
.
UnixNano
())
return
current
}
evictor
:=
NewRateLimitedTimedQueue
(
flowcontrol
.
NewFakeAlwaysRateLimiter
())
evictor
:=
NewRateLimitedTimedQueue
(
flowcontrol
.
NewFakeAlwaysRateLimiter
())
evictor
.
Add
(
"first"
)
evictor
.
Add
(
"first"
)
evictor
.
Add
(
"second"
)
evictor
.
Add
(
"second"
)
...
@@ -159,18 +172,38 @@ func TestTryOrdering(t *testing.T) {
...
@@ -159,18 +172,38 @@ func TestTryOrdering(t *testing.T) {
order
:=
[]
string
{}
order
:=
[]
string
{}
count
:=
0
count
:=
0
q
ueued
:=
false
hasQ
ueued
:=
false
evictor
.
Try
(
func
(
value
TimedValue
)
(
bool
,
time
.
Duration
)
{
evictor
.
Try
(
func
(
value
TimedValue
)
(
bool
,
time
.
Duration
)
{
count
++
count
++
if
value
.
AddedAt
.
IsZero
()
{
t
.
Logf
(
"eviction %d"
,
count
)
t
.
Fatalf
(
"added should not be zero"
)
}
if
value
.
ProcessAt
.
IsZero
()
{
if
value
.
ProcessAt
.
IsZero
()
{
t
.
Fatalf
(
"
nex
t should not be zero"
)
t
.
Fatalf
(
"
processA
t should not be zero"
)
}
}
if
!
queued
&&
value
.
Value
==
"second"
{
switch
value
.
Value
{
queued
=
true
case
"first"
:
return
false
,
time
.
Millisecond
if
!
value
.
AddedAt
.
Equal
(
time
.
Unix
(
0
,
time
.
Millisecond
.
Nanoseconds
()))
{
t
.
Fatalf
(
"added time for %s is %d"
,
value
.
Value
,
value
.
AddedAt
)
}
case
"second"
:
if
!
value
.
AddedAt
.
Equal
(
time
.
Unix
(
0
,
2
*
time
.
Millisecond
.
Nanoseconds
()))
{
t
.
Fatalf
(
"added time for %s is %d"
,
value
.
Value
,
value
.
AddedAt
)
}
if
hasQueued
{
if
!
value
.
ProcessAt
.
Equal
(
time
.
Unix
(
0
,
6
*
time
.
Millisecond
.
Nanoseconds
()))
{
t
.
Fatalf
(
"process time for %s is %d"
,
value
.
Value
,
value
.
ProcessAt
)
}
break
}
hasQueued
=
true
delay
=
1
t
.
Logf
(
"going to delay"
)
return
false
,
2
*
time
.
Millisecond
case
"third"
:
if
!
value
.
AddedAt
.
Equal
(
time
.
Unix
(
0
,
3
*
time
.
Millisecond
.
Nanoseconds
()))
{
t
.
Fatalf
(
"added time for %s is %d"
,
value
.
Value
,
value
.
AddedAt
)
}
}
}
order
=
append
(
order
,
value
.
Value
)
order
=
append
(
order
,
value
.
Value
)
return
true
,
0
return
true
,
0
...
...
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