Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Apr 23, 2024
1 parent feb4c10 commit c834134
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/update-feeds-loops/updatability-timestamp.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { generateTestConfig, initializeState } from '../../test/fixtures/mock-config';
import { getState } from '../state';

import { clearFirstMarkedUpdatableTimestamp, setFirstMarkedUpdatableTimestamp } from './updatability-timestamp';
import {
clearFirstMarkedUpdatableTimestamp,
initializeFirstMarkedUpdatableTimestamp,
setFirstMarkedUpdatableTimestamp,
} from './updatability-timestamp';

const chainId = '31337';
const providerName = 'localhost';
Expand All @@ -11,6 +15,7 @@ const sponsorWalletAddress = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';

beforeEach(() => {
initializeState(generateTestConfig());
initializeFirstMarkedUpdatableTimestamp(chainId, providerName);
});

describe(setFirstMarkedUpdatableTimestamp.name, () => {
Expand Down
8 changes: 4 additions & 4 deletions src/update-feeds-loops/update-feeds-loops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ describe(updateFeedsLoopsModule.runUpdateFeeds.name, () => {
'provider-name',
allowPartial<Chain>({
dataFeedBatchSize: 1,
dataFeedUpdateInterval: 0.15,
dataFeedUpdateInterval: 0.3, // 300ms update interval to make the test run quicker.
providers: { ['provider-name']: { url: 'provider-url' } },
contracts: {
AirseekerRegistry: '0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0',
Expand All @@ -261,11 +261,11 @@ describe(updateFeedsLoopsModule.runUpdateFeeds.name, () => {
expect(utilsModule.sleep).toHaveBeenCalledTimes(3);
expect(sleepCalls[0]).toBeGreaterThan(0); // The first stagger time is computed dynamically (the execution time is subtracted from the interval time) which is slow on CI, so we just check it's non-zero.
expect(sleepCalls[1]).toBe(0);
expect(sleepCalls[2]).toBe(50);
expect(sleepCalls[2]).toBe(100);

// Expect the call times of processBatch to be staggered as well.
expect(updateFeedsLoopsModule.processBatch).toHaveBeenCalledTimes(2);
expect(processBatchCalls[1]! - processBatchCalls[0]!).toBeGreaterThan(100 - 20); // The stagger time is 50ms, but second batch fails to load which means the third second processBatch call needs to happen after we wait for 2 stagger times. We add some buffer to account for processing delays.
expect(processBatchCalls[1]! - processBatchCalls[0]!).toBeGreaterThan(200 - 20); // The stagger time is 100ms, but second batch fails to load which means the third second processBatch call needs to happen after we wait for 2 stagger times. We add some buffer to account for processing delays.

// Expect the logs to be called with the correct context.
expect(logger.error).toHaveBeenCalledTimes(1);
Expand All @@ -282,7 +282,7 @@ describe(updateFeedsLoopsModule.runUpdateFeeds.name, () => {
expect(logger.debug).toHaveBeenNthCalledWith(4, 'Fetching gas price and saving it to the state.');
expect(logger.debug).toHaveBeenNthCalledWith(5, 'Fetching batches of active data feeds.', {
batchesCount: 3,
staggerTimeMs: 50,
staggerTimeMs: 100,
});
expect(logger.debug).toHaveBeenNthCalledWith(6, 'Fetching batch of active data feeds.', {
batchIndex: 1,
Expand Down

0 comments on commit c834134

Please sign in to comment.