Skip to content

Commit b7e742a

Browse files
committed
test: add helper for cleaning ipc temp files
1 parent 2b839a7 commit b7e742a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

test/unit/helpers.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ export async function uniqAddress(proto: Proto) {
8484
}
8585
}
8686

87+
export async function cleanSocket(address: string) {
88+
const [proto, path] = address.split("://")[1]
89+
if (proto !== "ipc" || !path) {
90+
return
91+
}
92+
const exists = await fs.promises
93+
.access(path, fs.constants.F_OK)
94+
.catch(() => false)
95+
if (exists) {
96+
await fs.promises.rm(path)
97+
}
98+
}
99+
87100
export function testProtos(...requested: Proto[]) {
88101
const set = new Set(requested)
89102

test/unit/proxy-router-dealer-test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as semver from "semver"
22
import * as zmq from "../../src"
33

44
import {assert} from "chai"
5-
import {testProtos, uniqAddress} from "./helpers"
5+
import {cleanSocket, testProtos, uniqAddress} from "./helpers"
66

77
for (const proto of testProtos("tcp", "ipc", "inproc")) {
88
describe(`proxy with ${proto} router/dealer`, function () {
@@ -29,14 +29,15 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
2929
rep = new zmq.Reply()
3030
})
3131

32-
afterEach(function () {
32+
afterEach(async function () {
3333
/* Closing proxy sockets is only necessary if run() fails. */
3434
proxy.frontEnd.close()
3535
proxy.backEnd.close()
3636

3737
req.close()
3838
rep.close()
3939
global.gc?.()
40+
await Promise.all([cleanSocket(frontAddress), cleanSocket(backAddress)])
4041
})
4142

4243
describe("run", function () {

0 commit comments

Comments
 (0)