Skip to content

Commit

Permalink
Add waitgroup wait to keep plugin running until goroutine is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean-Coakley committed Sep 19, 2022
1 parent 9fe1f95 commit c0ea8f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/plugins/process_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (pw *ProcessWatcher) Info() *core.Info {

func (pw *ProcessWatcher) Close() {
log.Info("ProcessWatcher is wrapping up")
pw.wg.Wait()
}

func (pw *ProcessWatcher) Process(message *core.Message) {}
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/process_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ func TestProcessWatcher_getProcUpdates(t *testing.T) {

func TestProcessWatcher_Process(t *testing.T) {
env := tutils.GetMockEnvWithProcess()

pluginUnderTest := NewProcessWatcher(env, tutils.GetMockNginxBinary())
messagePipe := core.SetupMockMessagePipe(t, context.TODO(), pluginUnderTest)

ctx, cancel := context.WithCancel(context.TODO())
messagePipe := core.SetupMockMessagePipe(t, ctx, pluginUnderTest)

pluginUnderTest.Init(messagePipe)
messagePipe.Run()
Expand All @@ -173,6 +174,8 @@ func TestProcessWatcher_Process(t *testing.T) {
}
}

cancel()

pluginUnderTest.Close()
}

Expand Down

0 comments on commit c0ea8f8

Please sign in to comment.