File tree 1 file changed +14
-11
lines changed
1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -21,23 +21,26 @@ const doSmth = time => {
21
21
} ;
22
22
23
23
metatests . test ( 'Non-blocking' , test => {
24
+ const ITEM_TIME = 1 ;
25
+ const TIMER_TIME = 9 ;
24
26
const ARRAY_SIZE = 1000 ;
25
- const MIN_IO_CALLS = 90 ;
26
- const MAX_IO_CALLS = 110 ;
27
+ const EXPECTED_PERCENT = 0.5 ;
28
+ const EXPECTED_DEVIATION = 0.2 ;
27
29
28
- let ioCallsCount = 0 ;
29
30
const arr = new Array ( ARRAY_SIZE ) . fill ( 1 ) ;
30
31
31
- const timer = setInterval ( ( ) => {
32
- doSmth ( 9 ) ;
33
- ioCallsCount ++ ;
34
- } , 1 ) ;
32
+ const timer = setInterval ( ( ) => doSmth ( TIMER_TIME ) , 1 ) ;
35
33
36
- metasync . asyncMap ( arr , ( ) => doSmth ( 1 ) ,
37
- { percent : 0.5 } , ( ) => {
34
+ const begin = Date . now ( ) ;
35
+ metasync . asyncMap ( arr , ( ) => doSmth ( ITEM_TIME ) ,
36
+ { percent : EXPECTED_PERCENT } , ( ) => {
38
37
clearInterval ( timer ) ;
39
- test . assert ( ioCallsCount >= MIN_IO_CALLS ) ;
40
- test . assert ( ioCallsCount <= MAX_IO_CALLS ) ;
38
+
39
+ const mapTime = ITEM_TIME * ARRAY_SIZE ;
40
+ const allTime = Date . now ( ) - begin ;
41
+ const actualPercent = mapTime / allTime ;
42
+ const actualDeviation = Math . abs ( actualPercent - EXPECTED_PERCENT ) ;
43
+ test . assert ( actualDeviation <= EXPECTED_DEVIATION ) ;
41
44
test . end ( ) ;
42
45
} ) ;
43
46
} ) ;
You can’t perform that action at this time.
0 commit comments