Skip to content

Commit

Permalink
test: fix DNS cancel tests
Browse files Browse the repository at this point in the history
PR-URL: #44432
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
szmarczak authored and targos committed May 12, 2024
1 parent f076e72 commit f47e8fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
22 changes: 8 additions & 14 deletions test/parallel/test-dns-channel-cancel-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,15 @@ const dgram = require('dgram');
const server = dgram.createSocket('udp4');
const resolver = new dnsPromises.Resolver();

const addMessageListener = () => {
server.removeAllListeners('message');

server.once('message', () => {
server.once('message', common.mustNotCall);

resolver.cancel();
});
};

server.bind(0, common.mustCall(async () => {
resolver.setServers([`127.0.0.1:${server.address().port}`]);

addMessageListener();

// Single promise
{
server.once('message', () => {
resolver.cancel();
});

const hostname = 'example0.org';

await assert.rejects(
Expand All @@ -36,10 +28,12 @@ server.bind(0, common.mustCall(async () => {
);
}

addMessageListener();

// Multiple promises
{
server.once('message', () => {
resolver.cancel();
});

const assertions = [];
const assertionCount = 10;

Expand Down
19 changes: 7 additions & 12 deletions test/parallel/test-dns-channel-cancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ const resolver = new Resolver();
const desiredQueries = 11;
let finishedQueries = 0;

const addMessageListener = () => {
server.removeAllListeners('message');

server.once('message', () => {
server.once('message', common.mustNotCall);

resolver.cancel();
});
};

server.bind(0, common.mustCall(async () => {
resolver.setServers([`127.0.0.1:${server.address().port}`]);

Expand All @@ -37,15 +27,20 @@ server.bind(0, common.mustCall(async () => {
const next = (...args) => {
callback(...args);

addMessageListener();
server.once('message', () => {
resolver.cancel();
});

// Multiple queries
for (let i = 1; i < desiredQueries; i++) {
resolver.resolve4(`example${i}.org`, callback);
}
};

server.once('message', () => {
resolver.cancel();
});

// Single query
addMessageListener();
resolver.resolve4('example0.org', next);
}));

0 comments on commit f47e8fc

Please sign in to comment.