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
3372aef1
Commit
3372aef1
authored
Oct 11, 2016
by
Marcin Wielgus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Checking function integrated with get from chanel in fed tests
parent
e72f26a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
19 deletions
+64
-19
deploymentcontroller_test.go
...ration-controller/deployment/deploymentcontroller_test.go
+19
-19
test_helper.go
...ration/pkg/federation-controller/util/test/test_helper.go
+45
-0
No files found.
federation/pkg/federation-controller/deployment/deploymentcontroller_test.go
View file @
3372aef1
...
@@ -119,34 +119,34 @@ func TestDeploymentController(t *testing.T) {
...
@@ -119,34 +119,34 @@ func TestDeploymentController(t *testing.T) {
// Create deployment. Expect to see it in cluster1.
// Create deployment. Expect to see it in cluster1.
dep1
:=
newDeploymentWithReplicas
(
"depA"
,
6
)
dep1
:=
newDeploymentWithReplicas
(
"depA"
,
6
)
deploymentsWatch
.
Add
(
dep1
)
deploymentsWatch
.
Add
(
dep1
)
createdDep1
:=
GetDeploymentFromChan
(
cluster1CreateChan
)
checkDeployment
:=
func
(
base
*
extensionsv1
.
Deployment
,
replicas
int32
)
CheckingFunction
{
assert
.
NotNil
(
t
,
createdDep1
)
return
func
(
obj
runtime
.
Object
)
error
{
assert
.
Equal
(
t
,
dep1
.
Namespace
,
createdDep1
.
Namespace
)
if
obj
==
nil
{
assert
.
Equal
(
t
,
dep1
.
Name
,
createdDep1
.
Name
)
return
fmt
.
Errorf
(
"Observed object is nil"
)
assert
.
Equal
(
t
,
dep1
.
Spec
.
Replicas
,
createdDep1
.
Spec
.
Replicas
)
}
d
:=
obj
.
(
*
extensionsv1
.
Deployment
)
if
err
:=
CompareObjectMeta
(
base
.
ObjectMeta
,
d
.
ObjectMeta
);
err
!=
nil
{
return
err
}
if
replicas
!=
*
d
.
Spec
.
Replicas
{
return
fmt
.
Errorf
(
"Replica count is different expected:%d observed:%d"
,
replicas
,
*
d
.
Spec
.
Replicas
)
}
return
nil
}
}
assert
.
NoError
(
t
,
CheckObjectFromChan
(
cluster1CreateChan
,
checkDeployment
(
dep1
,
*
dep1
.
Spec
.
Replicas
)))
// Increase replica count. Expect to see the update in cluster1.
// Increase replica count. Expect to see the update in cluster1.
newRep
:=
int32
(
8
)
newRep
:=
int32
(
8
)
dep1
.
Spec
.
Replicas
=
&
newRep
dep1
.
Spec
.
Replicas
=
&
newRep
deploymentsWatch
.
Modify
(
dep1
)
deploymentsWatch
.
Modify
(
dep1
)
updatedDep1
:=
GetDeploymentFromChan
(
cluster1UpdateChan
)
assert
.
NoError
(
t
,
CheckObjectFromChan
(
cluster1UpdateChan
,
checkDeployment
(
dep1
,
*
dep1
.
Spec
.
Replicas
)))
assert
.
NotNil
(
t
,
updatedDep1
)
assert
.
Equal
(
t
,
dep1
.
Namespace
,
updatedDep1
.
Namespace
)
assert
.
Equal
(
t
,
dep1
.
Name
,
updatedDep1
.
Name
)
assert
.
Equal
(
t
,
dep1
.
Spec
.
Replicas
,
updatedDep1
.
Spec
.
Replicas
)
// Add new cluster. Although rebalance = false, no pods have been created yet so it should
// Add new cluster. Although rebalance = false, no pods have been created yet so it should
// rebalance anyway.
// rebalance anyway.
clusterWatch
.
Add
(
cluster2
)
clusterWatch
.
Add
(
cluster2
)
updatedDep1
=
GetDeploymentFromChan
(
cluster1UpdateChan
)
assert
.
NoError
(
t
,
CheckObjectFromChan
(
cluster1UpdateChan
,
checkDeployment
(
dep1
,
*
dep1
.
Spec
.
Replicas
/
2
)))
createdDep2
:=
GetDeploymentFromChan
(
cluster2CreateChan
)
assert
.
NoError
(
t
,
CheckObjectFromChan
(
cluster2CreateChan
,
checkDeployment
(
dep1
,
*
dep1
.
Spec
.
Replicas
/
2
)))
assert
.
NotNil
(
t
,
updatedDep1
)
assert
.
NotNil
(
t
,
createdDep2
)
assert
.
Equal
(
t
,
dep1
.
Namespace
,
createdDep2
.
Namespace
)
assert
.
Equal
(
t
,
dep1
.
Name
,
createdDep2
.
Name
)
assert
.
Equal
(
t
,
*
dep1
.
Spec
.
Replicas
/
2
,
*
createdDep2
.
Spec
.
Replicas
)
assert
.
Equal
(
t
,
*
dep1
.
Spec
.
Replicas
/
2
,
*
updatedDep1
.
Spec
.
Replicas
)
}
}
func
GetDeploymentFromChan
(
c
chan
runtime
.
Object
)
*
extensionsv1
.
Deployment
{
func
GetDeploymentFromChan
(
c
chan
runtime
.
Object
)
*
extensionsv1
.
Deployment
{
...
...
federation/pkg/federation-controller/util/test/test_helper.go
View file @
3372aef1
...
@@ -17,7 +17,9 @@ limitations under the License.
...
@@ -17,7 +17,9 @@ limitations under the License.
package
testutil
package
testutil
import
(
import
(
"fmt"
"os"
"os"
"reflect"
"runtime/pprof"
"runtime/pprof"
"sync"
"sync"
"time"
"time"
...
@@ -201,6 +203,49 @@ func GetObjectFromChan(c chan runtime.Object) runtime.Object {
...
@@ -201,6 +203,49 @@ func GetObjectFromChan(c chan runtime.Object) runtime.Object {
}
}
}
}
type
CheckingFunction
func
(
runtime
.
Object
)
error
// CheckObjectFromChan tries to get an object matching the given check function
// within a reasonable time.
func
CheckObjectFromChan
(
c
chan
runtime
.
Object
,
checkFunction
CheckingFunction
)
error
{
delay
:=
20
*
time
.
Second
var
lastError
error
for
{
select
{
case
obj
:=
<-
c
:
if
lastError
=
checkFunction
(
obj
);
lastError
==
nil
{
return
nil
}
glog
.
Infof
(
"Check function failed with %v"
,
lastError
)
delay
=
5
*
time
.
Second
case
<-
time
.
After
(
delay
)
:
pprof
.
Lookup
(
"goroutine"
)
.
WriteTo
(
os
.
Stderr
,
1
)
if
lastError
==
nil
{
return
fmt
.
Errorf
(
"Failed to get an object from channel"
)
}
else
{
return
lastError
}
}
}
}
// CompareObjectMeta returns an error when the given objects are not equivalent.
func
CompareObjectMeta
(
a
,
b
api_v1
.
ObjectMeta
)
error
{
if
a
.
Namespace
!=
b
.
Namespace
{
return
fmt
.
Errorf
(
"Different namespace expected:%s observed:%s"
,
a
.
Namespace
,
b
.
Namespace
)
}
if
a
.
Name
!=
b
.
Name
{
return
fmt
.
Errorf
(
"Different name expected:%s observed:%s"
,
a
.
Namespace
,
b
.
Namespace
)
}
if
!
reflect
.
DeepEqual
(
a
.
Annotations
,
b
.
Annotations
)
{
return
fmt
.
Errorf
(
"Annotations are different expected:%v observerd:%v"
,
a
.
Annotations
,
b
.
Annotations
)
}
if
!
reflect
.
DeepEqual
(
a
.
Labels
,
b
.
Labels
)
{
return
fmt
.
Errorf
(
"Annotations are different expected:%v observerd:%v"
,
a
.
Labels
,
b
.
Labels
)
}
return
nil
}
func
ToFederatedInformerForTestOnly
(
informer
util
.
FederatedInformer
)
util
.
FederatedInformerForTestOnly
{
func
ToFederatedInformerForTestOnly
(
informer
util
.
FederatedInformer
)
util
.
FederatedInformerForTestOnly
{
inter
:=
informer
.
(
interface
{})
inter
:=
informer
.
(
interface
{})
return
inter
.
(
util
.
FederatedInformerForTestOnly
)
return
inter
.
(
util
.
FederatedInformerForTestOnly
)
...
...
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