taskbuffer/test/test.2.taskchain.ts

49 lines
1.3 KiB
TypeScript
Raw 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;
2017-06-17 14:56:33 +00:00
let task1 = new taskbuffer.Task({
taskFunction: async () => {
2018-08-04 15:53:22 +00:00
await smartdelay.delayFor(2000);
task1Executed = true;
2017-06-17 14:56:33 +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;
2017-06-17 14:56:33 +00:00
let task2 = new taskbuffer.Task({
taskFunction: async () => {
2018-08-04 15:53:22 +00:00
await smartdelay.delayFor(2000);
task2Executed = true;
2017-06-17 14:56:33 +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;
2017-06-17 14:56:33 +00:00
let task3 = new taskbuffer.Task({
taskFunction: async () => {
2018-08-04 15:53:22 +00:00
await smartdelay.delayFor(2000);
task3Executed = true;
2017-06-17 14:56:33 +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 () => {
let testTaskchain = new taskbuffer.Taskchain({
name: 'Taskchain1',
2018-08-04 15:53:22 +00:00
taskArray: [task1, task2, task3]
});
let testPromise = testTaskchain.trigger();
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();