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
1ec6b02e
Commit
1ec6b02e
authored
Apr 13, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix tests flaky due to timeouts
parent
a0fa592b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
21 deletions
+22
-21
controller_test.go
pkg/controller/framework/controller_test.go
+22
-21
No files found.
pkg/controller/framework/controller_test.go
View file @
1ec6b02e
...
@@ -45,8 +45,7 @@ func Example() {
...
@@ -45,8 +45,7 @@ func Example() {
fifo
:=
cache
.
NewDeltaFIFO
(
cache
.
MetaNamespaceKeyFunc
,
nil
,
downstream
)
fifo
:=
cache
.
NewDeltaFIFO
(
cache
.
MetaNamespaceKeyFunc
,
nil
,
downstream
)
// Let's do threadsafe output to get predictable test results.
// Let's do threadsafe output to get predictable test results.
outputSetLock
:=
sync
.
Mutex
{}
deletionCounter
:=
make
(
chan
string
,
1000
)
outputSet
:=
util
.
StringSet
{}
cfg
:=
&
framework
.
Config
{
cfg
:=
&
framework
.
Config
{
Queue
:
fifo
,
Queue
:
fifo
,
...
@@ -68,6 +67,7 @@ func Example() {
...
@@ -68,6 +67,7 @@ func Example() {
return
err
return
err
}
}
// Delete this object.
source
.
Delete
(
newest
.
Object
.
(
runtime
.
Object
))
source
.
Delete
(
newest
.
Object
.
(
runtime
.
Object
))
}
else
{
}
else
{
// Update our downstream store.
// Update our downstream store.
...
@@ -83,10 +83,8 @@ func Example() {
...
@@ -83,10 +83,8 @@ func Example() {
return
err
return
err
}
}
// Record some output.
// Report this deletion.
outputSetLock
.
Lock
()
deletionCounter
<-
key
defer
outputSetLock
.
Unlock
()
outputSet
.
Insert
(
key
)
}
}
return
nil
return
nil
},
},
...
@@ -94,20 +92,23 @@ func Example() {
...
@@ -94,20 +92,23 @@ func Example() {
// Create the controller and run it until we close stop.
// Create the controller and run it until we close stop.
stop
:=
make
(
chan
struct
{})
stop
:=
make
(
chan
struct
{})
defer
close
(
stop
)
go
framework
.
New
(
cfg
)
.
Run
(
stop
)
go
framework
.
New
(
cfg
)
.
Run
(
stop
)
// Let's add a few objects to the source.
// Let's add a few objects to the source.
for
_
,
name
:=
range
[]
string
{
"a-hello"
,
"b-controller"
,
"c-framework"
}
{
testIDs
:=
[]
string
{
"a-hello"
,
"b-controller"
,
"c-framework"
}
for
_
,
name
:=
range
testIDs
{
// Note that these pods are not valid-- the fake source doesn't
// Note that these pods are not valid-- the fake source doesn't
// call validation or anything.
// call validation or anything.
source
.
Add
(
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
}})
source
.
Add
(
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
}})
}
}
// Let's wait for the controller to process the things we just added.
// Let's wait for the controller to process the things we just added.
time
.
Sleep
(
500
*
time
.
Millisecond
)
outputSet
:=
util
.
StringSet
{}
close
(
stop
)
for
i
:=
0
;
i
<
len
(
testIDs
);
i
++
{
outputSet
.
Insert
(
<-
deletionCounter
)
}
outputSetLock
.
Lock
()
for
_
,
key
:=
range
outputSet
.
List
()
{
for
_
,
key
:=
range
outputSet
.
List
()
{
fmt
.
Println
(
key
)
fmt
.
Println
(
key
)
}
}
...
@@ -122,8 +123,7 @@ func ExampleInformer() {
...
@@ -122,8 +123,7 @@ func ExampleInformer() {
source
:=
framework
.
NewFakeControllerSource
()
source
:=
framework
.
NewFakeControllerSource
()
// Let's do threadsafe output to get predictable test results.
// Let's do threadsafe output to get predictable test results.
outputSetLock
:=
sync
.
Mutex
{}
deletionCounter
:=
make
(
chan
string
,
1000
)
outputSet
:=
util
.
StringSet
{}
// Make a controller that immediately deletes anything added to it, and
// Make a controller that immediately deletes anything added to it, and
// logs anything deleted.
// logs anything deleted.
...
@@ -141,30 +141,31 @@ func ExampleInformer() {
...
@@ -141,30 +141,31 @@ func ExampleInformer() {
key
=
"oops something went wrong with the key"
key
=
"oops something went wrong with the key"
}
}
// Record some output when items are deleted.
// Report this deletion.
outputSetLock
.
Lock
()
deletionCounter
<-
key
defer
outputSetLock
.
Unlock
()
outputSet
.
Insert
(
key
)
},
},
},
},
)
)
// Run the controller and run it until we close stop.
// Run the controller and run it until we close stop.
stop
:=
make
(
chan
struct
{})
stop
:=
make
(
chan
struct
{})
defer
close
(
stop
)
go
controller
.
Run
(
stop
)
go
controller
.
Run
(
stop
)
// Let's add a few objects to the source.
// Let's add a few objects to the source.
for
_
,
name
:=
range
[]
string
{
"a-hello"
,
"b-controller"
,
"c-framework"
}
{
testIDs
:=
[]
string
{
"a-hello"
,
"b-controller"
,
"c-framework"
}
for
_
,
name
:=
range
testIDs
{
// Note that these pods are not valid-- the fake source doesn't
// Note that these pods are not valid-- the fake source doesn't
// call validation or
perform any other check
ing.
// call validation or
anyth
ing.
source
.
Add
(
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
}})
source
.
Add
(
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
}})
}
}
// Let's wait for the controller to process the things we just added.
// Let's wait for the controller to process the things we just added.
time
.
Sleep
(
500
*
time
.
Millisecond
)
outputSet
:=
util
.
StringSet
{}
close
(
stop
)
for
i
:=
0
;
i
<
len
(
testIDs
);
i
++
{
outputSet
.
Insert
(
<-
deletionCounter
)
}
outputSetLock
.
Lock
()
for
_
,
key
:=
range
outputSet
.
List
()
{
for
_
,
key
:=
range
outputSet
.
List
()
{
fmt
.
Println
(
key
)
fmt
.
Println
(
key
)
}
}
...
...
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