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
3540846f
Commit
3540846f
authored
Nov 10, 2016
by
Marcin Wielgus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure proper serialization of updates and creates in federation test watcher
parent
abd653bd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
test_helper.go
...ration/pkg/federation-controller/util/test/test_helper.go
+19
-4
No files found.
federation/pkg/federation-controller/util/test/test_helper.go
View file @
3540846f
...
@@ -41,6 +41,8 @@ type WatcherDispatcher struct {
...
@@ -41,6 +41,8 @@ type WatcherDispatcher struct {
sync
.
Mutex
sync
.
Mutex
watchers
[]
*
watch
.
RaceFreeFakeWatcher
watchers
[]
*
watch
.
RaceFreeFakeWatcher
eventsSoFar
[]
*
watch
.
Event
eventsSoFar
[]
*
watch
.
Event
orderExecution
chan
func
()
stopChan
chan
struct
{}
}
}
func
(
wd
*
WatcherDispatcher
)
register
(
watcher
*
watch
.
RaceFreeFakeWatcher
)
{
func
(
wd
*
WatcherDispatcher
)
register
(
watcher
*
watch
.
RaceFreeFakeWatcher
)
{
...
@@ -55,6 +57,7 @@ func (wd *WatcherDispatcher) register(watcher *watch.RaceFreeFakeWatcher) {
...
@@ -55,6 +57,7 @@ func (wd *WatcherDispatcher) register(watcher *watch.RaceFreeFakeWatcher) {
func
(
wd
*
WatcherDispatcher
)
Stop
()
{
func
(
wd
*
WatcherDispatcher
)
Stop
()
{
wd
.
Lock
()
wd
.
Lock
()
defer
wd
.
Unlock
()
defer
wd
.
Unlock
()
close
(
wd
.
stopChan
)
for
_
,
watcher
:=
range
wd
.
watchers
{
for
_
,
watcher
:=
range
wd
.
watchers
{
watcher
.
Stop
()
watcher
.
Stop
()
}
}
...
@@ -138,7 +141,19 @@ func RegisterFakeWatch(resource string, client *core.Fake) *WatcherDispatcher {
...
@@ -138,7 +141,19 @@ func RegisterFakeWatch(resource string, client *core.Fake) *WatcherDispatcher {
dispatcher
:=
&
WatcherDispatcher
{
dispatcher
:=
&
WatcherDispatcher
{
watchers
:
make
([]
*
watch
.
RaceFreeFakeWatcher
,
0
),
watchers
:
make
([]
*
watch
.
RaceFreeFakeWatcher
,
0
),
eventsSoFar
:
make
([]
*
watch
.
Event
,
0
),
eventsSoFar
:
make
([]
*
watch
.
Event
,
0
),
orderExecution
:
make
(
chan
func
()),
stopChan
:
make
(
chan
struct
{}),
}
}
go
func
()
{
for
{
select
{
case
fun
:=
<-
dispatcher
.
orderExecution
:
fun
()
case
<-
dispatcher
.
stopChan
:
return
}
}
}()
client
.
AddWatchReactor
(
resource
,
func
(
action
core
.
Action
)
(
bool
,
watch
.
Interface
,
error
)
{
client
.
AddWatchReactor
(
resource
,
func
(
action
core
.
Action
)
(
bool
,
watch
.
Interface
,
error
)
{
watcher
:=
watch
.
NewRaceFreeFake
()
watcher
:=
watch
.
NewRaceFreeFake
()
...
@@ -166,11 +181,11 @@ func RegisterFakeCopyOnCreate(resource string, client *core.Fake, watcher *Watch
...
@@ -166,11 +181,11 @@ func RegisterFakeCopyOnCreate(resource string, client *core.Fake, watcher *Watch
originalObj
:=
createAction
.
GetObject
()
originalObj
:=
createAction
.
GetObject
()
// Create a copy of the object here to prevent data races while reading the object in go routine.
// Create a copy of the object here to prevent data races while reading the object in go routine.
obj
:=
copy
(
originalObj
)
obj
:=
copy
(
originalObj
)
go
func
()
{
watcher
.
orderExecution
<-
func
()
{
glog
.
V
(
4
)
.
Infof
(
"Object created. Writing to channel: %v"
,
obj
)
glog
.
V
(
4
)
.
Infof
(
"Object created. Writing to channel: %v"
,
obj
)
watcher
.
Add
(
obj
)
watcher
.
Add
(
obj
)
objChan
<-
obj
objChan
<-
obj
}
()
}
return
true
,
originalObj
,
nil
return
true
,
originalObj
,
nil
})
})
return
objChan
return
objChan
...
@@ -186,11 +201,11 @@ func RegisterFakeCopyOnUpdate(resource string, client *core.Fake, watcher *Watch
...
@@ -186,11 +201,11 @@ func RegisterFakeCopyOnUpdate(resource string, client *core.Fake, watcher *Watch
originalObj
:=
updateAction
.
GetObject
()
originalObj
:=
updateAction
.
GetObject
()
// Create a copy of the object here to prevent data races while reading the object in go routine.
// Create a copy of the object here to prevent data races while reading the object in go routine.
obj
:=
copy
(
originalObj
)
obj
:=
copy
(
originalObj
)
go
func
()
{
watcher
.
orderExecution
<-
func
()
{
glog
.
V
(
4
)
.
Infof
(
"Object updated. Writing to channel: %v"
,
obj
)
glog
.
V
(
4
)
.
Infof
(
"Object updated. Writing to channel: %v"
,
obj
)
watcher
.
Modify
(
obj
)
watcher
.
Modify
(
obj
)
objChan
<-
obj
objChan
<-
obj
}
()
}
return
true
,
originalObj
,
nil
return
true
,
originalObj
,
nil
})
})
return
objChan
return
objChan
...
...
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