Skip to content

Commit

Permalink
Added mutex to avoid concurrency errors on SubscriptionManager (#2316)
Browse files Browse the repository at this point in the history
* Added mutex to avoid concurrency errors on SubscriptionManager

* Fix CI dependencies

* Adding mutex to the event emitting
  • Loading branch information
danielbdias authored Apr 5, 2023
1 parent a20ee16 commit 40560b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:

build-go:
name: Build go binaries (API Server and CLI)
needs: [unit-test-cli, test-server]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 5 additions & 0 deletions server/executor/eventemitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package executor

import (
"context"
"sync"

"github.com/kubeshop/tracetest/server/model"
)
Expand All @@ -17,6 +18,7 @@ type publisher interface {
type internalEventEmitter struct {
repository model.TestRunEventRepository
publisher publisher
mutex sync.Mutex
}

func NewEventEmitter(repository model.TestRunEventRepository, publisher publisher) EventEmitter {
Expand All @@ -32,6 +34,9 @@ func (em *internalEventEmitter) Emit(ctx context.Context, event model.TestRunEve
return err
}

em.mutex.Lock()
defer em.mutex.Unlock()

em.publisher.Publish(event.ResourceID(), event)

return nil
Expand Down

0 comments on commit 40560b1

Please sign in to comment.