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
bd9fca62
Unverified
Commit
bd9fca62
authored
Nov 30, 2021
by
Derek Nola
Committed by
GitHub
Nov 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved cleanup for etcd unit test (#4537) (#4609)
* Improved cleanup for etcd unit test Signed-off-by:
Derek Nola
<
derek.nola@suse.com
>
parent
4e3a074c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
20 deletions
+53
-20
etcd_test.go
pkg/etcd/etcd_test.go
+53
-20
No files found.
pkg/etcd/etcd_test.go
View file @
bd9fca62
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
testutil
"github.com/rancher/k3s/tests/util"
testutil
"github.com/rancher/k3s/tests/util"
"github.com/robfig/cron/v3"
"github.com/robfig/cron/v3"
clientv3
"go.etcd.io/etcd/clientv3"
clientv3
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/etcdserver"
utilnet
"k8s.io/apimachinery/pkg/util/net"
utilnet
"k8s.io/apimachinery/pkg/util/net"
)
)
...
@@ -222,8 +223,8 @@ func Test_UnitETCD_Start(t *testing.T) {
...
@@ -222,8 +223,8 @@ func Test_UnitETCD_Start(t *testing.T) {
name
string
name
string
fields
fields
fields
fields
args
args
args
args
setup
func
(
cnf
*
config
.
Control
,
ctxInfo
*
contextInfo
)
error
setup
func
(
e
*
ETCD
,
ctxInfo
*
contextInfo
)
error
teardown
func
(
cnf
*
config
.
Control
,
ctxInfo
*
contextInfo
)
error
teardown
func
(
e
*
ETCD
,
ctxInfo
*
contextInfo
)
error
wantErr
bool
wantErr
bool
}{
}{
{
{
...
@@ -236,15 +237,24 @@ func Test_UnitETCD_Start(t *testing.T) {
...
@@ -236,15 +237,24 @@ func Test_UnitETCD_Start(t *testing.T) {
args
:
args
{
args
:
args
{
clientAccessInfo
:
nil
,
clientAccessInfo
:
nil
,
},
},
setup
:
func
(
cnf
*
config
.
Control
,
ctxInfo
*
contextInfo
)
error
{
setup
:
func
(
e
*
ETCD
,
ctxInfo
*
contextInfo
)
error
{
ctxInfo
.
ctx
,
ctxInfo
.
cancel
=
context
.
WithCancel
(
context
.
Background
())
ctxInfo
.
ctx
,
ctxInfo
.
cancel
=
context
.
WithCancel
(
context
.
Background
())
cnf
.
EtcdDisableSnapshots
=
true
e
.
config
.
EtcdDisableSnapshots
=
true
return
testutil
.
GenerateRuntime
(
cnf
)
testutil
.
GenerateRuntime
(
e
.
config
)
e
.
runtime
=
e
.
config
.
Runtime
client
,
err
:=
GetClient
(
ctxInfo
.
ctx
,
e
.
runtime
,
endpoint
)
e
.
client
=
client
return
err
},
},
teardown
:
func
(
cnf
*
config
.
Control
,
ctxInfo
*
contextInfo
)
error
{
teardown
:
func
(
e
*
ETCD
,
ctxInfo
*
contextInfo
)
error
{
// RemoveSelf will fail with a specific error, but it still does cleanup for testing purposes
if
err
:=
e
.
RemoveSelf
(
ctxInfo
.
ctx
);
err
!=
nil
&&
err
.
Error
()
!=
etcdserver
.
ErrNotEnoughStartedMembers
.
Error
()
{
return
err
}
ctxInfo
.
cancel
()
ctxInfo
.
cancel
()
time
.
Sleep
(
5
*
time
.
Second
)
time
.
Sleep
(
10
*
time
.
Second
)
testutil
.
CleanupDataDir
(
cnf
)
testutil
.
CleanupDataDir
(
e
.
config
)
return
nil
return
nil
},
},
},
},
...
@@ -259,14 +269,23 @@ func Test_UnitETCD_Start(t *testing.T) {
...
@@ -259,14 +269,23 @@ func Test_UnitETCD_Start(t *testing.T) {
args
:
args
{
args
:
args
{
clientAccessInfo
:
nil
,
clientAccessInfo
:
nil
,
},
},
setup
:
func
(
cnf
*
config
.
Control
,
ctxInfo
*
contextInfo
)
error
{
setup
:
func
(
e
*
ETCD
,
ctxInfo
*
contextInfo
)
error
{
ctxInfo
.
ctx
,
ctxInfo
.
cancel
=
context
.
WithCancel
(
context
.
Background
())
ctxInfo
.
ctx
,
ctxInfo
.
cancel
=
context
.
WithCancel
(
context
.
Background
())
return
testutil
.
GenerateRuntime
(
cnf
)
testutil
.
GenerateRuntime
(
e
.
config
)
e
.
runtime
=
e
.
config
.
Runtime
client
,
err
:=
GetClient
(
ctxInfo
.
ctx
,
e
.
runtime
,
endpoint
)
e
.
client
=
client
return
err
},
},
teardown
:
func
(
cnf
*
config
.
Control
,
ctxInfo
*
contextInfo
)
error
{
teardown
:
func
(
e
*
ETCD
,
ctxInfo
*
contextInfo
)
error
{
// RemoveSelf will fail with a specific error, but it still does cleanup for testing purposes
if
err
:=
e
.
RemoveSelf
(
ctxInfo
.
ctx
);
err
!=
nil
&&
err
.
Error
()
!=
etcdserver
.
ErrNotEnoughStartedMembers
.
Error
()
{
return
err
}
ctxInfo
.
cancel
()
ctxInfo
.
cancel
()
time
.
Sleep
(
5
*
time
.
Second
)
time
.
Sleep
(
5
*
time
.
Second
)
testutil
.
CleanupDataDir
(
cnf
)
testutil
.
CleanupDataDir
(
e
.
config
)
return
nil
return
nil
},
},
},
},
...
@@ -281,18 +300,28 @@ func Test_UnitETCD_Start(t *testing.T) {
...
@@ -281,18 +300,28 @@ func Test_UnitETCD_Start(t *testing.T) {
args
:
args
{
args
:
args
{
clientAccessInfo
:
nil
,
clientAccessInfo
:
nil
,
},
},
setup
:
func
(
cnf
*
config
.
Control
,
ctxInfo
*
contextInfo
)
error
{
setup
:
func
(
e
*
ETCD
,
ctxInfo
*
contextInfo
)
error
{
ctxInfo
.
ctx
,
ctxInfo
.
cancel
=
context
.
WithCancel
(
context
.
Background
())
ctxInfo
.
ctx
,
ctxInfo
.
cancel
=
context
.
WithCancel
(
context
.
Background
())
if
err
:=
testutil
.
GenerateRuntime
(
cnf
);
err
!=
nil
{
if
err
:=
testutil
.
GenerateRuntime
(
e
.
config
);
err
!=
nil
{
return
err
return
err
}
}
return
os
.
MkdirAll
(
walDir
(
cnf
),
0700
)
e
.
runtime
=
e
.
config
.
Runtime
client
,
err
:=
GetClient
(
ctxInfo
.
ctx
,
e
.
runtime
,
endpoint
)
if
err
!=
nil
{
return
err
}
e
.
client
=
client
return
os
.
MkdirAll
(
walDir
(
e
.
config
),
0700
)
},
},
teardown
:
func
(
cnf
*
config
.
Control
,
ctxInfo
*
contextInfo
)
error
{
teardown
:
func
(
e
*
ETCD
,
ctxInfo
*
contextInfo
)
error
{
// RemoveSelf will fail with a specific error, but it still does cleanup for testing purposes
if
err
:=
e
.
RemoveSelf
(
ctxInfo
.
ctx
);
err
!=
nil
&&
err
.
Error
()
!=
etcdserver
.
ErrNotEnoughStartedMembers
.
Error
()
{
return
err
}
ctxInfo
.
cancel
()
ctxInfo
.
cancel
()
time
.
Sleep
(
5
*
time
.
Second
)
time
.
Sleep
(
5
*
time
.
Second
)
testutil
.
CleanupDataDir
(
cnf
)
testutil
.
CleanupDataDir
(
e
.
config
)
os
.
Remove
(
walDir
(
cnf
))
os
.
Remove
(
walDir
(
e
.
config
))
return
nil
return
nil
},
},
},
},
...
@@ -308,14 +337,18 @@ func Test_UnitETCD_Start(t *testing.T) {
...
@@ -308,14 +337,18 @@ func Test_UnitETCD_Start(t *testing.T) {
cron
:
tt
.
fields
.
cron
,
cron
:
tt
.
fields
.
cron
,
s3
:
tt
.
fields
.
s3
,
s3
:
tt
.
fields
.
s3
,
}
}
defer
tt
.
teardown
(
e
.
config
,
&
tt
.
fields
.
context
)
if
err
:=
tt
.
setup
(
e
.
config
,
&
tt
.
fields
.
context
);
err
!=
nil
{
if
err
:=
tt
.
setup
(
e
,
&
tt
.
fields
.
context
);
err
!=
nil
{
t
.
Errorf
(
"Setup for ETCD.Start() failed = %v"
,
err
)
t
.
Errorf
(
"Setup for ETCD.Start() failed = %v"
,
err
)
return
return
}
}
if
err
:=
e
.
Start
(
tt
.
fields
.
context
.
ctx
,
tt
.
args
.
clientAccessInfo
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
if
err
:=
e
.
Start
(
tt
.
fields
.
context
.
ctx
,
tt
.
args
.
clientAccessInfo
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"ETCD.Start() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
t
.
Errorf
(
"ETCD.Start() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
}
}
if
err
:=
tt
.
teardown
(
e
,
&
tt
.
fields
.
context
);
err
!=
nil
{
t
.
Errorf
(
"Teardown for ETCD.Start() failed = %v"
,
err
)
return
}
})
})
}
}
}
}
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