Skip to content

Commit f631d46

Browse files
authored
Fix test-type-description-service.js flakiness (#1169)
This PR addresses test flakiness in the type description service tests by refining the asynchronous wait logic and cleaning up unused imports. Key changes include: - Removal of the unused assertUtils import. - Transition from a promise chain to async/await for waiting on the service and handling the response. - Introduction of an interval-based polling mechanism to send the request and clear the timer upon response. Fix: #1154
1 parent 8da31c9 commit f631d46

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

test/test-type-description-service.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
'use strict';
1616

1717
const assert = require('assert');
18-
const assertUtils = require('./utils.js');
1918
const DistroUtils = require('../lib/distro.js');
2019
const rclnodejs = require('../index.js');
2120
const TypeDescriptionService = require('../lib/type_description_service.js');
@@ -63,12 +62,15 @@ describe('type description service test suite', function () {
6362
const GetTypeDescription =
6463
'type_description_interfaces/srv/GetTypeDescription';
6564
const client = node.createClient(GetTypeDescription, serviceName);
66-
return client.waitForService(60 * 1000).then((result) => {
67-
if (!result) {
68-
throw new Error('Service not available');
69-
}
70-
return new Promise((resolve) => {
65+
const result = await client.waitForService(5000);
66+
if (!result) {
67+
throw new Error('Service not available');
68+
}
69+
70+
const promise = new Promise((resolve) => {
71+
const timer = setInterval(() => {
7172
client.sendRequest(request, (response) => {
73+
clearInterval(timer);
7274
assert.strictEqual(response.successful, true);
7375
assert.strictEqual(
7476
response.type_description.type_description.type_name,
@@ -77,8 +79,9 @@ describe('type description service test suite', function () {
7779
assert.notStrictEqual(response.type_sources.length, 0);
7880
resolve();
7981
});
80-
});
82+
}, 2000);
8183
});
84+
await promise;
8285
});
8386

8487
it('Test type description service configured by parameter', function (done) {

0 commit comments

Comments
 (0)