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
8752165f
Commit
8752165f
authored
Nov 30, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16853 from jayunit100/backoffresets
Auto commit by PR queue bot
parents
0d7d8793
7ffaef63
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
11 deletions
+50
-11
backoff.go
pkg/util/backoff.go
+7
-0
backoff_test.go
pkg/util/backoff_test.go
+8
-0
rand.go
pkg/util/rand/rand.go
+14
-11
rand_test.go
pkg/util/rand/rand_test.go
+21
-0
No files found.
pkg/util/backoff.go
View file @
8752165f
...
...
@@ -70,6 +70,13 @@ func (p *Backoff) Next(id string, eventTime time.Time) {
entry
.
lastUpdate
=
p
.
Clock
.
Now
()
}
// Reset forces clearing of all backoff data for a given key.
func
(
p
*
Backoff
)
Reset
(
id
string
)
{
p
.
Lock
()
defer
p
.
Unlock
()
delete
(
p
.
perItemBackoff
,
id
)
}
// Returns True if the elapsed time since eventTime is smaller than the current backoff window
func
(
p
*
Backoff
)
IsInBackOffSince
(
id
string
,
eventTime
time
.
Time
)
bool
{
p
.
Lock
()
...
...
pkg/util/backoff_test.go
View file @
8752165f
...
...
@@ -46,6 +46,14 @@ func TestSlowBackoff(t *testing.T) {
}
b
.
Next
(
id
,
tc
.
Now
())
}
//Now confirm that the Reset cancels backoff.
b
.
Next
(
id
,
tc
.
Now
())
b
.
Reset
(
id
)
if
b
.
Get
(
id
)
!=
0
{
t
.
Errorf
(
"Reset didn't clear the backoff."
)
}
}
func
TestBackoffReset
(
t
*
testing
.
T
)
{
...
...
pkg/util/rand/rand.go
View file @
8752165f
...
...
@@ -32,19 +32,12 @@ var rng = struct {
rand
:
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UTC
()
.
UnixNano
())),
}
// String generates a random alphanumeric string n characters long. This will
// panic if n is less than zero.
func
String
(
n
int
)
string
{
if
n
<
0
{
panic
(
"out-of-bounds value"
)
}
b
:=
make
([]
rune
,
n
)
// Intn generates an integer in range 0->max.
// By design this should panic if input is invalid, <= 0.
func
Intn
(
max
int
)
int
{
rng
.
Lock
()
defer
rng
.
Unlock
()
for
i
:=
range
b
{
b
[
i
]
=
letters
[
rng
.
rand
.
Intn
(
numLetters
)]
}
return
string
(
b
)
return
rng
.
rand
.
Intn
(
max
)
}
// Seed seeds the rng with the provided seed.
...
...
@@ -62,3 +55,13 @@ func Perm(n int) []int {
defer
rng
.
Unlock
()
return
rng
.
rand
.
Perm
(
n
)
}
// String generates a random alphanumeric string n characters long. This will
// panic if n is less than zero.
func
String
(
length
int
)
string
{
b
:=
make
([]
rune
,
length
)
for
i
:=
range
b
{
b
[
i
]
=
letters
[
Intn
(
numLetters
)]
}
return
string
(
b
)
}
pkg/util/rand/rand_test.go
View file @
8752165f
...
...
@@ -37,6 +37,27 @@ func TestString(t *testing.T) {
}
}
// Confirm that panic occurs on invalid input.
func
TestRangePanic
(
t
*
testing
.
T
)
{
defer
func
()
{
if
err
:=
recover
();
err
==
nil
{
t
.
Errorf
(
"Panic didn't occur!"
)
}
}()
// Should result in an error...
Intn
(
0
)
}
func
TestIntn
(
t
*
testing
.
T
)
{
// 0 is invalid.
for
_
,
max
:=
range
[]
int
{
1
,
2
,
10
,
123
}
{
inrange
:=
Intn
(
max
)
if
inrange
<
0
||
inrange
>
max
{
t
.
Errorf
(
"%v out of range (0,%v)"
,
inrange
,
max
)
}
}
}
func
TestPerm
(
t
*
testing
.
T
)
{
Seed
(
5
)
rand
.
Seed
(
5
)
...
...
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