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