taskbuffer/test/test.2.taskchain.ts

49 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2018-08-04 15:53:22 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
import taskbuffer = require('../ts/index');
2017-06-17 14:56:33 +00:00
2019-01-14 23:17:44 +00:00
import * as smartpromise from '@pushrocks/smartpromise';
2018-08-04 15:53:22 +00:00
import * as smartdelay from '@pushrocks/smartdelay';
2017-06-17 14:56:33 +00:00
2018-08-04 15:53:22 +00:00
let task1Executed = false;
2019-09-22 13:16:27 +00:00
const task1 = new taskbuffer.Task({
2017-06-17 14:56:33 +00:00
taskFunction: async () => {
2018-08-04 15:53:22 +00:00
await smartdelay.delayFor(2000);
task1Executed = true;
2020-07-12 00:48:51 +00:00
},
2018-08-04 15:53:22 +00:00
});
2017-06-17 14:56:33 +00:00
2018-08-04 15:53:22 +00:00
let task2Executed = false;
2019-09-22 13:16:27 +00:00
const task2 = new taskbuffer.Task({
2017-06-17 14:56:33 +00:00
taskFunction: async () => {
2018-08-04 15:53:22 +00:00
await smartdelay.delayFor(2000);
task2Executed = true;
2020-07-12 00:48:51 +00:00
},
2018-08-04 15:53:22 +00:00
});
2017-06-17 14:56:33 +00:00
2018-08-04 15:53:22 +00:00
let task3Executed = false;
2019-09-22 13:16:27 +00:00
const task3 = new taskbuffer.Task({
2017-06-17 14:56:33 +00:00
taskFunction: async () => {
2018-08-04 15:53:22 +00:00
await smartdelay.delayFor(2000);
task3Executed = true;
2020-07-12 00:48:51 +00:00
},
2018-08-04 15:53:22 +00:00
});
2017-06-17 14:56:33 +00:00
tap.test('expect run tasks in sequence', async () => {
2019-09-22 13:16:27 +00:00
const testTaskchain = new taskbuffer.Taskchain({
2017-06-17 14:56:33 +00:00
name: 'Taskchain1',
2020-07-12 00:48:51 +00:00
taskArray: [task1, task2, task3],
2018-08-04 15:53:22 +00:00
});
2019-09-22 13:16:27 +00:00
const testPromise = testTaskchain.trigger();
2018-08-04 15:53:22 +00:00
await smartdelay.delayFor(2100);
2017-06-17 14:56:33 +00:00
// tslint:disable-next-line:no-unused-expression
2018-08-04 15:53:22 +00:00
expect(task1Executed).to.be.true;
2017-06-17 14:56:33 +00:00
// tslint:disable-next-line:no-unused-expression
2018-08-04 15:53:22 +00:00
expect(task2Executed).to.be.false;
await smartdelay.delayFor(2100);
2017-06-17 14:56:33 +00:00
// tslint:disable-next-line:no-unused-expression
2018-08-04 15:53:22 +00:00
expect(task2Executed).to.be.true;
await testPromise;
});
2017-06-17 14:56:33 +00:00
2018-08-04 15:53:22 +00:00
tap.start();