@@ -25,7 +25,7 @@ if (process.argv[2] === 'child') {
25
25
if ( callCount === 2 ) {
26
26
binding . Unref ( ) ;
27
27
}
28
- } , false /* abort */ , true /* launchSecondary */ ) ;
28
+ } , false /* abort */ , true /* launchSecondary */ , + process . argv [ 3 ] ) ;
29
29
30
30
// Release the thread-safe function from the main thread so that it may be
31
31
// torn down via the environment cleanup handler.
@@ -37,6 +37,7 @@ function testWithJSMarshaller({
37
37
threadStarter,
38
38
quitAfter,
39
39
abort,
40
+ maxQueueSize,
40
41
launchSecondary } ) {
41
42
return new Promise ( ( resolve ) => {
42
43
const array = [ ] ;
@@ -49,7 +50,7 @@ function testWithJSMarshaller({
49
50
} ) , ! ! abort ) ;
50
51
} ) ;
51
52
}
52
- } , ! ! abort , ! ! launchSecondary ) ;
53
+ } , ! ! abort , ! ! launchSecondary , maxQueueSize ) ;
53
54
if ( threadStarter === 'StartThreadNonblocking' ) {
54
55
// Let's make this thread really busy for a short while to ensure that
55
56
// the queue fills and the thread receives a napi_queue_full.
@@ -59,6 +60,24 @@ function testWithJSMarshaller({
59
60
} ) ;
60
61
}
61
62
63
+ function testUnref ( queueSize ) {
64
+ return new Promise ( ( resolve , reject ) => {
65
+ let output = '' ;
66
+ const child = fork ( __filename , [ 'child' , queueSize ] , {
67
+ stdio : [ process . stdin , 'pipe' , process . stderr , 'ipc' ]
68
+ } ) ;
69
+ child . on ( 'close' , ( code ) => {
70
+ if ( code === 0 ) {
71
+ resolve ( output . match ( / \S + / g) ) ;
72
+ } else {
73
+ reject ( new Error ( 'Child process died with code ' + code ) ) ;
74
+ }
75
+ } ) ;
76
+ child . stdout . on ( 'data' , ( data ) => ( output += data . toString ( ) ) ) ;
77
+ } )
78
+ . then ( ( result ) => assert . strictEqual ( result . indexOf ( 0 ) , - 1 ) ) ;
79
+ }
80
+
62
81
new Promise ( function testWithoutJSMarshaller ( resolve ) {
63
82
let callCount = 0 ;
64
83
binding . StartThreadNoNative ( function testCallback ( ) {
@@ -73,13 +92,23 @@ new Promise(function testWithoutJSMarshaller(resolve) {
73
92
} ) , false ) ;
74
93
} ) ;
75
94
}
76
- } , false /* abort */ , false /* launchSecondary */ ) ;
95
+ } , false /* abort */ , false /* launchSecondary */ , binding . MAX_QUEUE_SIZE ) ;
77
96
} )
78
97
79
98
// Start the thread in blocking mode, and assert that all values are passed.
80
99
// Quit after it's done.
81
100
. then ( ( ) => testWithJSMarshaller ( {
82
101
threadStarter : 'StartThread' ,
102
+ maxQueueSize : binding . MAX_QUEUE_SIZE ,
103
+ quitAfter : binding . ARRAY_LENGTH
104
+ } ) )
105
+ . then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
106
+
107
+ // Start the thread in blocking mode with an infinite queue, and assert that all
108
+ // values are passed. Quit after it's done.
109
+ . then ( ( ) => testWithJSMarshaller ( {
110
+ threadStarter : 'StartThread' ,
111
+ maxQueueSize : 0 ,
83
112
quitAfter : binding . ARRAY_LENGTH
84
113
} ) )
85
114
. then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
@@ -88,6 +117,7 @@ new Promise(function testWithoutJSMarshaller(resolve) {
88
117
// Quit after it's done.
89
118
. then ( ( ) => testWithJSMarshaller ( {
90
119
threadStarter : 'StartThreadNonblocking' ,
120
+ maxQueueSize : binding . MAX_QUEUE_SIZE ,
91
121
quitAfter : binding . ARRAY_LENGTH
92
122
} ) )
93
123
. then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
@@ -96,6 +126,16 @@ new Promise(function testWithoutJSMarshaller(resolve) {
96
126
// Quit early, but let the thread finish.
97
127
. then ( ( ) => testWithJSMarshaller ( {
98
128
threadStarter : 'StartThread' ,
129
+ maxQueueSize : binding . MAX_QUEUE_SIZE ,
130
+ quitAfter : 1
131
+ } ) )
132
+ . then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
133
+
134
+ // Start the thread in blocking mode with an infinite queue, and assert that all
135
+ // values are passed. Quit early, but let the thread finish.
136
+ . then ( ( ) => testWithJSMarshaller ( {
137
+ threadStarter : 'StartThread' ,
138
+ maxQueueSize : 0 ,
99
139
quitAfter : 1
100
140
} ) )
101
141
. then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
@@ -104,6 +144,7 @@ new Promise(function testWithoutJSMarshaller(resolve) {
104
144
// Quit early, but let the thread finish.
105
145
. then ( ( ) => testWithJSMarshaller ( {
106
146
threadStarter : 'StartThreadNonblocking' ,
147
+ maxQueueSize : binding . MAX_QUEUE_SIZE ,
107
148
quitAfter : 1
108
149
} ) )
109
150
. then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
@@ -114,6 +155,7 @@ new Promise(function testWithoutJSMarshaller(resolve) {
114
155
. then ( ( ) => testWithJSMarshaller ( {
115
156
threadStarter : 'StartThread' ,
116
157
quitAfter : 1 ,
158
+ maxQueueSize : binding . MAX_QUEUE_SIZE ,
117
159
launchSecondary : true
118
160
} ) )
119
161
. then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
@@ -124,15 +166,27 @@ new Promise(function testWithoutJSMarshaller(resolve) {
124
166
. then ( ( ) => testWithJSMarshaller ( {
125
167
threadStarter : 'StartThreadNonblocking' ,
126
168
quitAfter : 1 ,
169
+ maxQueueSize : binding . MAX_QUEUE_SIZE ,
127
170
launchSecondary : true
128
171
} ) )
129
172
. then ( ( result ) => assert . deepStrictEqual ( result , expectedArray ) )
130
173
131
174
// Start the thread in blocking mode, and assert that it could not finish.
132
- // Quit early and aborting.
175
+ // Quit early by aborting.
176
+ . then ( ( ) => testWithJSMarshaller ( {
177
+ threadStarter : 'StartThread' ,
178
+ quitAfter : 1 ,
179
+ maxQueueSize : binding . MAX_QUEUE_SIZE ,
180
+ abort : true
181
+ } ) )
182
+ . then ( ( result ) => assert . strictEqual ( result . indexOf ( 0 ) , - 1 ) )
183
+
184
+ // Start the thread in blocking mode with an infinite queue, and assert that it
185
+ // could not finish. Quit early by aborting.
133
186
. then ( ( ) => testWithJSMarshaller ( {
134
187
threadStarter : 'StartThread' ,
135
188
quitAfter : 1 ,
189
+ maxQueueSize : 0 ,
136
190
abort : true
137
191
} ) )
138
192
. then ( ( result ) => assert . strictEqual ( result . indexOf ( 0 ) , - 1 ) )
@@ -142,25 +196,13 @@ new Promise(function testWithoutJSMarshaller(resolve) {
142
196
. then ( ( ) => testWithJSMarshaller ( {
143
197
threadStarter : 'StartThreadNonblocking' ,
144
198
quitAfter : 1 ,
199
+ maxQueueSize : binding . MAX_QUEUE_SIZE ,
145
200
abort : true
146
201
} ) )
147
202
. then ( ( result ) => assert . strictEqual ( result . indexOf ( 0 ) , - 1 ) )
148
203
149
204
// Start a child process to test rapid teardown
150
- . then ( ( ) => {
151
- return new Promise ( ( resolve , reject ) => {
152
- let output = '' ;
153
- const child = fork ( __filename , [ 'child' ] , {
154
- stdio : [ process . stdin , 'pipe' , process . stderr , 'ipc' ]
155
- } ) ;
156
- child . on ( 'close' , ( code ) => {
157
- if ( code === 0 ) {
158
- resolve ( output . match ( / \S + / g) ) ;
159
- } else {
160
- reject ( new Error ( 'Child process died with code ' + code ) ) ;
161
- }
162
- } ) ;
163
- child . stdout . on ( 'data' , ( data ) => ( output += data . toString ( ) ) ) ;
164
- } ) ;
165
- } )
166
- . then ( ( result ) => assert . strictEqual ( result . indexOf ( 0 ) , - 1 ) ) ;
205
+ . then ( ( ) => testUnref ( binding . MAX_QUEUE_SIZE ) )
206
+
207
+ // Start a child process with an infinite queue to test rapid teardown
208
+ . then ( ( ) => testUnref ( 0 ) ) ;
0 commit comments