Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarong committed Sep 6, 2020
1 parent e5527e3 commit 22f9102
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 135 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,6 @@ Errors thrown:

There was a problem with one or more of the supplied arguments.

- `err.message === "INVALID_STATE: ..."`

The client state is not `connected`.

Errors called back:

- `err.message === "TIMEOUT: ..."`
Expand All @@ -347,8 +343,9 @@ Errors called back:
response. If the client was connected to the server at the time of the action
invocation, the subsequent disconnect may have resulted from a call to
`client.disconnect()` or due to a transport connectivity failure. In both
cases, the action callback will always be invoked before any feed close events
are emitted, after which the client disconnect event will be emitted.
cases, the action callback is invoked before any feed close events are
emitted, and feed close events are emitted before the client disconnect event
is emitted.

* `err.message === "REJECTED: ..."`

Expand Down Expand Up @@ -394,8 +391,9 @@ Errors returned via promise rejection:
response. If the client was connected to the server at the time of the action
invocation, the subsequent disconnect may have resulted from a call to
`client.disconnect()` or due to a transport connectivity failure. In both
cases, the action promise will always be settled before any feed close events
are emitted, after which the client disconnect event will be emitted.
cases, the action promise is rejected before any feed close events are
emitted, and feed close events are emitted before the client disconnect event
is emitted.

- `err.message === "REJECTED: ..."`

Expand Down
135 changes: 8 additions & 127 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import delayOrig from "delay"; // eslint-disable-line import/no-extraneous-depen
// Delay must use real timers, not fake timers
const delay = delayOrig.createWithTimers({ clearTimeout, setTimeout });

// Use fake timers
beforeEach(() => {
jasmine.clock().install();
});
afterEach(() => {
jasmine.clock().uninstall();
});

/*
Integration/functional tests for the built library are run on Node and in the
Expand Down Expand Up @@ -194,10 +202,6 @@ Ensure that initialization options behave as documented.
*/

