Skip to content

Commit

Permalink
Merge pull request redis-rs#250 from shachlanAmazon/node-timeouts
Browse files Browse the repository at this point in the history
Node cluster tests: don't delete folder on failure
  • Loading branch information
shachlanAmazon authored Jun 7, 2023
2 parents 6efcf54 + b1697df commit 512185e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
11 changes: 9 additions & 2 deletions node/tests/ClusterSocketConnection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class RedisCluster {
}

describe("ClusterSocketConnection", () => {
let testsFailed = 0;
let cluster: RedisCluster;
beforeAll(async () => {
cluster = await RedisCluster.createCluster(3, 0);
Expand All @@ -96,7 +97,9 @@ describe("ClusterSocketConnection", () => {
});

afterAll(async () => {
await cluster.dispose();
if (testsFailed === 0) {
await cluster.dispose();
}
});

const getOptions = (ports: number[]): ConnectionOptions => {
Expand All @@ -110,6 +113,7 @@ describe("ClusterSocketConnection", () => {

runBaseTests<Context>({
init: async () => {
testsFailed += 1;
const client = await ClusterSocketConnection.CreateConnection(
getOptions(cluster.ports())
);
Expand All @@ -120,7 +124,10 @@ describe("ClusterSocketConnection", () => {
client,
};
},
close: (context: Context) => {
close: (context: Context, testSucceeded: boolean) => {
if (testSucceeded) {
testsFailed -= 1;
}
context.client.dispose();
},
timeout: TIMEOUT,
Expand Down
15 changes: 9 additions & 6 deletions node/tests/SharedTests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, it } from "@jest/globals";
import { expect, fit, it, xit } from "@jest/globals";
import { v4 as uuidv4 } from "uuid";
import { Client, GetAndSetRandomValue } from "./TestUtilities";

Expand All @@ -17,18 +17,19 @@ type BaseClient = {

export function runBaseTests<Context>(config: {
init: () => Promise<{ context: Context; client: BaseClient }>;
close: (context: Context) => void;
close: (context: Context, testSucceeded: boolean) => void;
timeout?: number;
}) {
runCommonTests(config);

const runTest = async (test: (client: BaseClient) => Promise<void>) => {
const { context, client } = await config.init();

let testSucceeded = false;
try {
await test(client);
testSucceeded = true;
} finally {
config.close(context);
config.close(context, testSucceeded);
}
};

Expand Down Expand Up @@ -111,16 +112,18 @@ export function runBaseTests<Context>(config: {

export function runCommonTests<Context>(config: {
init: () => Promise<{ context: Context; client: Client }>;
close: (context: Context) => void;
close: (context: Context, testSucceeded: boolean) => void;
timeout?: number;
}) {
const runTest = async (test: (client: Client) => Promise<void>) => {
const { context, client } = await config.init();
let testSucceeded = false;

try {
await test(client);
testSucceeded = true;
} finally {
config.close(context);
config.close(context, testSucceeded);
}
};

Expand Down

0 comments on commit 512185e

Please sign in to comment.