Skip to content

Commit

Permalink
test: 💍 add test
Browse files Browse the repository at this point in the history
  • Loading branch information
waynewyang committed Jan 2, 2024
1 parent 05f8c8e commit 9b3d571
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/backgroundTask/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { delay } from '@unipackage/utils';
* BackgroundTask class implementing the IBackgroundTask interface.
*/
export class BackgroundTask implements IBackgroundTask {
private context: IContext;
context: IContext;
private syncer: ISyncer;
private decoder: IDecoder;
private storager: IStorager;
Expand Down
29 changes: 25 additions & 4 deletions test/backgroundTask/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { calibrationBgTask } from '../../src/config/backgroundTask';
import { delay } from '@unipackage/utils';

describe('BackgroundTask', () => {
beforeAll(() => {
Expand All @@ -9,9 +10,29 @@ describe('BackgroundTask', () => {
calibrationBgTask.stop();
});

it('should stop the background task', () => {
it('should stop the background task', async () => {
expect(calibrationBgTask.isRunning()).toBe(true);
calibrationBgTask.stop();
expect(calibrationBgTask.isRunning()).toBe(false);
});

const startHeight = calibrationBgTask.getStartHeight();
expect(startHeight).toBe(1213437);

const startSyncHeight = calibrationBgTask.getCurrentSyncHeight();
await delay(20000);
const endSyncHeight = calibrationBgTask.getCurrentSyncHeight();
expect(endSyncHeight - startSyncHeight > 0).toBe(true);

const tipsets = await calibrationBgTask.context.datastore.tipset.find({});
const blocks = await calibrationBgTask.context.datastore.block.find({});
const messages = await calibrationBgTask.context.datastore.message.find({});
const dataswapMessages =
await calibrationBgTask.context.datastore.dataswapMessage.find({});
const datasetMetadata =
await calibrationBgTask.context.datastore.datasetMetadata.find({});

expect(tipsets.data.length > 0).toBe(true);
expect(blocks.data.length > 0).toBe(true);
expect(messages.data.length > 0).toBe(true);
expect(dataswapMessages.data.length > 0).toBe(true);
expect(datasetMetadata.data.length > 0).toBe(true);
}, 100000);
});

0 comments on commit 9b3d571

Please sign in to comment.