describe("The connectTimeoutMs option", () => {
beforeEach(() => {
jasmine.clock().install();
});

it("if synchronously connecting and connectTimeoutMs greater than zero, should time out appropriately - transport is connecting on timeout", async () => {
const opts = {
connectTimeoutMs: 1000
Expand Down Expand Up @@ -387,17 +391,9 @@ describe("The connectTimeoutMs option", () => {
expect(clientListener.badClientMessage.calls.count()).toBe(0);
expect(clientListener.transportError.calls.count()).toBe(0);
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("The connectRetryMs option", () => {
beforeEach(() => {
jasmine.clock().install();
});

it("if greater than zero, should wait appropriately between connection retries", async () => {
const opts = {
connectRetryMs: 1000
Expand Down Expand Up @@ -578,17 +574,9 @@ describe("The connectRetryMs option", () => {
expect(harness.transport.state.calls.argsFor(i).length).toBe(0);
}
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("The connectRetryBackoffMs and connectRetryMaxMs options", () => {
beforeEach(() => {
jasmine.clock().install();
});

it("should back off as configured", async () => {
const opts = {
connectRetryMs: 1000,
Expand Down Expand Up @@ -634,17 +622,9 @@ describe("The connectRetryBackoffMs and connectRetryMaxMs options", () => {
}
}
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("The connectRetryMaxAttempts option", () => {
beforeEach(() => {
jasmine.clock().install();
});

it("if greater than zero, should stop connection retries as configured", async () => {
const opts = {
connectRetryMs: 0,
Expand Down Expand Up @@ -713,17 +693,9 @@ describe("The connectRetryMaxAttempts option", () => {
}
}
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("The actionTimeoutMs option", () => {
beforeEach(() => {
jasmine.clock().install();
});

it("if greater than zero, should timeout as configured", async () => {
const opts = {
actionTimeoutMs: 1000
Expand Down Expand Up @@ -770,17 +742,9 @@ describe("The actionTimeoutMs option", () => {
jasmine.clock().tick(Number.MAX_SAFE_INTEGER);
expect(cb.calls.count()).toBe(0);
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("The feedTimeoutMs option", () => {
beforeEach(() => {
jasmine.clock().install();
});

it("if greater than zero, should timeout as configured", async () => {
const opts = {
feedTimeoutMs: 1000
Expand Down Expand Up @@ -841,17 +805,9 @@ describe("The feedTimeoutMs option", () => {
expect(feedListener.close.calls.count()).toBe(0);
expect(feedListener.action.calls.count()).toBe(0);
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("The reconnect option", () => {
beforeEach(() => {
jasmine.clock().install();
});

it("if true, should reconnect if the connection fails", async () => {
const opts = {
reconnect: true
Expand Down Expand Up @@ -891,17 +847,9 @@ describe("The reconnect option", () => {
expect(harness.transport.state.calls.argsFor(i).length).toBe(0);
}
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("The reopenMaxAttempts and reopenTrailingMs options", () => {
beforeEach(() => {
jasmine.clock().install();
});

it("if reopenMaxAttempts is negative, should always try to re-open the feed", async () => {
const opts = {
reopenMaxAttempts: -1
Expand Down Expand Up @@ -1278,10 +1226,6 @@ describe("The reopenMaxAttempts and reopenTrailingMs options", () => {
expect(feedListener.close.calls.count()).toBe(0);
expect(feedListener.action.calls.count()).toBe(0);
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

/*
Expand All @@ -1308,10 +1252,6 @@ For each operation, check
*/

describe("The client.connect() function", () => {
beforeEach(() => {
jasmine.clock().install();
});

// Errors and return values

describe("throw and return", () => {
Expand Down Expand Up @@ -2260,17 +2200,9 @@ describe("The client.connect() function", () => {
});

// Callbacks - N/A

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("The client.disconnect() function", () => {
beforeEach(() => {
jasmine.clock().install();
});

// Errors and return values

describe("throw and return", () => {
Expand Down Expand Up @@ -2682,17 +2614,9 @@ describe("The client.disconnect() function", () => {
});

// Callbacks - N/A

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("The client.action() function", () => {
beforeEach(() => {
jasmine.clock().install();
});

// Errors and return values

describe("throw and return - callback style", () => {
Expand Down Expand Up @@ -3400,10 +3324,6 @@ describe("The client.action() function", () => {
);
});
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("The client.feed() function", () => {
Expand Down Expand Up @@ -3446,10 +3366,6 @@ functions, events, and transport calls are then tested internally for each.
*/

describe("The feed.desireOpen() function", () => {
beforeEach(() => {
jasmine.clock().install();
});

describe("throw and return", () => {
it("should throw if already desired open", () => {
const harness = harnessFactory();
Expand Down Expand Up @@ -7162,17 +7078,9 @@ describe("The feed.desireOpen() function", () => {
});
});
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("The feed.desireClosed() function", () => {
beforeEach(() => {
jasmine.clock().install();
});

describe("throw and return", () => {
it("should throw if already desired closed", () => {
const harness = harnessFactory();
Expand Down Expand Up @@ -10022,10 +9930,6 @@ describe("The feed.desireClosed() function", () => {
});
});
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("The feed.destroy() function", () => {
Expand Down Expand Up @@ -10176,9 +10080,6 @@ describe("if the transport violates a library requirement", () => {
});

describe("if the transport unexpectedly disconnects", () => {
beforeEach(() => {
jasmine.clock().install();
});
let harness;
let feedDesiredClosed;
let feedClosed;
Expand Down Expand Up @@ -10409,10 +10310,6 @@ describe("if the transport unexpectedly disconnects", () => {
"DISCONNECTED: The transport disconnected."
);
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

/*
Expand Down Expand Up @@ -10500,10 +10397,6 @@ describe("structurally invalid server messages", () => {
});

describe("sequentially invalid server messages", () => {
beforeEach(() => {
jasmine.clock().install();
});

describe("unexpected HandshakeResponse - before Handshake", () => {
// Can't test, since Handshake is sent synchronously on transport connect
});
Expand Down Expand Up @@ -11249,10 +11142,6 @@ describe("sequentially invalid server messages", () => {

// Callbacks - N/A
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("Structurally/sequentially valid ViolationResponse message", () => {
Expand Down Expand Up @@ -11290,10 +11179,6 @@ describe("Structurally/sequentially valid ViolationResponse message", () => {
});

describe("Structurally/sequentially valid ActionRevelation message", () => {
beforeEach(() => {
jasmine.clock().install();
});

describe("if the server feed is open", () => {
let harness;
let feedWantedOpen;
Expand Down Expand Up @@ -12176,10 +12061,6 @@ describe("Structurally/sequentially valid ActionRevelation message", () => {
// Callbacks - N/A
});
});

afterEach(() => {
jasmine.clock().uninstall();
});
});

describe("Structurally/sequentially valid FeedTermination message", () => {
Expand Down

0 comments on commit 22f9102

Please sign in to comment.