Skip to content

Commit

Permalink
Fix panic in stop when the VM goes away
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
  • Loading branch information
alexandear committed Jul 8, 2024
1 parent 463ed82 commit abe88c0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/hostagent/events/watcher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package events

import (
"context"
"os"
"testing"
"time"

"gotest.tools/v3/assert"
)

func TestWatch(t *testing.T) {
t.Run("no panic when stdout file is removed", func(t *testing.T) {
stdout, err := os.CreateTemp(t.TempDir(), "")
assert.NilError(t, err)
t.Cleanup(func() { stdout.Close() })
stderr, err := os.CreateTemp(t.TempDir(), "")
assert.NilError(t, err)
t.Cleanup(func() { stderr.Close() })
ch := make(chan struct{}, 1)

go func() {
_ = os.Remove(stdout.Name())
ch <- struct{}{}
}()

err = Watch(context.Background(), stdout.Name(), stderr.Name(), time.Now(), func(Event) bool { return false })

assert.NilError(t, err)

<-ch
})
}

0 comments on commit abe88c0

Please sign in to comment.