Skip to content

Commit

Permalink
Fix data race in test (#3111)
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator authored Jul 20, 2023
1 parent a659bbb commit 2a3dfaa
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"context"
"testing"

"github.com/elastic/elastic-agent-libs/atomic"

"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent-client/v7/pkg/proto"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
Expand Down Expand Up @@ -41,20 +43,20 @@ func makeComponentState(name string, proxiedActions []string) runtime.ComponentC

type MockActionCoordinator struct {
st coordinator.State
performedActions int
performedActions atomic.Int
}

func (c *MockActionCoordinator) State() coordinator.State {
return c.st
}

func (c *MockActionCoordinator) PerformAction(ctx context.Context, comp component.Component, unit component.Unit, name string, params map[string]interface{}) (map[string]interface{}, error) {
c.performedActions++
c.performedActions.Inc()
return nil, nil
}

func (c *MockActionCoordinator) Clear() {
c.performedActions = 0
c.performedActions.Store(0)
}

type MockAcker struct {
Expand Down Expand Up @@ -205,7 +207,7 @@ func TestActionUnenrollHandler(t *testing.T) {
if tc.wantErr == nil {
require.Len(t, acker.Acked, 1)
}
require.Equal(t, tc.wantPerformedActions, coord.performedActions)
require.Equal(t, tc.wantPerformedActions, coord.performedActions.Load())
})
}
}

0 comments on commit 2a3dfaa

Please sign in to comment.