Skip to content

Commit

Permalink
fixing test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Chengxuan Xing <[email protected]>
  • Loading branch information
Chengxuan committed Sep 5, 2024
1 parent ed72634 commit 7f002f4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 4 additions & 1 deletion internal/ethereum/blocklistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@ func (bl *blockListener) waitClosed() {
bl.wsBackend.Close()
}
if listenLoopDone != nil {
<-listenLoopDone
select {
case <-listenLoopDone:
case <-bl.ctx.Done():
}
}
}
4 changes: 2 additions & 2 deletions internal/ethereum/event_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func newTestListener(t *testing.T, withMethods bool) (*listener, *rpcbackendmock

func TestGetInitialBlockTimeout(t *testing.T) {

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
defer cancel()

_, c, mRPC, done := newTestConnector(t)
Expand All @@ -141,7 +141,7 @@ func TestGetInitialBlockTimeout(t *testing.T) {

func TestGetHWMNotInit(t *testing.T) {

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
defer cancel()

_, c, mRPC, done := newTestConnector(t)
Expand Down
26 changes: 26 additions & 0 deletions internal/ethereum/event_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,32 @@ func TestLeadGroupCatchupRetry(t *testing.T) {

<-retried

}
func TestLeadGroupCatchupExitWhenNoBlockHeightEstablished(t *testing.T) {

l1req := &ffcapi.EventListenerAddRequest{
ListenerID: fftypes.NewUUID(),
EventListenerOptions: ffcapi.EventListenerOptions{
Filters: []fftypes.JSONAny{
*fftypes.JSONAnyPtr(`{"event":` + abiTransferEvent + `}`),
},
Options: fftypes.JSONAnyPtr(`{}`),
FromBlock: "0",
},
}
ctx, c, mRPC, cDone := newTestConnector(t)

attempted := make(chan struct{})
mRPC.On("CallRPC", mock.Anything, mock.Anything, "eth_blockNumber").Return(&rpcbackend.RPCError{Message: "pop"}).Run(func(args mock.Arguments) {
close(attempted)
cDone()
}).Once()

mRPC.On("CallRPC", mock.Anything, mock.Anything, "eth_blockNumber").Return(&rpcbackend.RPCError{Message: "pop"}).Maybe()
_, _, mRPC, done := testEventStreamExistingConnector(t, ctx, cDone, c, mRPC, l1req)
defer done()
<-attempted

}

func TestStreamLoopNewFilterFail(t *testing.T) {
Expand Down

0 comments on commit 7f002f4

Please sign in to comment.