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
cd3f7f41
Commit
cd3f7f41
authored
May 10, 2016
by
Hongchao Deng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
etcd3/watcher: refactor test
parent
da7e9783
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
8 deletions
+27
-8
store_test.go
pkg/storage/etcd3/store_test.go
+2
-2
watcher_test.go
pkg/storage/etcd3/watcher_test.go
+25
-6
No files found.
pkg/storage/etcd3/store_test.go
View file @
cd3f7f41
...
@@ -88,7 +88,7 @@ func TestCreateWithTTL(t *testing.T) {
...
@@ -88,7 +88,7 @@ func TestCreateWithTTL(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Watch failed: %v"
,
err
)
t
.
Fatalf
(
"Watch failed: %v"
,
err
)
}
}
testCheck
Result
(
t
,
0
,
watch
.
Deleted
,
w
,
nil
)
testCheck
EventType
(
t
,
watch
.
Deleted
,
w
)
}
}
func
TestCreateWithKeyExist
(
t
*
testing
.
T
)
{
func
TestCreateWithKeyExist
(
t
*
testing
.
T
)
{
...
@@ -396,7 +396,7 @@ func TestGuaranteedUpdateWithTTL(t *testing.T) {
...
@@ -396,7 +396,7 @@ func TestGuaranteedUpdateWithTTL(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Watch failed: %v"
,
err
)
t
.
Fatalf
(
"Watch failed: %v"
,
err
)
}
}
testCheck
Result
(
t
,
0
,
watch
.
Deleted
,
w
,
nil
)
testCheck
EventType
(
t
,
watch
.
Deleted
,
w
)
}
}
func
TestGuaranteedUpdateWithConflict
(
t
*
testing
.
T
)
{
func
TestGuaranteedUpdateWithConflict
(
t
*
testing
.
T
)
{
...
...
pkg/storage/etcd3/watcher_test.go
View file @
cd3f7f41
...
@@ -46,7 +46,8 @@ func TestWatchList(t *testing.T) {
...
@@ -46,7 +46,8 @@ func TestWatchList(t *testing.T) {
// It tests that
// It tests that
// - first occurrence of objects should notify Add event
// - first occurrence of objects should notify Add event
// -
// - update should trigger Modified event
// - update that gets filtered should trigger Deleted event
func
testWatch
(
t
*
testing
.
T
,
recursive
bool
)
{
func
testWatch
(
t
*
testing
.
T
,
recursive
bool
)
{
ctx
,
store
,
cluster
:=
testSetup
(
t
)
ctx
,
store
,
cluster
:=
testSetup
(
t
)
defer
cluster
.
Terminate
(
t
)
defer
cluster
.
Terminate
(
t
)
...
@@ -90,6 +91,7 @@ func testWatch(t *testing.T, recursive bool) {
...
@@ -90,6 +91,7 @@ func testWatch(t *testing.T, recursive bool) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Watch failed: %v"
,
err
)
t
.
Fatalf
(
"Watch failed: %v"
,
err
)
}
}
var
prevObj
*
api
.
Pod
for
_
,
watchTest
:=
range
tt
.
watchTests
{
for
_
,
watchTest
:=
range
tt
.
watchTests
{
out
:=
&
api
.
Pod
{}
out
:=
&
api
.
Pod
{}
key
:=
tt
.
key
key
:=
tt
.
key
...
@@ -104,8 +106,14 @@ func testWatch(t *testing.T, recursive bool) {
...
@@ -104,8 +106,14 @@ func testWatch(t *testing.T, recursive bool) {
t
.
Fatalf
(
"GuaranteedUpdate failed: %v"
,
err
)
t
.
Fatalf
(
"GuaranteedUpdate failed: %v"
,
err
)
}
}
if
watchTest
.
expectEvent
{
if
watchTest
.
expectEvent
{
testCheckResult
(
t
,
i
,
watchTest
.
watchType
,
w
,
nil
)
expectObj
:=
out
if
watchTest
.
watchType
==
watch
.
Deleted
{
expectObj
=
prevObj
expectObj
.
ResourceVersion
=
out
.
ResourceVersion
}
testCheckResult
(
t
,
i
,
watchTest
.
watchType
,
w
,
expectObj
)
}
}
prevObj
=
out
}
}
w
.
Stop
()
w
.
Stop
()
testCheckStop
(
t
,
i
,
w
)
testCheckStop
(
t
,
i
,
w
)
...
@@ -123,7 +131,7 @@ func TestDeleteTriggerWatch(t *testing.T) {
...
@@ -123,7 +131,7 @@ func TestDeleteTriggerWatch(t *testing.T) {
if
err
:=
store
.
Delete
(
ctx
,
key
,
&
api
.
Pod
{},
nil
);
err
!=
nil
{
if
err
:=
store
.
Delete
(
ctx
,
key
,
&
api
.
Pod
{},
nil
);
err
!=
nil
{
t
.
Fatalf
(
"Delete failed: %v"
,
err
)
t
.
Fatalf
(
"Delete failed: %v"
,
err
)
}
}
testCheck
Result
(
t
,
0
,
watch
.
Deleted
,
w
,
nil
)
testCheck
EventType
(
t
,
watch
.
Deleted
,
w
)
}
}
// TestWatchSync tests that
// TestWatchSync tests that
...
@@ -168,7 +176,7 @@ func TestWatchError(t *testing.T) {
...
@@ -168,7 +176,7 @@ func TestWatchError(t *testing.T) {
func
(
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
func
(
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}},
nil
return
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}},
nil
}))
}))
testCheck
Result
(
t
,
0
,
watch
.
Error
,
w
,
nil
)
testCheck
EventType
(
t
,
watch
.
Error
,
w
)
}
}
func
TestWatchContextCancel
(
t
*
testing
.
T
)
{
func
TestWatchContextCancel
(
t
*
testing
.
T
)
{
...
@@ -213,7 +221,7 @@ func TestWatchErrResultNotBlockAfterCancel(t *testing.T) {
...
@@ -213,7 +221,7 @@ func TestWatchErrResultNotBlockAfterCancel(t *testing.T) {
wg
.
Wait
()
wg
.
Wait
()
}
}
func
TestWatchDeleteEventObject
Should
HaveLatestRV
(
t
*
testing
.
T
)
{
func
TestWatchDeleteEventObjectHaveLatestRV
(
t
*
testing
.
T
)
{
ctx
,
store
,
cluster
:=
testSetup
(
t
)
ctx
,
store
,
cluster
:=
testSetup
(
t
)
defer
cluster
.
Terminate
(
t
)
defer
cluster
.
Terminate
(
t
)
key
,
storedObj
:=
testPropogateStore
(
t
,
store
,
ctx
,
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}})
key
,
storedObj
:=
testPropogateStore
(
t
,
store
,
ctx
,
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}})
...
@@ -257,6 +265,17 @@ func (c *testCodec) Decode(data []byte, defaults *unversioned.GroupVersionKind,
...
@@ -257,6 +265,17 @@ func (c *testCodec) Decode(data []byte, defaults *unversioned.GroupVersionKind,
return
nil
,
nil
,
errors
.
New
(
"Expected decoding failure"
)
return
nil
,
nil
,
errors
.
New
(
"Expected decoding failure"
)
}
}
func
testCheckEventType
(
t
*
testing
.
T
,
expectEventType
watch
.
EventType
,
w
watch
.
Interface
)
{
select
{
case
res
:=
<-
w
.
ResultChan
()
:
if
res
.
Type
!=
expectEventType
{
t
.
Errorf
(
"event type want=%v, get=%v"
,
expectEventType
,
res
.
Type
)
}
case
<-
time
.
After
(
wait
.
ForeverTestTimeout
)
:
t
.
Errorf
(
"time out after waiting %v on ResultChan"
,
wait
.
ForeverTestTimeout
)
}
}
func
testCheckResult
(
t
*
testing
.
T
,
i
int
,
expectEventType
watch
.
EventType
,
w
watch
.
Interface
,
expectObj
*
api
.
Pod
)
{
func
testCheckResult
(
t
*
testing
.
T
,
i
int
,
expectEventType
watch
.
EventType
,
w
watch
.
Interface
,
expectObj
*
api
.
Pod
)
{
select
{
select
{
case
res
:=
<-
w
.
ResultChan
()
:
case
res
:=
<-
w
.
ResultChan
()
:
...
@@ -264,7 +283,7 @@ func testCheckResult(t *testing.T, i int, expectEventType watch.EventType, w wat
...
@@ -264,7 +283,7 @@ func testCheckResult(t *testing.T, i int, expectEventType watch.EventType, w wat
t
.
Errorf
(
"#%d: event type want=%v, get=%v"
,
i
,
expectEventType
,
res
.
Type
)
t
.
Errorf
(
"#%d: event type want=%v, get=%v"
,
i
,
expectEventType
,
res
.
Type
)
return
return
}
}
if
expectObj
!=
nil
&&
!
reflect
.
DeepEqual
(
expectObj
,
res
.
Object
)
{
if
!
reflect
.
DeepEqual
(
expectObj
,
res
.
Object
)
{
t
.
Errorf
(
"#%d: obj want=
\n
%#v
\n
get=
\n
%#v"
,
i
,
expectObj
,
res
.
Object
)
t
.
Errorf
(
"#%d: obj want=
\n
%#v
\n
get=
\n
%#v"
,
i
,
expectObj
,
res
.
Object
)
}
}
case
<-
time
.
After
(
wait
.
ForeverTestTimeout
)
:
case
<-
time
.
After
(
wait
.
ForeverTestTimeout
)
:
...
...
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