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
8bf0adf1
Commit
8bf0adf1
authored
May 06, 2015
by
Prashanth Balasubramanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a getter to pod expectations and use it in unittests
parent
fccfa5ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
9 deletions
+19
-9
controller_utils.go
pkg/controller/controller_utils.go
+5
-3
replication_controller_test.go
pkg/controller/replication_controller_test.go
+14
-6
No files found.
pkg/controller/controller_utils.go
View file @
8bf0adf1
...
...
@@ -124,9 +124,6 @@ func (r *RCExpectations) ExpectDeletions(rc *api.ReplicationController, dels int
// Decrements the expectation counts of the given rc.
func
(
r
*
RCExpectations
)
lowerExpectations
(
rc
*
api
.
ReplicationController
,
add
,
del
int
)
{
if
podExp
,
exists
,
err
:=
r
.
GetExpectations
(
rc
);
err
==
nil
&&
exists
{
if
podExp
.
add
>
0
&&
podExp
.
del
>
0
{
glog
.
V
(
2
)
.
Infof
(
"Controller has both add and del expectations %+v"
,
podExp
)
}
podExp
.
Seen
(
int64
(
add
),
int64
(
del
))
// The expectations might've been modified since the update on the previous line.
glog
.
V
(
4
)
.
Infof
(
"Lowering expectations %+v"
,
podExp
)
...
...
@@ -167,6 +164,11 @@ func (e *PodExpectations) Fulfilled() bool {
return
atomic
.
LoadInt64
(
&
e
.
add
)
<=
0
&&
atomic
.
LoadInt64
(
&
e
.
del
)
<=
0
}
// getExpectations returns the add and del expectations of the pod.
func
(
e
*
PodExpectations
)
getExpectations
()
(
int64
,
int64
)
{
return
atomic
.
LoadInt64
(
&
e
.
add
),
atomic
.
LoadInt64
(
&
e
.
del
)
}
// NewRCExpectations returns a store for PodExpectations.
func
NewRCExpectations
()
*
RCExpectations
{
return
&
RCExpectations
{
cache
.
NewTTLStore
(
expKeyFunc
,
ExpectationsTimeout
)}
...
...
pkg/controller/replication_controller_test.go
View file @
8bf0adf1
...
...
@@ -48,6 +48,12 @@ type FakePodControl struct {
err
error
}
// Give each test that starts a background controller upto 1/2 a second.
// Since we need to start up a goroutine to test watch, this routine needs
// to get cpu before the test can complete. If the test is starved of cpu,
// the watch test will take upto 1/2 a second before timing out.
const
controllerTimeout
=
500
*
time
.
Millisecond
func
init
()
{
api
.
ForTesting_ReferencesAllowBlankSelfLinks
=
true
}
...
...
@@ -487,7 +493,8 @@ func TestRCExpectations(t *testing.T) {
// Expectations have been surpassed
if
podExp
,
exists
,
err
:=
e
.
GetExpectations
(
rc
);
err
==
nil
&&
exists
{
if
podExp
.
add
!=
-
1
||
podExp
.
del
!=
-
1
{
add
,
del
:=
podExp
.
getExpectations
()
if
add
!=
-
1
||
del
!=
-
1
{
t
.
Errorf
(
"Unexpected pod expectations %#v"
,
podExp
)
}
}
else
{
...
...
@@ -500,7 +507,8 @@ func TestRCExpectations(t *testing.T) {
// Next round of rc sync, old expectations are cleared
e
.
setExpectations
(
rc
,
1
,
2
)
if
podExp
,
exists
,
err
:=
e
.
GetExpectations
(
rc
);
err
==
nil
&&
exists
{
if
podExp
.
add
!=
1
||
podExp
.
del
!=
2
{
add
,
del
:=
podExp
.
getExpectations
()
if
add
!=
1
||
del
!=
2
{
t
.
Errorf
(
"Unexpected pod expectations %#v"
,
podExp
)
}
}
else
{
...
...
@@ -663,7 +671,7 @@ func TestWatchControllers(t *testing.T) {
select
{
case
<-
received
:
case
<-
time
.
After
(
100
*
time
.
Millisecond
)
:
case
<-
time
.
After
(
controllerTimeout
)
:
t
.
Errorf
(
"Expected 1 call but got 0"
)
}
}
...
...
@@ -706,7 +714,7 @@ func TestWatchPods(t *testing.T) {
select
{
case
<-
received
:
case
<-
time
.
After
(
100
*
time
.
Millisecond
)
:
case
<-
time
.
After
(
controllerTimeout
)
:
t
.
Errorf
(
"Expected 1 call but got 0"
)
}
}
...
...
@@ -756,7 +764,7 @@ func TestUpdatePods(t *testing.T) {
if
!
expected
.
Has
(
got
)
{
t
.
Errorf
(
"Expected keys %#v got %v"
,
expected
,
got
)
}
case
<-
time
.
After
(
100
*
time
.
Millisecond
)
:
case
<-
time
.
After
(
controllerTimeout
)
:
t
.
Errorf
(
"Expected update notifications for controllers within 100ms each"
)
}
}
...
...
@@ -795,7 +803,7 @@ func TestControllerUpdateRequeue(t *testing.T) {
if
key
!=
expectedKey
{
t
.
Errorf
(
"Expected requeue of controller with key %s got %s"
,
expectedKey
,
key
)
}
case
<-
time
.
After
(
100
*
time
.
Millisecond
)
:
case
<-
time
.
After
(
controllerTimeout
)
:
manager
.
queue
.
ShutDown
()
t
.
Errorf
(
"Expected to find an rc in the queue, found none."
)
}
...
...
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