Skip to content

Commit

Permalink
test: use isFullError checks in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 5, 2022
1 parent 89258a0 commit ff6a0fc
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface RadioGroupOptions {
group: Buffer | string
}

export interface Radio extends Writable<MessageLike, [RadioGroupOptions]> {}
export type Radio = Writable<MessageLike, [RadioGroupOptions]>
Object.assign(Radio.prototype, {send})

export class Dish extends Socket {
Expand Down Expand Up @@ -66,7 +66,7 @@ interface DishGroupOptions {
group: Buffer
}

export interface Dish extends Readable<[Message, DishGroupOptions]> {}
export type Dish = Readable<[Message, DishGroupOptions]>
Object.assign(Dish.prototype, {receive})

export class Gather extends Socket {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ export class Publisher extends Socket {
}
}

export interface Publisher extends Writable {}
export type Publisher = Writable
Object.assign(Publisher.prototype, {send})

/**
Expand Down Expand Up @@ -1125,7 +1125,7 @@ export class Subscriber extends Socket {
}
}

export interface Subscriber extends Readable {}
export type Subscriber = Readable
Object.assign(Subscriber.prototype, {receive})

/**
Expand Down
4 changes: 3 additions & 1 deletion test/unit/compat/socket-error-callback-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ if (process.env.INCLUDE_COMPAT_TESTS) {

it("should callback with error when not connected", function (done) {
sock.send(["foo", "bar"], null, err => {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
sock.close()
done()
})
Expand Down
4 changes: 3 additions & 1 deletion test/unit/compat/socket-monitor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
})

doubleRep.bind(address, err => {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
})
})
})
Expand Down
5 changes: 4 additions & 1 deletion test/unit/proxy-construction-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as semver from "semver"
import * as zmq from "../../src"

import {assert} from "chai"
import {isFullError} from "../../src/errors"

describe("proxy construction", function () {
beforeEach(function () {
Expand Down Expand Up @@ -50,7 +51,9 @@ describe("proxy construction", function () {
new (zmq.Proxy as any)({}, {})
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.oneOf((err as Error).message, [
"Invalid pointer passed as argument" /* before 8.7 */,
"Invalid argument" /* as of 8.7 */,
Expand Down
17 changes: 13 additions & 4 deletions test/unit/proxy-run-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as zmq from "../../src"

import {assert} from "chai"
import {testProtos, uniqAddress} from "./helpers"
import {isFullError} from "../../src/errors"

for (const proto of testProtos("tcp", "ipc", "inproc")) {
describe(`proxy with ${proto} run`, function () {
Expand Down Expand Up @@ -30,7 +31,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await proxy.run()
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Front-end socket must be bound or connected")
}
})
Expand All @@ -44,7 +47,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await proxy.run()
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Front-end socket must be bound or connected")
}
})
Expand All @@ -56,7 +61,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await proxy.run()
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Back-end socket must be bound or connected")
assert.equal(err.code, "EINVAL")
assert.typeOf(err.errno, "number")
Expand All @@ -72,7 +79,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await proxy.run()
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Back-end socket must be bound or connected")
assert.equal(err.code, "EINVAL")
assert.typeOf(err.errno, "number")
Expand Down
5 changes: 4 additions & 1 deletion test/unit/proxy-terminate-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as zmq from "../../src"

import {assert} from "chai"
import {testProtos, uniqAddress} from "./helpers"
import {isFullError} from "../../src/errors"

