source: trip-planner-front/node_modules/qjobs/tests/events.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#!/usr/bin/env node
2var assert = require('assert');
3var qjob = require('../qjobs');
4
5var maxConcurrency = 2;
6var q = new qjob({maxConcurrency:maxConcurrency});
7
8var testExecutedJobs = 0;
9var testStartFired = false;
10var testEndFired = false;
11var testJobsStartFired = 0;
12var testJobsEndFired = 0;
13var testConcurrency = 0;
14
15var myjob = function(args,next) {
16 setTimeout(function() {
17 testExecutedJobs++;
18 next();
19 },50);
20}
21
22// Let's add 10 job and add them to the queue
23for (var i = 0; i<10; i++) {
24 q.add(myjob,['test'+i]);
25}
26
27q.on('start',function() {
28 testStartFired = true;
29});
30
31q.on('jobStart',function() {
32 var running = q.stats()._jobsRunning;
33 if (running>testConcurrency) testConcurrency = running;
34 testJobsStartFired++;
35});
36
37q.on('jobEnd',function() {
38 testJobsEndFired++;
39});
40
41q.on('end',function() {
42 testEndFired = true;
43 assert.equal(testExecutedJobs, 10);
44 assert.equal(testJobsStartFired,10);
45 assert.equal(testJobsEndFired,10);
46 assert.equal(testConcurrency,maxConcurrency);
47 assert.ok(testStartFired);
48});
49
50var running = q.stats()._jobsRunning;
51
52assert.equal(testExecutedJobs,0);
53assert.equal(testJobsStartFired,0);
54assert.equal(testJobsEndFired,0);
55assert.equal(running,0);
56assert.ok(!testStartFired);
57assert.ok(!testEndFired);
58
59q.run();
Note: See TracBrowser for help on using the repository browser.