Skip to content

Commit 189de17

Browse files
committed
Fix flaky test
1 parent 3566800 commit 189de17

File tree

1 file changed

+39
-29
lines changed

1 file changed

+39
-29
lines changed

indexer/services/ender/__tests__/lib/candles-generator.test.ts

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,16 @@ describe('candleHelper', () => {
485485
const usdVolume: string = Big(existingPrice).times(baseTokenVolume).toString();
486486
const orderbookMidPriceClose = '7500';
487487
const orderbookMidPriceOpen = '8000';
488+
// Set candle start time to be far in the past to ensure all candles are new
489+
const startTime: IsoString = helpers.calculateNormalizedCandleStartTime(
490+
testConstants.createdDateTime.minus({ minutes: 100 }),
491+
CandleResolution.ONE_MINUTE,
492+
).toISO();
493+
488494
await Promise.all(
489495
_.map(Object.values(CandleResolution), (resolution: CandleResolution) => {
490496
return CandleTable.create({
491-
startedAt: previousStartedAt,
497+
startedAt: startTime,
492498
ticker: testConstants.defaultPerpetualMarket.ticker,
493499
resolution,
494500
low: existingPrice,
@@ -508,40 +514,39 @@ describe('candleHelper', () => {
508514

509515
setCachePrice('BTC-USD', '10005');
510516
await OrderbookMidPriceMemoryCache.updateOrderbookMidPrices();
511-
517+
// Add two trades for BTC-USD market
512518
const publisher: KafkaPublisher = new KafkaPublisher();
513519
publisher.addEvents([
514520
defaultTradeKafkaEvent,
515521
defaultTradeKafkaEvent2,
516522
]);
517523

518524
// Create new candles, with trades
519-
await runUpdateCandles(publisher).then(async () => {
520-
521-
// Verify previous candles have orderbookMidPriceClose updated
522-
const previousExpectedCandles: CandleFromDatabase[] = _.map(
523-
Object.values(CandleResolution),
524-
(resolution: CandleResolution) => {
525-
return {
526-
id: CandleTable.uuid(previousStartedAt, defaultCandle.ticker, resolution),
527-
startedAt: previousStartedAt,
528-
ticker: defaultCandle.ticker,
529-
resolution,
530-
low: existingPrice,
531-
high: existingPrice,
532-
open: existingPrice,
533-
close: existingPrice,
534-
baseTokenVolume,
535-
usdVolume,
536-
trades: existingTrades,
537-
startingOpenInterest,
538-
orderbookMidPriceClose: '10005',
539-
orderbookMidPriceOpen,
540-
};
541-
},
542-
);
543-
await verifyCandlesInPostgres(previousExpectedCandles);
544-
});
525+
await runUpdateCandles(publisher);
526+
527+
// Verify previous candles have orderbookMidPriceClose updated
528+
const previousExpectedCandles: CandleFromDatabase[] = _.map(
529+
Object.values(CandleResolution),
530+
(resolution: CandleResolution) => {
531+
return {
532+
id: CandleTable.uuid(startTime, defaultCandle.ticker, resolution),
533+
startedAt: startTime,
534+
ticker: defaultCandle.ticker,
535+
resolution,
536+
low: existingPrice,
537+
high: existingPrice,
538+
open: existingPrice,
539+
close: existingPrice,
540+
baseTokenVolume,
541+
usdVolume,
542+
trades: existingTrades,
543+
startingOpenInterest,
544+
orderbookMidPriceClose: '10005',
545+
orderbookMidPriceOpen,
546+
};
547+
},
548+
);
549+
await verifyCandlesInPostgres(previousExpectedCandles);
545550

546551
// Verify new candles were created
547552
const expectedCandles: CandleFromDatabase[] = _.map(
@@ -583,11 +588,16 @@ describe('candleHelper', () => {
583588
const usdVolume: string = Big(existingPrice).times(baseTokenVolume).toString();
584589
const orderbookMidPriceClose = '7500';
585590
const orderbookMidPriceOpen = '8000';
591+
// Set candle start time to be far in the past to ensure all candles are new
592+
const startTime: IsoString = helpers.calculateNormalizedCandleStartTime(
593+
testConstants.createdDateTime.minus({ minutes: 100 }),
594+
CandleResolution.ONE_MINUTE,
595+
).toISO();
586596

587597
await Promise.all(
588598
_.map(Object.values(CandleResolution), (resolution: CandleResolution) => {
589599
return CandleTable.create({
590-
startedAt: previousStartedAt,
600+
startedAt: startTime,
591601
ticker: testConstants.defaultPerpetualMarket.ticker,
592602
resolution,
593603
low: existingPrice,

0 commit comments

Comments
 (0)