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
05b60a30
Commit
05b60a30
authored
Dec 28, 2015
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix flakes in cacher_test
parent
25f5daa0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
4 deletions
+25
-4
cacher.go
pkg/storage/cacher.go
+6
-1
cacher_test.go
pkg/storage/cacher_test.go
+19
-3
No files found.
pkg/storage/cacher.go
View file @
05b60a30
...
@@ -293,7 +293,7 @@ func (c *Cacher) List(ctx context.Context, key string, resourceVersion string, f
...
@@ -293,7 +293,7 @@ func (c *Cacher) List(ctx context.Context, key string, resourceVersion string, f
return
err
return
err
}
}
// To avoid situation when List is proce
e
sed before the underlying
// To avoid situation when List is proce
s
sed before the underlying
// watchCache is propagated for the first time, we acquire and immediately
// watchCache is propagated for the first time, we acquire and immediately
// release the 'usable' lock.
// release the 'usable' lock.
// We don't need to hold it all the time, because watchCache is thread-safe
// We don't need to hold it all the time, because watchCache is thread-safe
...
@@ -399,6 +399,11 @@ func filterFunction(key string, keyFunc func(runtime.Object) (string, error), fi
...
@@ -399,6 +399,11 @@ func filterFunction(key string, keyFunc func(runtime.Object) (string, error), fi
// Returns resource version to which the underlying cache is synced.
// Returns resource version to which the underlying cache is synced.
func
(
c
*
Cacher
)
LastSyncResourceVersion
()
(
uint64
,
error
)
{
func
(
c
*
Cacher
)
LastSyncResourceVersion
()
(
uint64
,
error
)
{
// To avoid situation when LastSyncResourceVersion is processed before the
// underlying watchCache is propagated, we acquire 'usable' lock.
c
.
usable
.
RLock
()
defer
c
.
usable
.
RUnlock
()
c
.
RLock
()
c
.
RLock
()
defer
c
.
RUnlock
()
defer
c
.
RUnlock
()
...
...
pkg/storage/cacher_test.go
View file @
05b60a30
...
@@ -178,8 +178,16 @@ func TestWatch(t *testing.T) {
...
@@ -178,8 +178,16 @@ func TestWatch(t *testing.T) {
podFooBis
:=
makeTestPod
(
"foo"
)
podFooBis
:=
makeTestPod
(
"foo"
)
podFooBis
.
Spec
.
NodeName
=
"anotherFakeNode"
podFooBis
.
Spec
.
NodeName
=
"anotherFakeNode"
// initialVersion is used to initate the watcher at the beginning of the world,
// which is not defined precisely in etcd.
initialVersion
,
err
:=
cacher
.
LastSyncResourceVersion
()
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
startVersion
:=
strconv
.
Itoa
(
int
(
initialVersion
))
// Set up Watch for object "podFoo".
// Set up Watch for object "podFoo".
watcher
,
err
:=
cacher
.
Watch
(
context
.
TODO
(),
"pods/ns/foo"
,
"1"
,
storage
.
Everything
)
watcher
,
err
:=
cacher
.
Watch
(
context
.
TODO
(),
"pods/ns/foo"
,
startVersion
,
storage
.
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
@@ -227,15 +235,23 @@ func TestWatcherTimeout(t *testing.T) {
...
@@ -227,15 +235,23 @@ func TestWatcherTimeout(t *testing.T) {
cacher
:=
newTestCacher
(
etcdStorage
)
cacher
:=
newTestCacher
(
etcdStorage
)
defer
cacher
.
Stop
()
defer
cacher
.
Stop
()
// initialVersion is used to initate the watcher at the beginning of the world,
// which is not defined precisely in etcd.
initialVersion
,
err
:=
cacher
.
LastSyncResourceVersion
()
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
startVersion
:=
strconv
.
Itoa
(
int
(
initialVersion
))
// Create a watcher that will not be reading any result.
// Create a watcher that will not be reading any result.
watcher
,
err
:=
cacher
.
WatchList
(
context
.
TODO
(),
"pods/ns"
,
"1"
,
storage
.
Everything
)
watcher
,
err
:=
cacher
.
WatchList
(
context
.
TODO
(),
"pods/ns"
,
startVersion
,
storage
.
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
defer
watcher
.
Stop
()
defer
watcher
.
Stop
()
// Create a second watcher that will be reading result.
// Create a second watcher that will be reading result.
readingWatcher
,
err
:=
cacher
.
WatchList
(
context
.
TODO
(),
"pods/ns"
,
"1"
,
storage
.
Everything
)
readingWatcher
,
err
:=
cacher
.
WatchList
(
context
.
TODO
(),
"pods/ns"
,
startVersion
,
storage
.
Everything
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
...
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