for (const proto of testProtos("tcp", "ipc", "inproc")) {
describe(`proxy with ${proto} terminate`, function () {
Expand Down Expand Up @@ -34,7 +35,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await proxy.terminate()
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Socket is closed")
assert.equal(err.code, "EBADF")
assert.typeOf(err.errno, "number")
Expand Down
29 changes: 22 additions & 7 deletions test/unit/socket-bind-unbind-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as zmq from "../../src"

import {assert} from "chai"
import {testProtos, uniqAddress} from "./helpers"
import {isFullError} from "../../src/errors"

for (const proto of testProtos("tcp", "ipc", "inproc")) {
describe(`socket with ${proto} bind/unbind`, function () {
Expand All @@ -28,7 +29,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await sock.unbind(address)
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "No such endpoint")
assert.equal(err.code, "ENOENT")
assert.typeOf(err.errno, "number")
Expand All @@ -41,7 +44,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await sock.bind("foo-bar")
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Invalid argument")
assert.equal(err.code, "EINVAL")
assert.typeOf(err.errno, "number")
Expand All @@ -54,7 +59,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await sock.bind("foo://bar")
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Protocol not supported")
assert.equal(err.code, "EPROTONOSUPPORT")
assert.typeOf(err.errno, "number")
Expand All @@ -69,7 +76,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await sock.bind(uniqAddress(proto))
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(
err.message,
"Socket is blocked by a bind or unbind operation",
Expand All @@ -94,7 +103,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await sock.unbind("foo-bar")
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Invalid argument")
assert.equal(err.code, "EINVAL")
assert.typeOf(err.errno, "number")
Expand All @@ -107,7 +118,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await sock.unbind("foo://bar")
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Protocol not supported")
assert.equal(err.code, "EPROTONOSUPPORT")
assert.typeOf(err.errno, "number")
Expand All @@ -124,7 +137,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await sock.unbind(address)
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(
err.message,
"Socket is blocked by a bind or unbind operation",
Expand Down
9 changes: 7 additions & 2 deletions test/unit/socket-close-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as zmq from "../../src"

import {assert} from "chai"
import {testProtos, uniqAddress} from "./helpers"
import {isFullError} from "../../src/errors"

for (const proto of testProtos("tcp", "ipc", "inproc")) {
describe(`socket with ${proto} close`, function () {
Expand Down Expand Up @@ -32,7 +33,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
try {
await promise
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Operation was not possible or timed out")
assert.equal(err.code, "EAGAIN")
assert.typeOf(err.errno, "number")
Expand All @@ -47,7 +50,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
try {
await promise
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Operation was not possible or timed out")
assert.equal(err.code, "EAGAIN")
assert.typeOf(err.errno, "number")
Expand Down
21 changes: 16 additions & 5 deletions test/unit/socket-connect-disconnect-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as zmq from "../../src"

import {assert} from "chai"
import {testProtos, uniqAddress} from "./helpers"
import {isFullError} from "../../src/errors"

for (const proto of testProtos("tcp", "ipc", "inproc")) {
describe(`socket with ${proto} connect/disconnect`, function () {
Expand All @@ -23,7 +24,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await sock.connect("foo-bar")
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Invalid argument")
assert.equal(err.code, "EINVAL")
assert.typeOf(err.errno, "number")
Expand All @@ -36,7 +39,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await sock.connect("foo://bar")
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Protocol not supported")
assert.equal(err.code, "EPROTONOSUPPORT")
assert.typeOf(err.errno, "number")
Expand All @@ -60,7 +65,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await sock.disconnect(address)
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "No such endpoint")
assert.equal(err.code, "ENOENT")
assert.typeOf(err.errno, "number")
Expand All @@ -73,7 +80,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await sock.disconnect("foo-bar")
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Invalid argument")
assert.equal(err.code, "EINVAL")
assert.typeOf(err.errno, "number")
Expand All @@ -86,7 +95,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await sock.disconnect("foo://bar")
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Protocol not supported")
assert.equal(err.code, "EPROTONOSUPPORT")
assert.typeOf(err.errno, "number")
Expand Down
13 changes: 10 additions & 3 deletions test/unit/socket-construction-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as zmq from "../../src"

import {assert} from "chai"
import {isFullError} from "../../src/errors"

describe("socket construction", function () {
afterEach(function () {
Expand Down Expand Up @@ -53,7 +54,9 @@ describe("socket construction", function () {
new (zmq.Socket as any)(37, new zmq.Context())
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Invalid argument")
assert.equal(err.code, "EINVAL")
assert.typeOf(err.errno, "number")
Expand All @@ -65,7 +68,9 @@ describe("socket construction", function () {
new (zmq.Socket as any)(1, {context: {}})
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.oneOf(err.message, [
"Invalid pointer passed as argument" /* before 8.7 */,
"Invalid argument" /* as of 8.7 */,
Expand Down Expand Up @@ -177,7 +182,9 @@ describe("socket construction", function () {
sockets.push(new zmq.Dealer({context}))
}
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}
assert.equal(err.message, "Too many open file descriptors")
assert.equal(err.code, "EMFILE")
assert.typeOf(err.errno, "number")
Expand Down
5 changes: 4 additions & 1 deletion test/unit/socket-draft-server-client-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as draft from "../../src/draft"

import {assert} from "chai"
import {testProtos, uniqAddress} from "./helpers"
import {isFullError} from "../../src/errors"

if (zmq.capability.draft) {
for (const proto of testProtos("tcp", "ipc", "inproc")) {
Expand Down Expand Up @@ -75,7 +76,9 @@ if (zmq.capability.draft) {
await server.send("foo", {routingId: 12345})
assert.ok(false)
} catch (err) {
assert.instanceOf(err, Error)
if (!isFullError(err)) {
throw err
}

assert.equal(err.message, "Host unreachable")
assert.equal(err.code, "EHOSTUNREACH")
Expand Down
Loading

0 comments on commit ff6a0fc

Please sign in to comment.