Skip to content

Commit

Permalink
test: add helper for cleaning ipc temp files
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Dec 30, 2024
1 parent 2b839a7 commit b7e742a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions test/unit/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ export async function uniqAddress(proto: Proto) {
}
}

export async function cleanSocket(address: string) {
const [proto, path] = address.split("://")[1]
if (proto !== "ipc" || !path) {
return
}
const exists = await fs.promises
.access(path, fs.constants.F_OK)
.catch(() => false)
if (exists) {
await fs.promises.rm(path)
}
}

export function testProtos(...requested: Proto[]) {
const set = new Set(requested)

Expand Down
5 changes: 3 additions & 2 deletions test/unit/proxy-router-dealer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as semver from "semver"
import * as zmq from "../../src"

import {assert} from "chai"
import {testProtos, uniqAddress} from "./helpers"
import {cleanSocket, testProtos, uniqAddress} from "./helpers"

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

afterEach(function () {
afterEach(async function () {
/* Closing proxy sockets is only necessary if run() fails. */
proxy.frontEnd.close()
proxy.backEnd.close()

req.close()
rep.close()
global.gc?.()
await Promise.all([cleanSocket(frontAddress), cleanSocket(backAddress)])
})

describe("run", function () {
Expand Down

0 comments on commit b7e742a

Please sign in to comment.