Skip to content

Commit f306a46

Browse files
committed
Fix flakiness of test-message-type.js (#1171)
This PR addresses the flakiness of test-message-type.js by ensuring that subscriptions are properly destroyed after each test execution. - Added node.destroySubscription(subscription) to each test callback following publisher.kill('SIGINT') to ensure a clean test environment. - Improves test reliability by explicitly cleaning up subscriptions in all message type tests. Fix: #1170
1 parent 29c02d4 commit f306a46

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

test/test-message-type.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe('Rclnodejs message type testing', function () {
4242
'Bool_channel',
4343
(msg) => {
4444
publisher.kill('SIGINT');
45+
node.destroySubscription(subscription);
4546
assert.deepStrictEqual(typeof msg.data, 'boolean');
4647
assert.ok(msg.data);
4748
done();
@@ -62,6 +63,7 @@ describe('Rclnodejs message type testing', function () {
6263
'Char_channel',
6364
(msg) => {
6465
publisher.kill('SIGINT');
66+
node.destroySubscription(subscription);
6567
assert.deepStrictEqual(typeof msg.data, 'number');
6668
assert.deepStrictEqual(msg.data, 65);
6769
done();
@@ -82,6 +84,7 @@ describe('Rclnodejs message type testing', function () {
8284
'Byte_channel',
8385
(msg) => {
8486
publisher.kill('SIGINT');
87+
node.destroySubscription(subscription);
8588
assert.deepStrictEqual(typeof msg.data, 'number');
8689
assert.deepStrictEqual(msg.data, 10);
8790
done();
@@ -122,6 +125,7 @@ describe('Rclnodejs message type testing', function () {
122125
'Int8_channel',
123126
(msg) => {
124127
publisher.kill('SIGINT');
128+
node.destroySubscription(subscription);
125129
assert.deepStrictEqual(typeof msg.data, 'number');
126130
assert.deepStrictEqual(msg.data, 127);
127131
done();
@@ -142,6 +146,7 @@ describe('Rclnodejs message type testing', function () {
142146
'UInt8_channel',
143147
(msg) => {
144148
publisher.kill('SIGINT');
149+
node.destroySubscription(subscription);
145150
assert.deepStrictEqual(typeof msg.data, 'number');
146151
assert.deepStrictEqual(msg.data, 255);
147152
done();
@@ -162,6 +167,7 @@ describe('Rclnodejs message type testing', function () {
162167
'Int16_channel',
163168
(msg) => {
164169
publisher.kill('SIGINT');
170+
node.destroySubscription(subscription);
165171
assert.deepStrictEqual(typeof msg.data, 'number');
166172
assert.deepStrictEqual(msg.data, 0x7fff);
167173
done();
@@ -182,6 +188,7 @@ describe('Rclnodejs message type testing', function () {
182188
'UInt16_channel',
183189
(msg) => {
184190
publisher.kill('SIGINT');
191+
node.destroySubscription(subscription);
185192
assert.deepStrictEqual(typeof msg.data, 'number');
186193
assert.deepStrictEqual(msg.data, 0xffff);
187194
done();
@@ -202,6 +209,7 @@ describe('Rclnodejs message type testing', function () {
202209
'Int32_channel',
203210
(msg) => {
204211
publisher.kill('SIGINT');
212+
node.destroySubscription(subscription);
205213
assert.deepStrictEqual(typeof msg.data, 'number');
206214
assert.deepStrictEqual(msg.data, 0x7fffffff);
207215
done();
@@ -222,6 +230,7 @@ describe('Rclnodejs message type testing', function () {
222230
'UInt32_channel',
223231
(msg) => {
224232
publisher.kill('SIGINT');
233+
node.destroySubscription(subscription);
225234
assert.deepStrictEqual(typeof msg.data, 'number');
226235
assert.deepStrictEqual(msg.data, 0xffffffff);
227236
done();
@@ -242,6 +251,7 @@ describe('Rclnodejs message type testing', function () {
242251
'Int64_channel',
243252
(msg) => {
244253
publisher.kill('SIGINT');
254+
node.destroySubscription(subscription);
245255
assert.deepStrictEqual(typeof msg.data, 'bigint');
246256
assert.deepStrictEqual(msg.data, BigInt('0x1fffffffffffff'));
247257
done();
@@ -262,6 +272,7 @@ describe('Rclnodejs message type testing', function () {
262272
'UInt64_channel',
263273
(msg) => {
264274
publisher.kill('SIGINT');
275+
node.destroySubscription(subscription);
265276
assert.deepStrictEqual(typeof msg.data, 'bigint');
266277
assert.deepStrictEqual(msg.data, BigInt('0x1fffffffffffff'));
267278
done();
@@ -282,6 +293,7 @@ describe('Rclnodejs message type testing', function () {
282293
'Float32_channel',
283294
(msg) => {
284295
publisher.kill('SIGINT');
296+
node.destroySubscription(subscription);
285297
assert.deepStrictEqual(typeof msg.data, 'number');
286298
assert.ok(Math.abs(msg.data - 3.14) < 0.000001);
287299
done();
@@ -302,6 +314,7 @@ describe('Rclnodejs message type testing', function () {
302314
'Float64_channel',
303315
(msg) => {
304316
publisher.kill('SIGINT');
317+
node.destroySubscription(subscription);
305318
assert.deepStrictEqual(typeof msg.data, 'number');
306319
assert.ok(Math.abs(msg.data - 3.14) < 0.000001);
307320
done();
@@ -324,6 +337,7 @@ describe('Rclnodejs message type testing', function () {
324337
'ColorRGBA_channel',
325338
(msg) => {
326339
publisher.kill('SIGINT');
340+
node.destroySubscription(subscription);
327341
assert.ok('r' in msg);
328342
assert.deepStrictEqual(typeof msg.r, 'number');
329343
assert.deepStrictEqual(msg.r, 127);
@@ -351,7 +365,7 @@ describe('Rclnodejs message type testing', function () {
351365
'Header_channel',
352366
(header) => {
353367
publisher.kill('SIGINT');
354-
368+
node.destroySubscription(subscription);
355369
assert.ok('stamp' in header);
356370
assert.ok('sec' in header.stamp);
357371
assert.deepStrictEqual(header.stamp.sec, 123456);
@@ -377,7 +391,7 @@ describe('Rclnodejs message type testing', function () {
377391
'JointState_channel',
378392
(state) => {
379393
publisher.kill('SIGINT');
380-
394+
node.destroySubscription(subscription);
381395
assert.deepStrictEqual(state.name, ['Tom', 'Jerry']);
382396
assert.deepStrictEqual(state.position, Float64Array.from([1, 2]));
383397
assert.deepStrictEqual(state.velocity, Float64Array.from([2, 3]));

0 commit comments

Comments
 (0)