Skip to content
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

Block in filePoller.Close until loop is finished #879

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,22 @@ jobs:
cache: true
- name: Test
run: make test-ci
- name: Determine skip-codecov
id: skip-codecov
with:
script: |
const { repo, owner } = context.repo;
const { data: commit } = await github.rest.repos.getCommit({
owner,
repo,
ref: '${{ github.event.pull_request.head.sha || github.event.after }}'
});
const commitMesasge = commit.commit.message;
const skip = commitMessage.includes("[skip codecov]") || commitMessage.includes("[skip-codecov]");
core.setOutput("skip", skip);
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: steps.skip-codecov.outputs.skip != "true"
with:
file: covreport
env:
Expand Down
2 changes: 2 additions & 0 deletions internal/filenotify/filenotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ func NewPollingWatcher(cfg Config) (FileWatcher, error) {
wr: watcher.New(),
events: make(chan fsnotify.Event),
errors: make(chan error),
done: make(chan struct{}),
}
poller.wr.FilterOps(watcher.Create, watcher.Rename, watcher.Move)
go poller.loop()

// Block until radovskyb's watcher is started.
done := make(chan error)
{
go func() {
Expand Down
14 changes: 13 additions & 1 deletion internal/filenotify/poller.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package filenotify

import (
"errors"
"time"

"github.com/fsnotify/fsnotify"
"github.com/radovskyb/watcher"
)
Expand All @@ -16,6 +19,9 @@ type filePoller struct {

// errors is the channel to listen to for watch errors.
errors chan error

// done signals that the loop is done when the channel is closed.
done chan struct{}
}

// loop captures and transform radovskyb's watcher into fsnotify events.
Expand Down Expand Up @@ -43,6 +49,7 @@ func (w *filePoller) loop() {
case err := <-w.wr.Error:
w.errors <- err
case <-w.wr.Closed:
close(w.done)
return
}
}
Expand Down Expand Up @@ -70,5 +77,10 @@ func (w *filePoller) Errors() <-chan error {
func (w *filePoller) Close() error {
w.wr.Close()

return nil
select {
case <-w.done:
return nil
case <-time.After(time.Second * 5):
return errors.New("filePoller.Close timeout")
}
}
Loading