UNPKG

@clickup/pg-microsharding

Version:
32 lines (27 loc) 950 B
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: "active", }); }); 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_inactive(${no});`), ); const { rows } = await clients[0].client.query( "SELECT unnest(microsharding_list_active_shards())", ); expect(rows.map((r) => shardNo(r.unnest))).toEqual([]); });