@@ -4,60 +4,45 @@ const common = require('./common')
44const assert = require ( 'assert' ) ;
55const os = require ( 'os' ) ;
66
7- test ( require ( `./build/${ buildType } /binding.node` ) ) ;
8- test ( require ( `./build/${ buildType } /binding_noexcept.node` ) ) ;
7+ module . exports = test ( require ( `./build/${ buildType } /binding.node` ) )
8+ . then ( ( ) => test ( require ( `./build/${ buildType } /binding_noexcept.node` ) ) ) ;
99
10- function test ( { asyncprogressqueueworker } ) {
11- success ( asyncprogressqueueworker ) ;
12- fail ( asyncprogressqueueworker ) ;
13- cancel ( asyncprogressqueueworker ) ;
14- return ;
10+ async function test ( { asyncprogressqueueworker } ) {
11+ await success ( asyncprogressqueueworker ) ;
12+ await fail ( asyncprogressqueueworker ) ;
1513}
1614
1715function success ( binding ) {
18- const expected = [ 0 , 1 , 2 , 3 ] ;
19- const actual = [ ] ;
20- const worker = binding . createWork ( expected . length ,
21- common . mustCall ( ( err ) => {
22- if ( err ) {
23- assert . fail ( err ) ;
24- }
25- // All queued items shall be invoked before complete callback.
26- assert . deepEqual ( actual , expected ) ;
27- } ) ,
28- common . mustCall ( ( _progress ) => {
29- actual . push ( _progress ) ;
30- } , expected . length )
31- ) ;
32- binding . queueWork ( worker ) ;
16+ return new Promise ( ( resolve , reject ) => {
17+ const expected = [ 0 , 1 , 2 , 3 ] ;
18+ const actual = [ ] ;
19+ const worker = binding . createWork ( expected . length ,
20+ common . mustCall ( ( err ) => {
21+ if ( err ) {
22+ reject ( err ) ;
23+ } else {
24+ // All queued items shall be invoked before complete callback.
25+ assert . deepEqual ( actual , expected ) ;
26+ resolve ( ) ;
27+ }
28+ } ) ,
29+ common . mustCall ( ( _progress ) => {
30+ actual . push ( _progress ) ;
31+ } , expected . length )
32+ ) ;
33+ binding . queueWork ( worker ) ;
34+ } ) ;
3335}
3436
3537function fail ( binding ) {
36- const worker = binding . createWork ( - 1 ,
37- common . mustCall ( ( err ) => {
38- assert . throws ( ( ) => { throw err } , / t e s t e r r o r / )
39- } ) ,
40- ( ) => {
41- assert . fail ( 'unexpected progress report' ) ;
42- }
43- ) ;
44- binding . queueWork ( worker ) ;
45- }
46-
47- function cancel ( binding ) {
48- // make sure the work we are going to cancel will not be
49- // able to start by using all the threads in the pool.
50- for ( let i = 0 ; i < os . cpus ( ) . length ; ++ i ) {
51- const worker = binding . createWork ( - 1 , ( ) => { } , ( ) => { } ) ;
38+ return new Promise ( ( resolve , reject ) => {
39+ const worker = binding . createWork ( - 1 ,
40+ common . mustCall ( ( err ) => {
41+ assert . throws ( ( ) => { throw err } , / t e s t e r r o r / ) ;
42+ resolve ( ) ;
43+ } ) ,
44+ common . mustNotCall ( )
45+ ) ;
5246 binding . queueWork ( worker ) ;
53- }
54- const worker = binding . createWork ( - 1 ,
55- ( ) => {
56- assert . fail ( 'unexpected callback' ) ;
57- } ,
58- ( ) => {
59- assert . fail ( 'unexpected progress report' ) ;
60- }
61- ) ;
62- binding . cancelWork ( worker ) ;
47+ } ) ;
6348}
0 commit comments