Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samsondav committed Dec 20, 2023
1 parent a48e64e commit 894c466
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
13 changes: 12 additions & 1 deletion core/services/relay/evm/mercury/wsrpc/cache/cache_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (

func Test_CacheSet(t *testing.T) {
lggr := logger.TestLogger(t)
cs := newCacheSet(lggr, Config{})
cs := newCacheSet(lggr, Config{LatestReportTTL: 1})
disabledCs := newCacheSet(lggr, Config{LatestReportTTL: 0})
ctx := testutils.Context(t)
servicetest.Run(t, cs)

Expand All @@ -22,6 +23,16 @@ func Test_CacheSet(t *testing.T) {

var err error
var f Fetcher
t.Run("with caching disabled, returns the passed client", func(t *testing.T) {
assert.Len(t, disabledCs.caches, 0)

f, err = disabledCs.Get(ctx, c)
require.NoError(t, err)

assert.Same(t, c, f)
assert.Len(t, disabledCs.caches, 0)
})

t.Run("with virgin cacheset, makes new entry and returns it", func(t *testing.T) {
assert.Len(t, cs.caches, 0)

Expand Down
15 changes: 6 additions & 9 deletions core/services/relay/evm/mercury/wsrpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Test_Client_Transmit(t *testing.T) {

noopCacheSet := newNoopCacheSet()

t.Run("sends on reset channel after MaxConsecutiveTransmitFailures timed out transmits", func(t *testing.T) {
t.Run("sends on reset channel after MaxConsecutiveRequestFailures timed out transmits", func(t *testing.T) {
calls := 0
transmitErr := context.DeadlineExceeded
wsrpcClient := &mocks.MockWSRPCClient{
Expand All @@ -70,19 +70,19 @@ func Test_Client_Transmit(t *testing.T) {
c.conn = conn
c.rawClient = wsrpcClient
require.NoError(t, c.StartOnce("Mock WSRPC Client", func() error { return nil }))
for i := 1; i < MaxConsecutiveTransmitFailures; i++ {
for i := 1; i < MaxConsecutiveRequestFailures; i++ {
_, err := c.Transmit(ctx, req)
require.EqualError(t, err, "context deadline exceeded")
}
assert.Equal(t, 4, calls)
assert.Equal(t, MaxConsecutiveRequestFailures-1, calls)
select {
case <-c.chResetTransport:
t.Fatal("unexpected send on chResetTransport")
default:
}
_, err := c.Transmit(ctx, req)
require.EqualError(t, err, "context deadline exceeded")
assert.Equal(t, 5, calls)
assert.Equal(t, MaxConsecutiveRequestFailures, calls)
select {
case <-c.chResetTransport:
default:
Expand All @@ -94,14 +94,14 @@ func Test_Client_Transmit(t *testing.T) {
// working transmit to reset counter
_, err = c.Transmit(ctx, req)
require.NoError(t, err)
assert.Equal(t, 6, calls)
assert.Equal(t, MaxConsecutiveRequestFailures+1, calls)
assert.Equal(t, 0, int(c.consecutiveTimeoutCnt.Load()))
})

t.Run("doesn't block in case channel is full", func(t *testing.T) {
transmitErr = context.DeadlineExceeded
c.chResetTransport = nil // simulate full channel
for i := 0; i < MaxConsecutiveTransmitFailures; i++ {
for i := 0; i < MaxConsecutiveRequestFailures; i++ {
_, err := c.Transmit(ctx, req)
require.EqualError(t, err, "context deadline exceeded")
}
Expand Down Expand Up @@ -162,10 +162,7 @@ func Test_Client_LatestReport(t *testing.T) {

// simulate start without dialling
require.NoError(t, c.StartOnce("Mock WSRPC Client", func() error { return nil }))
var err error
servicetest.Run(t, cacheSet)
c.cache, err = cacheSet.Get(ctx, c)
require.NoError(t, err)

for i := 0; i < 5; i++ {
r, err := c.LatestReport(ctx, req)
Expand Down

0 comments on commit 894c466

Please sign in to comment.