Skip to content

Commit 11d2700

Browse files
committed
Address comments
1 parent de0fec6 commit 11d2700

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

lib/wait_for_message.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
'use strict';
1616

17+
const { TimeoutError } = require('./errors.js');
18+
1719
/**
1820
* Wait for a single message on a topic.
1921
*
@@ -56,7 +58,7 @@ function waitForMessage(typeClass, node, topic, options = {}) {
5658
if (subscription) {
5759
try {
5860
node.destroySubscription(subscription);
59-
} catch (e) {
61+
} catch {
6062
// Subscription may already be destroyed if node is shutting down
6163
}
6264
subscription = null;
@@ -92,8 +94,9 @@ function waitForMessage(typeClass, node, topic, options = {}) {
9294
if (options.timeout != null && options.timeout >= 0) {
9395
timer = setTimeout(() => {
9496
settle(
95-
new Error(
96-
`waitForMessage timed out after ${options.timeout}ms on topic '${topic}'`
97+
new TimeoutError(
98+
`waitForMessage timed out after ${options.timeout}ms on topic '${topic}'`,
99+
{ entityType: 'topic', entityName: topic }
97100
)
98101
);
99102
}, options.timeout);

test/test-wait-for-message.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ describe('waitForMessage tests', function () {
7070
'wfm_nonexistent_topic',
7171
{ timeout: 500 }
7272
),
73-
{ message: /timed out/ }
73+
(error) => {
74+
assert.strictEqual(error.name, 'TimeoutError');
75+
return true;
76+
}
7477
);
7578
});
7679

@@ -80,8 +83,6 @@ describe('waitForMessage tests', function () {
8083
'wfm_test_topic_2'
8184
);
8285

83-
let receiveCount = 0;
84-
8586
setTimeout(() => {
8687
publisher.publish('first');
8788
publisher.publish('second');

0 commit comments

Comments
 (0)