@clickup/pg-microsharding
Version:
Microshards support for PostgreSQL
34 lines (29 loc) • 984 B
text/typescript
import range from "lodash/range";
import { shardNo } from "../internal/names";
import { promiseAllMap } from "../internal/promiseAllMap";
import { createTestConnectedClient } from "./internal/createTestConnectedClient";
import { ensureTestDBExists } from "./internal/ensureTestDBExists";
let testDsn: string;
beforeAll(async () => {
testDsn = await ensureTestDBExists({
from: 9990,
to: 9999,
state: "inactive",
});
});
test("race condition", async () => {
const clients = await promiseAllMap(range(9990, 9999 + 1), async (no) => ({
no,
client: await createTestConnectedClient(testDsn),
}));
// Simulate race update.
await promiseAllMap(clients, async ({ no, client }) =>
client.query(`SELECT microsharding_ensure_active(${no});`),
);
const { rows } = await clients[0].client.query(
"SELECT unnest(microsharding_list_active_shards())",
);
expect(rows.map((r) => shardNo(r.unnest))).toEqual(
clients.map(({ no }) => no),
);
});