Skip to content

Commit

Permalink
test: add a test for deferred jobs
Browse files Browse the repository at this point in the history
Just one more bit of coverage.
  • Loading branch information
hansl committed Feb 7, 2019
1 parent 02f7b03 commit 063525f
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -590,5 +590,36 @@ describe('SimpleScheduler', () => {
expect(await job.output.toPromise()).toBe(103);
expect(outputs).toEqual([101, 103]);
});

it('works deferred', async () => {
// This is a more complex test. The job returns an output deferred from the input
registry.register(
'job',
createJobHandler<number, number, number>((argument, context) => {
return new Observable<number>(subscriber => {
context.input.subscribe(x => {
if (x === null) {
setTimeout(() => subscriber.complete(), 10);
} else {
setTimeout(() => subscriber.next(parseInt('' + x) + argument), x);
}
});
});
}),
);

const job = scheduler.schedule('job', 100);
const outputs: number[] = [];

job.output.subscribe(x => outputs.push(x as number));

job.input.next(1);
job.input.next(2);
job.input.next(3);
job.input.next(null);

expect(await job.output.toPromise()).toBe(103);
expect(outputs).toEqual(jasmine.arrayWithExactContents([101, 102, 103]));
});
});
});

0 comments on commit 063525f

Please sign in to comment.