Skip to content

Commit 04e43c4

Browse files
committed
test cache invalidation
1 parent f835b58 commit 04e43c4

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

commit/chainfee/outcome_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package chainfee
22

33
import (
4+
"context"
45
"math/big"
6+
"sync"
57
"testing"
68
"time"
79

810
"github.com/smartcontractkit/chainlink-ccip/internal"
11+
"github.com/smartcontractkit/chainlink-ccip/pkg/consts"
912

1013
"github.com/stretchr/testify/mock"
1114

@@ -431,3 +434,46 @@ func TestProcessor_Outcome(t *testing.T) {
431434
})
432435
}
433436
}
437+
438+
func TestProcessor_Outcome_cacheInvalidation(t *testing.T) {
439+
lggr := logger.Test(t)
440+
ctx := tests.Context(t)
441+
442+
obs := &asyncObserver{
443+
lggr: lggr,
444+
cancelFunc: nil,
445+
mu: &sync.RWMutex{},
446+
triggerSyncChan: make(chan time.Time),
447+
}
448+
449+
p := &processor{
450+
lggr: lggr,
451+
obs: obs,
452+
}
453+
454+
obs.mu.Lock()
455+
obs.chainFeePriceUpdates = map[cciptypes.ChainSelector]Update{1: {}}
456+
obs.mu.Unlock()
457+
458+
// cache is not invalidated with a normal context
459+
_, _ = p.Outcome(ctx, Outcome{}, Query{}, nil)
460+
updates := obs.getChainFeePriceUpdates(ctx, lggr)
461+
require.Len(t, updates, 1)
462+
463+
// cache is not invalidated with invalidation context set to false
464+
ctx = context.WithValue(ctx, consts.InvalidateCacheKey, false)
465+
_, _ = p.Outcome(ctx, Outcome{}, Query{}, nil)
466+
updates = obs.getChainFeePriceUpdates(ctx, lggr)
467+
require.Len(t, updates, 1)
468+
469+
// cache is invalidated with invalidation context set to true and a sync op is triggered
470+
wg := sync.WaitGroup{}
471+
go func() {
472+
<-obs.triggerSyncChan
473+
}()
474+
ctx = context.WithValue(ctx, consts.InvalidateCacheKey, true)
475+
_, _ = p.Outcome(ctx, Outcome{}, Query{}, nil)
476+
updates = obs.getChainFeePriceUpdates(ctx, lggr)
477+
require.Len(t, updates, 0)
478+
wg.Wait() // wait until receiving the sync operation signal
479+
}

0 commit comments

Comments
 (0)