@@ -4,10 +4,12 @@ const buildType = process.config.target_defaults.default_configuration;
4
4
const assert = require ( 'assert' ) ;
5
5
const common = require ( '../common' ) ;
6
6
7
- module . exports = test ( require ( `../build/${ buildType } /binding.node` ) )
8
- . then ( ( ) => test ( require ( `../build/${ buildType } /binding_noexcept.node` ) ) ) ;
7
+ module . exports = async function ( ) {
8
+ await test ( require ( `../build/${ buildType } /binding.node` ) ) ;
9
+ await test ( require ( `../build/${ buildType } /binding_noexcept.node` ) ) ;
10
+ } ;
9
11
10
- function test ( binding ) {
12
+ async function test ( binding ) {
11
13
const expectedArray = ( function ( arrayLength ) {
12
14
const result = [ ] ;
13
15
for ( let index = 0 ; index < arrayLength ; index ++ ) {
@@ -43,7 +45,7 @@ function test(binding) {
43
45
} ) ;
44
46
}
45
47
46
- return new Promise ( function testWithoutJSMarshaller ( resolve ) {
48
+ await new Promise ( function testWithoutJSMarshaller ( resolve ) {
47
49
let callCount = 0 ;
48
50
binding . threadsafe_function . startThreadNoNative ( function testCallback ( ) {
49
51
callCount ++ ;
@@ -59,112 +61,134 @@ function test(binding) {
59
61
}
60
62
} , false /* abort */ , false /* launchSecondary */ ,
61
63
binding . threadsafe_function . MAX_QUEUE_SIZE ) ;
62
- } )
64
+ } ) ;
63
65
64
66
// Start the thread in blocking mode, and assert that all values are passed.
65
67
// Quit after it's done.
66
- . then ( ( ) => testWithJSMarshaller ( {
67
- threadStarter : 'startThread' ,
68
- maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
69
- quitAfter : binding . threadsafe_function . ARRAY_LENGTH
70
- } ) )
71
- . then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
68
+ assert . deepStrictEqual (
69
+ await testWithJSMarshaller ( {
70
+ threadStarter : 'startThread' ,
71
+ maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
72
+ quitAfter : binding . threadsafe_function . ARRAY_LENGTH
73
+ } ) ,
74
+ expectedArray ,
75
+ ) ;
72
76
73
77
// Start the thread in blocking mode with an infinite queue, and assert that
74
78
// all values are passed. Quit after it's done.
75
- . then ( ( ) => testWithJSMarshaller ( {
76
- threadStarter : 'startThread' ,
77
- maxQueueSize : 0 ,
78
- quitAfter : binding . threadsafe_function . ARRAY_LENGTH
79
- } ) )
80
- . then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
79
+ assert . deepStrictEqual (
80
+ await testWithJSMarshaller ( {
81
+ threadStarter : 'startThread' ,
82
+ maxQueueSize : 0 ,
83
+ quitAfter : binding . threadsafe_function . ARRAY_LENGTH
84
+ } ) ,
85
+ expectedArray ,
86
+ ) ;
81
87
82
88
// Start the thread in non-blocking mode, and assert that all values are
83
89
// passed. Quit after it's done.
84
- . then ( ( ) => testWithJSMarshaller ( {
85
- threadStarter : 'startThreadNonblocking' ,
86
- maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
87
- quitAfter : binding . threadsafe_function . ARRAY_LENGTH
88
- } ) )
89
- . then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
90
+ assert . deepStrictEqual (
91
+ await testWithJSMarshaller ( {
92
+ threadStarter : 'startThreadNonblocking' ,
93
+ maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
94
+ quitAfter : binding . threadsafe_function . ARRAY_LENGTH
95
+ } ) ,
96
+ expectedArray ,
97
+ ) ;
90
98
91
99
// Start the thread in blocking mode, and assert that all values are passed.
92
100
// Quit early, but let the thread finish.
93
- . then ( ( ) => testWithJSMarshaller ( {
94
- threadStarter : 'startThread' ,
95
- maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
96
- quitAfter : 1
97
- } ) )
98
- . then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
101
+ assert . deepStrictEqual (
102
+ await testWithJSMarshaller ( {
103
+ threadStarter : 'startThread' ,
104
+ maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
105
+ quitAfter : 1
106
+ } ) ,
107
+ expectedArray ,
108
+ ) ;
99
109
100
110
// Start the thread in blocking mode with an infinite queue, and assert that
101
111
// all values are passed. Quit early, but let the thread finish.
102
- . then ( ( ) => testWithJSMarshaller ( {
103
- threadStarter : 'startThread' ,
104
- maxQueueSize : 0 ,
105
- quitAfter : 1
106
- } ) )
107
- . then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
112
+ assert . deepStrictEqual (
113
+ await testWithJSMarshaller ( {
114
+ threadStarter : 'startThread' ,
115
+ maxQueueSize : 0 ,
116
+ quitAfter : 1
117
+ } ) ,
118
+ expectedArray ,
119
+ ) ;
108
120
109
121
110
122
// Start the thread in non-blocking mode, and assert that all values are
111
123
// passed. Quit early, but let the thread finish.
112
- . then ( ( ) => testWithJSMarshaller ( {
113
- threadStarter : 'startThreadNonblocking' ,
114
- maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
115
- quitAfter : 1
116
- } ) )
117
- . then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
124
+ assert . deepStrictEqual (
125
+ await testWithJSMarshaller ( {
126
+ threadStarter : 'startThreadNonblocking' ,
127
+ maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
128
+ quitAfter : 1
129
+ } ) ,
130
+ expectedArray ,
131
+ ) ;
118
132
119
133
// Start the thread in blocking mode, and assert that all values are passed.
120
134
// Quit early, but let the thread finish. Launch a secondary thread to test
121
135
// the reference counter incrementing functionality.
122
- . then ( ( ) => testWithJSMarshaller ( {
123
- threadStarter : 'startThread' ,
124
- quitAfter : 1 ,
125
- maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
126
- launchSecondary : true
127
- } ) )
128
- . then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
136
+ assert . deepStrictEqual (
137
+ await testWithJSMarshaller ( {
138
+ threadStarter : 'startThread' ,
139
+ quitAfter : 1 ,
140
+ maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
141
+ launchSecondary : true
142
+ } ) ,
143
+ expectedArray ,
144
+ ) ;
129
145
130
146
// Start the thread in non-blocking mode, and assert that all values are
131
147
// passed. Quit early, but let the thread finish. Launch a secondary thread
132
148
// to test the reference counter incrementing functionality.
133
- . then ( ( ) => testWithJSMarshaller ( {
134
- threadStarter : 'startThreadNonblocking' ,
135
- quitAfter : 1 ,
136
- maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
137
- launchSecondary : true
138
- } ) )
139
- . then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
149
+ assert . deepStrictEqual (
150
+ await testWithJSMarshaller ( {
151
+ threadStarter : 'startThreadNonblocking' ,
152
+ quitAfter : 1 ,
153
+ maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
154
+ launchSecondary : true
155
+ } ) ,
156
+ expectedArray ,
157
+ ) ;
140
158
141
159
// Start the thread in blocking mode, and assert that it could not finish.
142
160
// Quit early by aborting.
143
- . then ( ( ) => testWithJSMarshaller ( {
144
- threadStarter : 'startThread' ,
145
- quitAfter : 1 ,
146
- maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
147
- abort : true
148
- } ) )
149
- . then ( ( result ) => assert . strictEqual ( result . indexOf ( 0 ) , - 1 ) )
161
+ assert . strictEqual (
162
+ ( await testWithJSMarshaller ( {
163
+ threadStarter : 'startThread' ,
164
+ quitAfter : 1 ,
165
+ maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
166
+ abort : true
167
+ } ) ) . indexOf ( 0 ) ,
168
+ - 1 ,
169
+ ) ;
150
170
151
171
// Start the thread in blocking mode with an infinite queue, and assert that
152
172
// it could not finish. Quit early by aborting.
153
- . then ( ( ) => testWithJSMarshaller ( {
154
- threadStarter : 'startThread' ,
155
- quitAfter : 1 ,
156
- maxQueueSize : 0 ,
157
- abort : true
158
- } ) )
159
- . then ( ( result ) => assert . strictEqual ( result . indexOf ( 0 ) , - 1 ) )
173
+ assert . strictEqual (
174
+ ( await testWithJSMarshaller ( {
175
+ threadStarter : 'startThread' ,
176
+ quitAfter : 1 ,
177
+ maxQueueSize : 0 ,
178
+ abort : true
179
+ } ) ) . indexOf ( 0 ) ,
180
+ - 1 ,
181
+ ) ;
160
182
161
183
// Start the thread in non-blocking mode, and assert that it could not finish.
162
184
// Quit early and aborting.
163
- . then ( ( ) => testWithJSMarshaller ( {
164
- threadStarter : 'startThreadNonblocking' ,
165
- quitAfter : 1 ,
166
- maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
167
- abort : true
168
- } ) )
169
- . then ( ( result ) => assert . strictEqual ( result . indexOf ( 0 ) , - 1 ) )
185
+ assert . strictEqual (
186
+ ( await testWithJSMarshaller ( {
187
+ threadStarter : 'startThreadNonblocking' ,
188
+ quitAfter : 1 ,
189
+ maxQueueSize : binding . threadsafe_function . MAX_QUEUE_SIZE ,
190
+ abort : true
191
+ } ) ) . indexOf ( 0 ) ,
192
+ - 1 ,
193
+ ) ;
170
194
}
0 commit comments