Small improvement to Events processor interface

In this commit, we make sure that there are no left over channels
after phase.Run is complete

Change-Id: Ia9b7a37f19aad892e77fdca5ad02efe8322e612b
This commit is contained in:
Kostiantyn Kalynovskyi 2020-11-17 14:31:37 -06:00
parent 1918421ae8
commit c89cd5fba0
3 changed files with 8 additions and 0 deletions

View File

@ -27,6 +27,7 @@ import (
// EventProcessor use to process event channels produced by executors
type EventProcessor interface {
Process(<-chan Event) error
Close()
}
// DefaultProcessor is implementation of EventProcessor
@ -72,6 +73,11 @@ func (p *DefaultProcessor) Process(ch <-chan Event) error {
return checkErrors(p.errors)
}
// Close cleans up the auxiliary channels used to process events
func (p *DefaultProcessor) Close() {
close(p.applierChan)
}
func (p *DefaultProcessor) processApplierEvent(e applyevent.Event) {
if e.Type == applyevent.ErrorType {
log.Printf("Received error when applying errors to kubernetes %v", e.ErrorEvent.Err)

View File

@ -28,6 +28,7 @@ import (
func TestDefaultProcessor(t *testing.T) {
proc := events.NewDefaultProcessor(utils.Streams())
defer proc.Close()
tests := []struct {
name string
events []events.Event

View File

@ -115,6 +115,7 @@ func (p *phase) Executor() (ifc.Executor, error) {
// Run runs the phase via executor
func (p *phase) Run(ro ifc.RunOptions) error {
defer p.processor.Close()
executor, err := p.Executor()
if err != nil {
return err