Skip to content

Commit

Permalink
fix keystone e2e test dispatcher to correctly replicate duplicate reg…
Browse files Browse the repository at this point in the history
…istration behaviour (#14018)
  • Loading branch information
ettec authored Aug 2, 2024
1 parent 2a032e8 commit 82accff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-adults-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#internal fix to keystone e2e test dispatcher to correctly mock duplicate registration error
19 changes: 19 additions & 0 deletions core/capabilities/integration_tests/mock_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/remote"
remotetypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/remote/types"
p2ptypes "github.com/smartcontractkit/chainlink/v2/core/services/p2p/types"

Expand Down Expand Up @@ -58,6 +59,7 @@ func (a *testAsyncMessageBroker) NewDispatcherForNode(nodePeerID p2ptypes.PeerID
return &brokerDispatcher{
callerPeerID: nodePeerID,
broker: a,
receivers: map[key]remotetypes.Receiver{},
}
}

Expand Down Expand Up @@ -158,6 +160,14 @@ type broker interface {
type brokerDispatcher struct {
callerPeerID p2ptypes.PeerID
broker broker

receivers map[key]remotetypes.Receiver
mu sync.Mutex
}

type key struct {
capId string
donId uint32
}

func (t *brokerDispatcher) Send(peerID p2ptypes.PeerID, msgBody *remotetypes.MessageBody) error {
Expand All @@ -171,6 +181,15 @@ func (t *brokerDispatcher) Send(peerID p2ptypes.PeerID, msgBody *remotetypes.Mes
}

func (t *brokerDispatcher) SetReceiver(capabilityId string, donId uint32, receiver remotetypes.Receiver) error {
t.mu.Lock()
defer t.mu.Unlock()
k := key{capabilityId, donId}
_, ok := t.receivers[k]
if ok {
return fmt.Errorf("%w: receiver already exists for capability %s and don %d", remote.ErrReceiverExists, capabilityId, donId)
}
t.receivers[k] = receiver

t.broker.(*testAsyncMessageBroker).registerReceiverNode(t.callerPeerID, capabilityId, donId, receiver)
return nil
}
Expand Down

0 comments on commit 82accff

Please sign in to comment.