Skip to content

Commit

Permalink
fixup! test(binding-coap): await all calls of coapServer.stop()
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Sep 21, 2023
1 parent 7b46440 commit 7a3538a
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions packages/binding-coap/test/coap-server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,29 +336,32 @@ class CoapServerTest {
null,
];

const promises = contentFormats.map((contentFormat) => new Promise<void>((resolve) => {
const req = request(uri);

if (contentFormat != null) {
req.setHeader("Accept", contentFormat);
}

req.on("response", async (res: IncomingMessage) => {
const requestContentFormat = res.headers["Content-Format"];

if (contentFormat === unsupportedContentFormat) {
expect(res.code).to.equal("4.06");
expect(res.payload.toString()).to.equal(
`Content-Format ${unsupportedContentFormat} is not supported by this resource.`
);
} else {
expect(requestContentFormat).to.equal(contentFormat ?? defaultContentFormat);
const promises = contentFormats.map(
(contentFormat) =>
new Promise<void>((resolve) => {
const req = request(uri);

if (contentFormat != null) {
req.setHeader("Accept", contentFormat);
}

resolve();
});
req.end();
}));
req.on("response", async (res: IncomingMessage) => {
const requestContentFormat = res.headers["Content-Format"];

if (contentFormat === unsupportedContentFormat) {
expect(res.code).to.equal("4.06");
expect(res.payload.toString()).to.equal(
`Content-Format ${unsupportedContentFormat} is not supported by this resource.`
);
} else {
expect(requestContentFormat).to.equal(contentFormat ?? defaultContentFormat);
}

resolve();
});
req.end();
})
);

await Promise.all(promises);

Expand Down

0 comments on commit 7a3538a

Please sign in to comment.