Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
fix: Make fake event sender thread safe by adding a lock (#357)
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Bacher <[email protected]>
  • Loading branch information
bacherfl authored Nov 24, 2021
1 parent b27c16d commit fe1fb0c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/lib/v0_2_0/fake/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"context"
"fmt"
cloudevents "github.com/cloudevents/sdk-go/v2"
"sync"
)

// EventSender fakes the sending of CloudEvents
type EventSender struct {
SentEvents []cloudevents.Event
Reactors map[string]func(event cloudevents.Event) error
lock sync.Mutex
}

// SendEvent fakes the sending of CloudEvents
Expand All @@ -27,6 +29,8 @@ func (es *EventSender) Send(ctx context.Context, event cloudevents.Event) error
}
}
}
es.lock.Lock()
defer es.lock.Unlock()
es.SentEvents = append(es.SentEvents, event)
return nil
}
Expand Down

0 comments on commit fe1fb0c

Please sign in to comment.