source: trip-planner-front/node_modules/qjobs/tests/interval.js@ b738035

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

initial commit

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[6a3a178]1#!/usr/bin/env node
2var assert = require('assert');
3var qjob = require('../qjobs');
4
5// maximum number of jobs executed in parallels
6var maxConcurrency = 5;
7
8// delay between each group of maxConcurrency jobs done
9var interval = 1000;
10
11var q = new qjob({
12 maxConcurrency:maxConcurrency,
13 interval:interval
14});
15
16// number of total jobs
17var maxJobs = 20;
18
19// tests dedicated variables
20var testExecutedJobs = 0;
21var testNbSleep = 0;
22
23// warning, if you change maxConcurrency, maxJobs
24// or interval variable, you will have to review
25// the testMaxNbSleep value
26var testMaxNbSleep = 4;
27
28var myjob = function(args,next) {
29 setTimeout(function() {
30 testExecutedJobs++;
31 next();
32 },args[1]);
33}
34
35// Let's add 10 job and add them to the queue
36for (var i = 0; i<maxJobs; i++) {
37 q.add(myjob,['test'+i,Math.random()*1000]);
38}
39
40q.on('end',function() {
41 assert.equal(testExecutedJobs, maxJobs);
42 assert.equal(testNbSleep, testMaxNbSleep);
43 //console.log('Done');
44});
45
46q.on('jobStart',function(args) {
47 //console.log(args[0]+' wait for '+args[1]+' ms');
48});
49
50q.on('sleep',function() {
51 testNbSleep++;
52 //console.log('zzZZzzzz for '+interval+'ms',testNbSleep);
53});
54
55q.on('continu',function() {
56 //console.log('WAKE !');
57});
58
59q.run();
60
61
Note: See TracBrowser for help on using the repository browser.