Skip to content

Commit

Permalink
koordlet: revise flaky test in pleg (#2060)
Browse files Browse the repository at this point in the history
Signed-off-by: saintube <saintube@foxmail.com>
  • Loading branch information
saintube committed May 23, 2024
1 parent f5b611f commit 7e944d5
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions pkg/koordlet/pleg/pleg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,6 @@ func TestPlegHandlePodEvents(t *testing.T) {
}

func TestPlegHandleContainerEvents(t *testing.T) {
stopCh := make(chan struct{})
defer close(stopCh)

pg, err := NewPLEG("./test")
if err != nil {
t.Fatal(err)
}
pg.(*pleg).podWatcher, _ = NewTestWatcher()
pg.(*pleg).containerWatcher, _ = NewTestWatcher()
go pg.Run(stopCh)

handler := NewTestHandler()
id := pg.AddHandler(handler)
defer pg.RemoverHandler(id)

testCases := []struct {
name string
mockEvent *inotify.Event
Expand Down Expand Up @@ -194,6 +179,21 @@ func TestPlegHandleContainerEvents(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
stopCh := make(chan struct{})
defer close(stopCh)

pg, err := NewPLEG("./test-" + tc.name)
if err != nil {
t.Fatal(err)
}
pg.(*pleg).podWatcher, _ = NewTestWatcher()
pg.(*pleg).containerWatcher, _ = NewTestWatcher()
go pg.Run(stopCh)

handler := NewTestHandler()
id := pg.AddHandler(handler)
defer pg.RemoverHandler(id)

pg.(*pleg).containerWatcher.Event() <- tc.mockEvent
timer := time.NewTimer(100 * time.Millisecond)
defer timer.Stop()
Expand Down

0 comments on commit 7e944d5

Please sign in to comment.