Repository navigation
fix(platform): stop the manifest file watcher when the context ends #839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bc8ec89
c7a650c
9dd1b5d
644185f
2234913
d179e7f
170f9e0
c82133c
911d6dd
51c0b4d
731c506
1216e86
0edd45f
928e415
0d08bb6
4d6148f
2cf3e8d
8c1d82d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |
| "net/http" | ||
| "net/http/httptest" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "sync" | ||
| "testing" | ||
|
|
@@ -515,6 +516,7 @@ func Test_LocalServer_WatchManifest(t *testing.T) { | |
| manifestSource config.ManifestSource | ||
| manifestErr error | ||
| watch *hooks.WatchOpts | ||
| watchManifest bool | ||
| expectedErr error | ||
| expectedOutput []string | ||
| }{ | ||
|
|
@@ -538,6 +540,11 @@ func Test_LocalServer_WatchManifest(t *testing.T) { | |
| watch: &hooks.WatchOpts{}, | ||
| expectedOutput: []string{"Manifest source is remote", "Manifest watching is not enabled"}, | ||
| }, | ||
| "watches manifest paths until the context ends": { | ||
| manifestSource: config.ManifestSourceRemote, | ||
| watchManifest: true, | ||
| expectedOutput: []string{"Watching manifest changes to file paths matching"}, | ||
| }, | ||
| } { | ||
| t.Run(name, func(t *testing.T) { | ||
| ctx, cancel := context.WithCancel(slackcontext.MockContext(t.Context())) | ||
|
|
@@ -551,6 +558,14 @@ func Test_LocalServer_WatchManifest(t *testing.T) { | |
| clients := shared.NewClientFactory(clientsMock.MockClientFactory()) | ||
| server := LocalServer{clients: clients} | ||
| server.cliConfig.Config.Watch = tc.watch | ||
| if tc.watchManifest { | ||
| server.cliConfig.Config.Watch = &hooks.WatchOpts{ | ||
| Manifest: &hooks.ManifestWatchOpts{ | ||
| Paths: []string{t.TempDir()}, | ||
| FilterRegex: `manifest\.json$`, | ||
| }, | ||
| } | ||
| } | ||
| errChan := make(chan error, 1) | ||
| go func() { | ||
| errChan <- server.WatchManifest(ctx, types.SlackAuth{}, types.App{}) | ||
|
|
@@ -583,6 +598,32 @@ func Test_LocalServer_WatchManifest(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func Test_closeWatcherOnDone_drainsAnUnreadEvent(t *testing.T) { | ||
| dir := t.TempDir() | ||
| manifest := filepath.Join(dir, "manifest.json") | ||
| require.NoError(t, os.WriteFile(manifest, []byte("{}"), 0o600)) | ||
| w := watcher.New() | ||
| require.NoError(t, w.AddRecursive(dir)) | ||
| later := time.Now().Add(time.Hour) | ||
| require.NoError(t, os.Chtimes(manifest, later, later)) | ||
| started := make(chan error, 1) | ||
| go func() { started <- w.Start(time.Millisecond) }() | ||
| ctx, cancel := context.WithCancel(t.Context()) | ||
| cancel() | ||
| time.Sleep(50 * time.Millisecond) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 question (non-blocking): On a slow runner
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! The event channel is unbuffered, so the test can't see the pending send without reading it. I'll keep the sleep for now and revisit if it flakes in CI. |
||
| done := make(chan struct{}) | ||
| go func() { | ||
| closeWatcherOnDone(ctx, w) | ||
| close(done) | ||
| }() | ||
| select { | ||
| case <-done: | ||
| case <-time.After(time.Second): | ||
| require.FailNow(t, "closeWatcherOnDone did not return with an unread event") | ||
| } | ||
| require.NoError(t, <-started) | ||
| } | ||
|
|
||
| func Test_LocalServer_watchManifestEvents(t *testing.T) { | ||
| for name, tc := range map[string]struct { | ||
| cancel bool | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧪 issue (blocking): Nothing tests the drain loop: swapping it for a plain
w.Close()still passesTest_LocalServer_WatchManifest. Could we add a test with one unread event pending? This one passes here and hangs without the drain (needspath/filepath):There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in commit 170f9e0, thanks for the test! 🙇