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
a2212186
Commit
a2212186
authored
Jun 04, 2018
by
yue9944882
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes data races
parent
4c13f5fd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
9 deletions
+14
-9
file_linux_test.go
pkg/kubelet/config/file_linux_test.go
+14
-9
No files found.
pkg/kubelet/config/file_linux_test.go
View file @
a2212186
...
...
@@ -131,6 +131,7 @@ func TestWatchFileChanged(t *testing.T) {
}
type
testCase
struct
{
lock
*
sync
.
Mutex
desc
string
linkedFile
string
pod
runtime
.
Object
...
...
@@ -141,6 +142,7 @@ func getTestCases(hostname types.NodeName) []*testCase {
grace
:=
int64
(
30
)
return
[]
*
testCase
{
{
lock
:
&
sync
.
Mutex
{},
desc
:
"Simple pod"
,
pod
:
&
v1
.
Pod
{
TypeMeta
:
metav1
.
TypeMeta
{
...
...
@@ -304,11 +306,10 @@ func watchFileChanged(watchDir bool, symlink bool, t *testing.T) {
}
var
file
string
lock
:=
&
sync
.
Mutex
{}
ch
:=
make
(
chan
interface
{})
func
()
{
lock
.
Lock
()
defer
lock
.
Unlock
()
testCase
.
lock
.
Lock
()
defer
testCase
.
lock
.
Unlock
()
if
symlink
{
file
=
testCase
.
writeToFile
(
linkedDirName
,
fileName
,
t
)
...
...
@@ -332,8 +333,8 @@ func watchFileChanged(watchDir bool, symlink bool, t *testing.T) {
changeFile
:=
func
()
{
// Edit the file content
lock
.
Lock
()
defer
lock
.
Unlock
()
testCase
.
lock
.
Lock
()
defer
testCase
.
lock
.
Unlock
()
pod
:=
testCase
.
pod
.
(
*
v1
.
Pod
)
pod
.
Spec
.
Containers
[
0
]
.
Name
=
"image2"
...
...
@@ -352,9 +353,7 @@ func watchFileChanged(watchDir bool, symlink bool, t *testing.T) {
expectUpdate
(
t
,
ch
,
testCase
)
if
watchDir
{
from
:=
fileName
fileName
=
fileName
+
"_ch"
go
changeFileName
(
dirName
,
from
,
fileName
,
t
)
go
changeFileName
(
dirName
,
fileName
,
fileName
+
"_ch"
,
t
)
// expect an update by MOVED_FROM inotify event cause changing file name
expectEmptyUpdate
(
t
,
ch
)
// expect an update by MOVED_TO inotify event cause changing file name
...
...
@@ -365,8 +364,12 @@ func watchFileChanged(watchDir bool, symlink bool, t *testing.T) {
}
func
deleteFile
(
dir
,
file
string
,
ch
chan
interface
{},
t
*
testing
.
T
)
{
path
:=
filepath
.
Join
(
dir
,
file
)
if
_
,
err
:=
os
.
Stat
(
path
);
err
!=
nil
{
// The file might absent if it's renamed, deleted..
return
}
go
func
()
{
path
:=
filepath
.
Join
(
dir
,
file
)
err
:=
os
.
Remove
(
path
)
if
err
!=
nil
{
t
.
Errorf
(
"unable to remove test file %s: %s"
,
path
,
err
)
...
...
@@ -397,6 +400,8 @@ func expectUpdate(t *testing.T, ch chan interface{}, testCase *testCase) {
}
}
testCase
.
lock
.
Lock
()
defer
testCase
.
lock
.
Unlock
()
if
!
apiequality
.
Semantic
.
DeepEqual
(
testCase
.
expected
,
update
)
{
t
.
Fatalf
(
"%s: Expected: %#v, Got: %#v"
,
testCase
.
desc
,
testCase
.
expected
,
update
)
}
...
...
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