Skip to content

Commit

Permalink
Ukflake TestFunctionsConnectorHandler (#13916)
Browse files Browse the repository at this point in the history
Wait for the handler to be called before proceeding.
  • Loading branch information
bolekk authored Jul 23, 2024
1 parent 4565fef commit 518350d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions core/services/functions/connector_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,18 @@ func TestFunctionsConnectorHandler(t *testing.T) {
// first call to trigger the request
var response functions.HeartbeatResponse
allowlist.On("Allow", addr).Return(true).Once()
listener.On("HandleOffchainRequest", mock.Anything, mock.Anything).Return(nil).Once()
handlerCalled := make(chan struct{})
listener.On("HandleOffchainRequest", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
handlerCalled <- struct{}{}
}).Return(nil).Once()
connector.On("SendToGateway", mock.Anything, "gw1", mock.Anything).Run(func(args mock.Arguments) {
respMsg, ok := args[2].(*api.Message)
require.True(t, ok)
require.NoError(t, json.Unmarshal(respMsg.Body.Payload, &response))
require.Equal(t, functions.RequestStatePending, response.Status)
}).Return(nil).Once()
handler.HandleGatewayMessage(ctx, "gw1", msg)
<-handlerCalled

// async response computation
reportCh <- &functions.OffchainResponse{
Expand Down Expand Up @@ -304,9 +308,13 @@ func TestFunctionsConnectorHandler(t *testing.T) {
// first call to trigger the request
var response functions.HeartbeatResponse
allowlist.On("Allow", addr).Return(true).Once()
listener.On("HandleOffchainRequest", mock.Anything, mock.Anything).Return(errors.New("boom")).Once()
handlerCalled := make(chan struct{})
listener.On("HandleOffchainRequest", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
handlerCalled <- struct{}{}
}).Return(errors.New("boom")).Once()
connector.On("SendToGateway", mock.Anything, "gw1", mock.Anything).Return(nil).Once()
handler.HandleGatewayMessage(ctx, "gw1", msg)
<-handlerCalled

// collect the response - should eventually result in an internal error
gomega.NewGomegaWithT(t).Eventually(func() bool {
Expand Down

0 comments on commit 518350d

Please sign in to comment.