Skip to content

Commit

Permalink
[TEST] added test for kick
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Sep 26, 2023
1 parent 5d15adc commit 5996a8f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
49 changes: 48 additions & 1 deletion tests/events_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Lock, NatsServer, ServerSignals } from "../tests/helpers/mod.ts";
import {
Lock,
NatsServer,
notCompatible,
ServerSignals,
} from "../tests/helpers/mod.ts";
import { connect, Events, ServersChanged } from "../src/mod.ts";
import { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";
import { delay, NatsConnectionImpl } from "../nats-base-client/internal_mod.ts";
Expand Down Expand Up @@ -131,6 +136,48 @@ Deno.test("events - ldm", async () => {
await NatsServer.stopAll(cluster);
});

Deno.test("events - kick", async () => {
const cluster = await NatsServer.cluster(2, {
system_account: "SYS",
no_auth_user: "a",
accounts: {
A: {
users: [{ user: "a", password: "a" }],
},
SYS: {
users: [{ user: "sys", password: "sys" }],
},
},
});

if (await cluster[0].notCompatible("2.10.0")) {
await NatsServer.stopAll(cluster);
}

const a = await connect(
{
servers: `127.0.0.1:${cluster[0].port}`,
user: "a",
pass: "a",
reconnect: false,
},
);
const sys = await connect(
{ servers: `127.0.0.1:${cluster[0].port}`, user: "sys", pass: "sys" },
);

await sys.request(
`$SYS.REQ.SERVER.${a.info?.server_id}.KICK`,
JSON.stringify(
{ CID: a.info?.client_id },
),
);

await a.closed();
await sys.close();
await NatsServer.stopAll(cluster);
});

Deno.test("events - ignore server updates", async () => {
const cluster = await NatsServer.cluster(1);
const nc = await connect(
Expand Down
20 changes: 18 additions & 2 deletions tests/helpers/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
*/
// deno-lint-ignore-file no-explicit-any
import * as path from "https://deno.land/[email protected]/path/mod.ts";
import { rgb24 } from "https://deno.land/[email protected]/fmt/colors.ts";
import { check, jsopts } from "./mod.ts";
import { rgb24, yellow } from "https://deno.land/[email protected]/fmt/colors.ts";
import { check, cleanup, jsopts } from "./mod.ts";
import {
compare,
Deferred,
deferred,
delay,
extend,
NatsConnection,
nuid,
parseSemVer,
timeout,
} from "../../nats-base-client/internal_mod.ts";

Expand Down Expand Up @@ -621,6 +624,19 @@ export class NatsServer implements PortInfo {
throw err;
}
}

async notCompatible(version = "2.3.3"): Promise<boolean> {
const varz = await this.varz() as unknown as Record<string, string>;
const sv = parseSemVer(varz.version);
if (compare(sv, parseSemVer(version)) < 0) {
const m = new TextEncoder().encode(yellow(
`skipping test as server (${varz.version}) doesn't implement required feature from ${version} `,
));
await Deno.stdout.write(m);
return true;
}
return false;
}
}

// @ts-ignore: any is exactly what we need here
Expand Down

0 comments on commit 5996a8f

Please sign in to comment.