Skip to content

Commit

Permalink
Merge cc5d062 into 47b2faa
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Dec 1, 2022
2 parents 47b2faa + cc5d062 commit 12ea7e5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 57 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nats",
"version": "2.9.1",
"version": "2.9.2",
"description": "Node.js client for NATS, a lightweight, high-performance cloud native messaging system",
"keywords": [
"nats",
Expand Down Expand Up @@ -40,7 +40,7 @@
"build": "tsc",
"cjs": "deno run --allow-all bin/cjs-fix-imports.ts -o nats-base-client/ ./.deps/nats.deno/nats-base-client/",
"clean": "shx rm -Rf ./lib/* ./nats-base-client ./.deps",
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch v1.9.2 https://github.com/nats-io/nats.deno.git",
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch v1.9.3 https://github.com/nats-io/nats.deno.git",
"fmt": "deno fmt ./src/ ./examples/ ./test/",
"prepack": "npm run clone-nbc && npm run cjs && npm run check-package && npm run build",
"ava": "nyc ava --verbose -T 60000",
Expand Down
2 changes: 1 addition & 1 deletion src/node_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const { resolve } = require("path");
const { readFile, existsSync } = require("fs");
const dns = require("dns");

const VERSION = "2.9.1";
const VERSION = "2.9.2";
const LANG = "nats.js";

export class NodeTransport implements Transport {
Expand Down
61 changes: 7 additions & 54 deletions test/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,62 +487,15 @@ test("basics - server gone", async (t) => {
});

test("basics - server error", async (t) => {
const PING = { re: /^PING\r\n/i, out: "PONG\r\n" };
const CONNECT = { re: /^CONNECT\s+([^\r\n]+)\r\n/i, out: "" };

const CMDS = [PING, CONNECT];

let inbound;

const pp = deferred();
const server = net.createServer();
server.on("connection", (conn) => {
const buf = Buffer.from(
`INFO {"server_id":"FAKE","server_name":"FAKE","version":"2.9.4","proto":1,"go":"go1.19.2","host":"127.0.0.1","port":${port},"headers":true,"max_payload":1048576,"jetstream":true,"client_id":4,"client_ip":"127.0.0.1"}\r\n`,
);
conn.write(buf);

conn.on("data", (data) => {
if (inbound) {
inbound = Buffer.concat([inbound, data]);
} else {
inbound = data;
}
while (data.length > 0) {
let m = null;
for (let i = 0; i < CMDS.length; i++) {
m = CMDS[i].re.exec(inbound);
if (m) {
const len = m[0].length;
if (len <= inbound.length) {
inbound = inbound.slice(len);
conn.write(Buffer.from(CMDS[i].out));
if (i === 0) {
// fail as if the server sent an error
conn.write(Buffer.from("-ERR 'here'\r\n"));
}
break;
}
}
}
if (m === null) {
break;
}
}
});
});

server.listen(0, (v) => {
const p = server.address().port;
pp.resolve(p);
const ns = await NatsServer.start();
t.plan(1);
const nc = await connect({ port: ns.port, reconnect: false });
setTimeout(() => {
nc.protocol.sendCommand("X\r\n");
});

const port = await pp;
const nc = await connect({ port, reconnect: false });
const err = await nc.closed();
t.is(err.message, "'here'");

server.close();
t.is(err?.code, ErrorCode.ProtocolError);
await ns.stop();
});

test("basics - subscription with timeout", async (t) => {
Expand Down

0 comments on commit 12ea7e5

Please sign in to comment.