diff options
author | Pablo Núñez <pablonete@gmail.com> | 2019-04-08 00:25:07 +0200 |
---|---|---|
committer | Alex Early <alexander.early@gmail.com> | 2019-04-07 15:25:07 -0700 |
commit | 4330d536c106592139fa82062494c9dba0da1fdb (patch) | |
tree | 6c1120c134349b1375d7bb33ce558fae909e18ec /test | |
parent | a4c00358cf3c638398735f4006b65e3a82d80ca9 (diff) | |
download | async-4330d536c106592139fa82062494c9dba0da1fdb.tar.gz |
chore: Add Azure Pipelines for CI (Windows, Linux, Mac) (#1630), Fix async function serialization in Safari.
* Add azure pipelines CI.
* Publish test results.
* Enable coveralls
* Use Safari for OSX browser tests.
* Adding missing lib files to karma (only Safari complained).
* Rename with dot so it gets better placed in order.
* Use ci instead of install, so we stick with package-lock.json
* Use npm test instead of mocha directly. It just needed a double -- escape.
* Move DISPLAY to Linux only, with value set just once.
* Use variables for DISPLAY, browser tests and coveralls.
* Simplify steps with a browser name variable.
* Run junit reporter on CI only.
* DISPLAY should be already an environment variable.
* Use vmImage for consistency with other OS.
* Don't use verbose npm@1 task.
* No need to setTimeout, let's `done` on the callback.
* Don't resume twice.
Check queue length on callback for safety, setTimeout may be delayed.
* Avoid time dependency, act on events instead.
* Avoid dependency on timing to final assertion.
* Rewrite test to avoid setTimeout
* Fix formatting.
* Make diff more significant (125+50 ~= 200)
* Make diff more significant to avoid race conditions.
* Wait a bit more so default 5 retries did happen.
* Make delays shorter to avoid "Timeout of 250ms exceeded"
* Shorten delay to avoid 200ms test timeout in browser tests.
* Shorten timeout to mitigate 200ms test timeout.
* Add more diff on delays to enforce test behavior.
* Make delays more significant to avoid race conditions.
* Stop using setTimeout and rely on events to push new items, so order is enforced.
* Fix async function serialization in Safari.
* Add more delay so 4 never completes before 3.
* Ensure 3 never completes before 4.
* Use drain instead of task count.
Trying to ensure done is called from Windows browser tests that fail frequently.
* Ensure 2 starts before 3 arrives.Avoid expected 'process 2 3' to equal 'process 2'
* Add retries to browser tests.
* Don't fail all on Mac & Windows browser tests.
* Ensure 3 happens before 2, it fails sparely on OSX.
AssertionError: expected [ 1, 2, 3 ] to deeply equal [ 1, 3, 2 ]
* Avoid unnecessary multilines.
* Use Edge for Windows browser tests.
Diffstat (limited to 'test')
-rw-r--r-- | test/cargo.js | 23 | ||||
-rw-r--r-- | test/cargoQueue.js | 64 | ||||
-rw-r--r-- | test/concat.js | 2 | ||||
-rw-r--r-- | test/detect.js | 10 | ||||
-rw-r--r-- | test/es2017/asyncFunctions.js | 8 | ||||
-rw-r--r-- | test/es2017/asyncGenerators.js | 4 | ||||
-rw-r--r-- | test/parallel.js | 6 | ||||
-rw-r--r-- | test/priorityQueue.js | 4 | ||||
-rw-r--r-- | test/queue.js | 20 | ||||
-rw-r--r-- | test/retry.js | 2 | ||||
-rw-r--r-- | test/support/get_function_object.js | 2 | ||||
-rw-r--r-- | test/timeout.js | 10 |
12 files changed, 77 insertions, 78 deletions
diff --git a/test/cargo.js b/test/cargo.js index fc377fe..2191eb8 100644 --- a/test/cargo.js +++ b/test/cargo.js @@ -72,7 +72,7 @@ describe('cargo', () => { it('without callback', (done) => { var call_order = [], - delays = [40,20,60,20]; + delays = [40,60,60,20]; // worker: --1-2---34-5- // order of completion: 1,2,3,4,5 @@ -88,14 +88,14 @@ describe('cargo', () => { setTimeout(() => { c.push(2); - }, 30); + }, 20); setTimeout(() => { c.push(3); c.push(4); c.push(5); - }, 50); + }, 80); - setTimeout(() => { + c.drain = function() { expect(call_order).to.eql([ 'process 1', 'process 2', @@ -103,7 +103,7 @@ describe('cargo', () => { 'process 5' ]); done(); - }, 200); + } }); it('bulk task', (done) => { @@ -174,15 +174,16 @@ describe('cargo', () => { var drainCounter = 0; c.drain = function () { drainCounter++; + + if (drainCounter === 1) { + loadCargo(); + } else { + expect(drainCounter).to.equal(2); + done(); + } }; loadCargo(); - setTimeout(loadCargo, 50); - - setTimeout(() => { - expect(drainCounter).to.equal(2); - done(); - }, 100); }); it('events', (done) => { diff --git a/test/cargoQueue.js b/test/cargoQueue.js index 3ff7f18..517422c 100644 --- a/test/cargoQueue.js +++ b/test/cargoQueue.js @@ -11,12 +11,35 @@ describe('cargoQueue', () => { it('cargoQueue', (done) => { var call_order = [], - delays = [40, 40, 20]; + delays = [50, 50, 50]; // worker: --12--34--5- // order of completion: 1,2,3,4,5 var c = async.cargoQueue((tasks, callback) => { + if (tasks[0] === 1) { + c.push(3, (err, arg) => { + expect(err).to.equal('error'); + expect(arg).to.equal('arg'); + expect(c.length()).to.equal(0); + call_order.push('callback ' + 3); + }); + } else if (tasks[0] === 3) { + c.push(4, (err, arg) => { + expect(err).to.equal('error'); + expect(arg).to.equal('arg'); + expect(c.length()).to.equal(0); + call_order.push('callback ' + 4); + }); + expect(c.length()).to.equal(1); + c.push(5, (err, arg) => { + expect(err).to.equal('error'); + expect(arg).to.equal('arg'); + expect(c.length()).to.equal(0); + call_order.push('callback ' + 5); + }); + } + setTimeout(() => { call_order.push('process ' + tasks.join(' ')); callback('error', 'arg'); @@ -38,32 +61,6 @@ describe('cargoQueue', () => { expect(c.length()).to.equal(2); - // async push - setTimeout(() => { - c.push(3, (err, arg) => { - expect(err).to.equal('error'); - expect(arg).to.equal('arg'); - expect(c.length()).to.equal(0); - call_order.push('callback ' + 3); - }); - }, 15); - setTimeout(() => { - c.push(4, (err, arg) => { - expect(err).to.equal('error'); - expect(arg).to.equal('arg'); - expect(c.length()).to.equal(0); - call_order.push('callback ' + 4); - }); - expect(c.length()).to.equal(1); - c.push(5, (err, arg) => { - expect(err).to.equal('error'); - expect(arg).to.equal('arg'); - expect(c.length()).to.equal(0); - call_order.push('callback ' + 5); - }); - }, 30); - - c.drain = function () { expect(call_order).to.eql([ 'process 1 2', 'callback 1', 'callback 2', @@ -167,15 +164,16 @@ describe('cargoQueue', () => { var drainCounter = 0; c.drain = function () { drainCounter++; + + if (drainCounter === 1) { + loadCargo(); + } else { + expect(drainCounter).to.equal(2); + done(); + } }; loadCargo(); - setTimeout(loadCargo, 50); - - setTimeout(() => { - expect(drainCounter).to.equal(2); - done(); - }, 100); }); it('events', (done) => { diff --git a/test/concat.js b/test/concat.js index e42344b..bca05d7 100644 --- a/test/concat.js +++ b/test/concat.js @@ -387,7 +387,7 @@ describe('concat', function() { x--; } cb(null, r); - }, x*25); + }, x*10); }; async.concatSeries([1,3,2], iteratee, (err, results) => { expect(results).to.eql([1,3,2,1,2,1]); diff --git a/test/detect.js b/test/detect.js index 3351d9e..4663e29 100644 --- a/test/detect.js +++ b/test/detect.js @@ -71,11 +71,10 @@ describe("detect", () => { call_order.push('callback'); expect(err).to.equal(null); expect(result).to.equal(2); - }); - setTimeout(() => { + expect(call_order).to.eql([3,2,'callback']); done(); - }, 50); + }); }); it('detectSeries - multiple matches', function(done){ @@ -84,11 +83,10 @@ describe("detect", () => { call_order.push('callback'); expect(err).to.equal(null); expect(result).to.equal(2); - }); - setTimeout(() => { + expect(call_order).to.eql([3,2,'callback']); done(); - }, 50); + }); }); it('detect no callback', (done) => { diff --git a/test/es2017/asyncFunctions.js b/test/es2017/asyncFunctions.js index 59c0df8..efb6555 100644 --- a/test/es2017/asyncFunctions.js +++ b/test/es2017/asyncFunctions.js @@ -9,6 +9,8 @@ module.exports = function () { return res; } + this.retries(3); + const input = [1, 2, 3]; const inputObj = {a: 1, b: 2, c: 3}; @@ -303,8 +305,8 @@ module.exports = function () { /* eslint prefer-arrow-callback: 0, object-shorthand: 0 */ it('should handle async functions in autoInject', (done) => { async.autoInject({ - z: async function(){ return 0}, - a: async function a () { + z: async function () { return 0 }, + a: async function () { return await Promise.resolve(1); }, b: async function (a) { @@ -676,7 +678,7 @@ module.exports = function () { var fn = async.timeout(async (val) => { await new Promise((resolve) => setTimeout(resolve, 100)); return val; - }, 50); + }, 20); fn(1, (err) => { expect(err.message).to.match(/timed out/); done(); diff --git a/test/es2017/asyncGenerators.js b/test/es2017/asyncGenerators.js index c9be07e..61ac964 100644 --- a/test/es2017/asyncGenerators.js +++ b/test/es2017/asyncGenerators.js @@ -26,12 +26,14 @@ module.exports = function () { } } + this.retries(3); + it('should handle async generators in each', (done) => { const calls = [] async.each(range(5), async (val) => { calls.push(val) - await delay(5) + await delay(1) }, (err) => { if (err) throw err expect(calls).to.eql([0, 1, 2, 3, 4]) diff --git a/test/parallel.js b/test/parallel.js index e95e65c..067c6ce 100644 --- a/test/parallel.js +++ b/test/parallel.js @@ -143,19 +143,19 @@ describe('parallel', () => { setTimeout(() => { call_order.push(1); callback(null, 1); - }, 50); + }, 10); }, function(callback){ setTimeout(() => { call_order.push(2); callback(null, 2); - }, 100); + }, 180); }, function(callback){ setTimeout(() => { call_order.push(3); callback(null, 3,3); - }, 25); + }, 10); } ], 2, diff --git a/test/priorityQueue.js b/test/priorityQueue.js index e1c3b29..1a8cc76 100644 --- a/test/priorityQueue.js +++ b/test/priorityQueue.js @@ -55,7 +55,7 @@ describe('priorityQueue', () => { it('concurrency', (done) => { var call_order = [], - delays = [160,80,240,80]; + delays = [80,20,180,20]; // worker1: --2-3 // worker2: -1---4 @@ -65,7 +65,7 @@ describe('priorityQueue', () => { setTimeout(() => { call_order.push('process ' + task); callback('error', 'arg'); - }, delays.splice(0,1)[0]); + }, delays.shift()); }, 2); q.push(1, 1.4, (err, arg) => { diff --git a/test/queue.js b/test/queue.js index 2ac5077..f103aaa 100644 --- a/test/queue.js +++ b/test/queue.js @@ -10,8 +10,7 @@ describe('queue', function(){ it('basics', (done) => { var call_order = []; - var delays = [40,10,60,10]; - + var delays = [50,10,180,10]; // worker1: --1-4 // worker2: -2---3 @@ -66,7 +65,7 @@ describe('queue', function(){ it('default concurrency', (done) => { var call_order = [], - delays = [40,10,60,10]; + delays = [50,10,180,10]; // order of completion: 1,2,3,4 @@ -223,7 +222,7 @@ describe('queue', function(){ this.retries(3); // test can be flakey var call_order = []; - var delays = [40,10,60,10]; + var delays = [50,10,180,10]; var concurrencyList = []; var running = 0; @@ -300,7 +299,7 @@ describe('queue', function(){ it('bulk task', (done) => { var call_order = [], - delays = [40,10,60,10]; + delays = [50,10,180,10]; // worker1: --1-4 // worker2: -2---3 @@ -445,6 +444,11 @@ describe('queue', function(){ it('start paused', (done) => { var q = async.queue((task, callback) => { + if (task === 2) { + expect(q.length()).to.equal(1); + expect(q.running()).to.equal(2); + } + setTimeout(() => { callback(); }, 40); @@ -458,12 +462,6 @@ describe('queue', function(){ q.resume(); }, 5); - setTimeout(() => { - expect(q.length()).to.equal(1); - expect(q.running()).to.equal(2); - q.resume(); - }, 15); - q.drain = function () { done(); }; diff --git a/test/retry.js b/test/retry.js index d6cc06d..f76c7d8 100644 --- a/test/retry.js +++ b/test/retry.js @@ -124,7 +124,7 @@ describe("retry", () => { setTimeout(() => { expect(calls).to.equal(5); done(); - }, 50); + }, 100); }); it("should be cancelable", (done) => { diff --git a/test/support/get_function_object.js b/test/support/get_function_object.js index c31088f..561b152 100644 --- a/test/support/get_function_object.js +++ b/test/support/get_function_object.js @@ -10,7 +10,7 @@ module.exports = function (call_order) { setTimeout(() => { call_order.push(2); callback(null, 2); - }, 200); + }, 350); }, three(callback) { setTimeout(() => { diff --git a/test/timeout.js b/test/timeout.js index e5596ac..0d1c5b1 100644 --- a/test/timeout.js +++ b/test/timeout.js @@ -51,15 +51,15 @@ describe('timeout', () => { it('timeout with parallel', (done) => { async.parallel([ async.timeout((callback) => { - setTimeout(() => { + setImmediate(() => { callback(null, 'I didn\'t time out'); - }, 25); - }, 50), + }); + }, 20), async.timeout((callback) => { setTimeout(() => { callback(null, 'I will time out'); }, 75); - }, 50) + }, 20) ], (err, results) => { expect(err.message).to.equal('Callback function "anonymous" timed out.'); @@ -81,7 +81,7 @@ describe('timeout', () => { callback(null, 'I didn\'t time out'); }) } - }, 50); + }, 20); async.series([ function(cb) { |