mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #99926 from gjkim42/deflake-TestWatchFileChanged
kubelet_test: Deflake TestWatchFileChanged
This commit is contained in:
commit
ea07644522
@ -108,11 +108,16 @@ var (
|
||||
testCases = []struct {
|
||||
watchDir bool
|
||||
symlink bool
|
||||
period time.Duration
|
||||
}{
|
||||
{true, true},
|
||||
{true, false},
|
||||
{false, true},
|
||||
{false, false},
|
||||
// set the period to be long enough for the file to be changed
|
||||
// and short enough to trigger the event
|
||||
{true, true, 3 * time.Second},
|
||||
|
||||
// set the period to avoid periodic PodUpdate event
|
||||
{true, false, 60 * time.Second},
|
||||
{false, true, 60 * time.Second},
|
||||
{false, false, 60 * time.Second},
|
||||
}
|
||||
)
|
||||
|
||||
@ -124,7 +129,7 @@ func TestWatchFileAdded(t *testing.T) {
|
||||
|
||||
func TestWatchFileChanged(t *testing.T) {
|
||||
for _, testCase := range testCases {
|
||||
watchFileChanged(testCase.watchDir, testCase.symlink, t)
|
||||
watchFileChanged(testCase.watchDir, testCase.symlink, testCase.period, t)
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,7 +280,7 @@ func watchFileAdded(watchDir bool, symlink bool, t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func watchFileChanged(watchDir bool, symlink bool, t *testing.T) {
|
||||
func watchFileChanged(watchDir bool, symlink bool, period time.Duration, t *testing.T) {
|
||||
hostname := types.NodeName("random-test-hostname")
|
||||
var testCases = getTestCases(hostname)
|
||||
|
||||
@ -314,22 +319,23 @@ func watchFileChanged(watchDir bool, symlink bool, t *testing.T) {
|
||||
}()
|
||||
|
||||
if watchDir {
|
||||
NewSourceFile(dirName, hostname, 100*time.Millisecond, ch)
|
||||
NewSourceFile(dirName, hostname, period, ch)
|
||||
} else {
|
||||
NewSourceFile(file, hostname, 100*time.Millisecond, ch)
|
||||
NewSourceFile(file, hostname, period, ch)
|
||||
}
|
||||
|
||||
// await fsnotify to be ready
|
||||
time.Sleep(time.Second)
|
||||
|
||||
// expect an update by SourceFile.resetStoreFromPath()
|
||||
expectUpdate(t, ch, testCase)
|
||||
|
||||
pod := testCase.pod.(*v1.Pod)
|
||||
pod.Spec.Containers[0].Name = "image2"
|
||||
|
||||
testCase.expected.Pods[0].Spec.Containers[0].Name = "image2"
|
||||
changeFile := func() {
|
||||
// Edit the file content
|
||||
testCase.lock.Lock()
|
||||
defer testCase.lock.Unlock()
|
||||
|
||||
pod := testCase.pod.(*v1.Pod)
|
||||
pod.Spec.Containers[0].Name = "image2"
|
||||
|
||||
testCase.expected.Pods[0].Spec.Containers[0].Name = "image2"
|
||||
if symlink {
|
||||
file = testCase.writeToFile(linkedDirName, fileName, t)
|
||||
return
|
||||
@ -374,8 +380,6 @@ 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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user