Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ class Connection extends EventEmitter {
throw new Error("Connection is closing");
}

if (!this.socket) {
throw new Error("Socket is not connected");
}

return new Promise((resolve, reject) => {
this.socket.write(string, (err) => (err ? reject(err) : resolve()));
});
Expand Down
64 changes: 14 additions & 50 deletions test/stream-management.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ const domain = "localhost";

let xmpp;

afterEach(async () => {
await xmpp?.stop();
await server.reset();
beforeAll(async () => {
await server.enableModules(["smacks"]);
});

test("client ack stanzas", async () => {
await server.enableModules(["smacks"]);
beforeEach(async () => {
await server.restart();
});

afterAll(async () => {
try {
await xmpp?.stop();
} finally {
await server.reset();
}
});

test("client ack stanzas", async () => {

xmpp = client({ credentials, service: domain });
debug(xmpp);
Expand All @@ -36,9 +45,6 @@ test("client ack stanzas", async () => {
});

test("client fail stanzas", async () => {
await server.enableModules(["smacks"]);
await server.restart();

xmpp = client({ credentials, service: domain });
debug(xmpp);

Expand All @@ -60,9 +66,6 @@ test("client fail stanzas", async () => {
});

test("client retry stanzas", async () => {
await server.enableModules(["smacks"]);
await server.restart();

xmpp = client({ credentials, service: domain });
debug(xmpp);

Expand All @@ -86,9 +89,6 @@ test("client retry stanzas", async () => {
});

test("client reconnects when server fails to ack stanza", async () => {
await server.enableModules(["smacks"]);
await server.restart();

xmpp = client({ credentials, service: domain });
xmpp.streamManagement.timeout = 10;
xmpp.streamManagement.requestAckInterval = 5;
Expand All @@ -110,39 +110,3 @@ test("client reconnects when server fails to ack stanza", async () => {
await promise_resumed;
expect().pass();
});

test("pings do not prevent timeout", async () => {
await server.enableModules(["smacks"]);
await server.restart();

xmpp = client({ credentials, service: domain });
xmpp.streamManagement.timeout = 10;
xmpp.streamManagement.requestAckInterval = 5;

// Make sure an ack request is sent right away after a stanza
xmpp.streamManagement.debounceAckRequest = 1;
debug(xmpp);

let promise_disconnect = new Promise((resolve) => {
xmpp.disconnect = () => {
resolve();
return Promise.resolve(null);
};
});
await xmpp.start();

// Send just any stanza to trigger the act request send
xmpp.send(
<iq to={domain} id="ping" type="get">
<ping xmlns="urn:xmppp:ping" />
</iq>,
);

// Pretend we don't receive the ack by removing event listeners
// on the socket, so that the timeout can fire
xmpp._detachSocket();

// Timeout fires, and disconnect happens
await promise_disconnect;
expect().pass();
});