Skip to content

Commit

Permalink
close the server via context
Browse files Browse the repository at this point in the history
Signed-off-by: EshaanAgg <[email protected]>
  • Loading branch information
EshaanAgg committed Jan 25, 2025
1 parent b1c1e27 commit b1518b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions internal/provider/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ func (p *Provider) Start(ctx context.Context) error {

switch event.Op {
case fsnotify.Create, fsnotify.Write, fsnotify.Remove:
// Since we do not watch any events in the subdirectories, any events involving files
// modifications in current directory will trigger the event handling.
// Since we do not watch any events related to creation/deletion of subdirectories,
// any events involving files & folder modifications should trigger the event handling.
goto handle
default:
// do nothing
Expand Down Expand Up @@ -209,4 +209,5 @@ func (p *Provider) startHealthProbeServer(ctx context.Context, readyzChecker hea
if err := srv.ListenAndServe(); err != nil {
p.logger.Error(err, "failed to start health probe server")
}

Check failure on line 212 in internal/provider/file/file.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gofumpt)
}
8 changes: 6 additions & 2 deletions internal/provider/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ func TestFileProvider(t *testing.T) {
require.NoError(t, err)

// Start file provider.
ctx, cancelFpContext := context.WithCancel(context.Background())
go func() {
if err := fp.Start(context.Background()); err != nil {
if err := fp.Start(ctx); err != nil {
t.Errorf("failed to start file provider: %v", err)
}
}()
Expand Down Expand Up @@ -166,6 +167,7 @@ func TestFileProvider(t *testing.T) {
})

t.Cleanup(func() {
cancelFpContext()
err := os.RemoveAll(watchFileBase)
require.NoError(t, err)
err = os.RemoveAll(watchDirPath)
Expand Down Expand Up @@ -214,8 +216,9 @@ func TestRecursiveFileProvider(t *testing.T) {
require.NoError(t, err)

// Start file provider.
ctx, cancelFpContext := context.WithCancel(context.Background())
go func() {
if err := fp.Start(context.Background()); err != nil {
if err := fp.Start(ctx); err != nil {
t.Errorf("failed to start file provider: %v", err)
}
}()
Expand Down Expand Up @@ -281,6 +284,7 @@ func TestRecursiveFileProvider(t *testing.T) {
})

t.Cleanup(func() {
cancelFpContext()
err := os.RemoveAll(baseDir)
require.NoError(t, err)
err = os.RemoveAll(unwatchedDir)
Expand Down

0 comments on commit b1518b9

Please sign in to comment.