1 | const assert = require('assert');
|
2 | const {circuitBreak} = require('../index');
|
3 |
|
4 | describe('Concurrency', function() {
|
5 | describe('#Promise.any()', function() {
|
6 | it('should return an array of value objects if there is no exception', async function(){
|
7 | let res = await Promise.any([Promise.resolve(1), Promise.resolve(2)]);
|
8 | assert.deepEqual(res,[{value:1},{value:2}]);
|
9 | });
|
10 | it('should return an array of error objects if there no exception', async function(){
|
11 | let res = await Promise.any([Promise.reject(1), Promise.reject(2)]);
|
12 | assert.deepEqual(res,[{error:1},{error:2}]);
|
13 | });
|
14 | it('should return an array mixed value and error objects', async function(){
|
15 | let res = await Promise.any([Promise.resolve(1), Promise.reject(2), Promise.resolve(3)]);
|
16 | assert.deepEqual(res,[{value:1},{error:2},{value:3}]);
|
17 | });
|
18 | });
|
19 | describe('#Promise.best()', function() {
|
20 | it('should return the first result', async function(){
|
21 | let res = await Promise.best([Promise.resolve(1), Promise.resolve(2)]);
|
22 | assert.deepEqual(res,1);
|
23 | });
|
24 | it('should return the first good result', async function(){
|
25 | let res = await Promise.best([Promise.reject(1), Promise.resolve(2), Promise.resolve(3)]);
|
26 | assert.deepEqual(res,2);
|
27 | });
|
28 | it('should return an exception with all error objects', async function(){
|
29 | try{
|
30 | let res = await Promise.best([Promise.reject(1), Promise.reject(2)]);
|
31 | assert.fail()
|
32 | }catch(e){
|
33 | assert.deepEqual(e,[1,2]);
|
34 | }
|
35 | });
|
36 | });
|
37 | });
|