-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- http2-assertion-failure should use classic append - write-after-end should test both append styles - reconnect tests should use classic append
- Loading branch information
1 parent
b4ba1a9
commit a149a27
Showing
3 changed files
with
128 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,96 @@ | ||
import { createTestNode, delay, jsonTestEvents } from "@test-utils"; | ||
/** @jest-environment ./src/__test__/utils/enableVersionCheck.ts */ | ||
|
||
import { | ||
createTestNode, | ||
delay, | ||
jsonTestEvents, | ||
matchServerVersion, | ||
optionalTest, | ||
} from "@test-utils"; | ||
import { EventStoreDBClient, UnavailableError } from "@eventstore/db-client"; | ||
|
||
describe("write after end", () => { | ||
const node = createTestNode(); | ||
let client!: EventStoreDBClient; | ||
// These tests can take time. | ||
jest.setTimeout(120_000); | ||
|
||
beforeAll(async () => { | ||
describe("write after end", () => { | ||
test("Should not write after end", async () => { | ||
const node = createTestNode(); | ||
await node.up(); | ||
client = new EventStoreDBClient( | ||
|
||
const client = new EventStoreDBClient( | ||
{ endpoint: node.uri }, | ||
{ rootCertificate: node.rootCertificate }, | ||
{ username: "admin", password: "changeit" } | ||
{ rootCertificate: node.rootCertificate } | ||
); | ||
}); | ||
|
||
afterAll(async () => { | ||
await node.down(); | ||
}); | ||
|
||
test("Should not write after end", async () => { | ||
const STREAM_NAME = "json_stream_name"; | ||
await client.appendToStream(STREAM_NAME, jsonTestEvents()); | ||
|
||
client | ||
.appendToStream(STREAM_NAME, jsonTestEvents(100_000)) | ||
.then((result) => { | ||
expect(result).toBe("unreachable"); | ||
}) | ||
.catch((e) => { | ||
expect(e).toBeInstanceOf(UnavailableError); | ||
await client.appendToStream(STREAM_NAME, jsonTestEvents(), { | ||
// credentials enforces classic append | ||
credentials: { username: "admin", password: "changeit" }, | ||
}); | ||
|
||
const writeUntilError = () => | ||
new Promise((resolve) => { | ||
const writeOnLoop = (): Promise<never> => | ||
client | ||
.appendToStream(STREAM_NAME, jsonTestEvents(30_000), { | ||
// credentials enforces classic append | ||
credentials: { username: "admin", password: "changeit" }, | ||
}) | ||
.then(writeOnLoop); | ||
|
||
writeOnLoop().catch((e) => { | ||
resolve(e); | ||
}); | ||
}); | ||
|
||
node.killNode(node.endpoints[0]); | ||
const errorPromise = writeUntilError(); | ||
|
||
await node.killNode(node.endpoints[0]); | ||
|
||
const error = await errorPromise; | ||
expect(error).toBeInstanceOf(UnavailableError); | ||
|
||
// wait for any unhandled rejections | ||
await delay(5_000); | ||
|
||
await node.down(); | ||
}); | ||
|
||
optionalTest(matchServerVersion`>=21.10`)( | ||
"Should not write after end (batch append)", | ||
async () => { | ||
const node = createTestNode(); | ||
await node.up(); | ||
|
||
const client = new EventStoreDBClient( | ||
{ endpoint: node.uri }, | ||
{ rootCertificate: node.rootCertificate } | ||
); | ||
|
||
const STREAM_NAME = "json_stream_name"; | ||
await client.appendToStream(STREAM_NAME, jsonTestEvents()); | ||
|
||
const writeUntilError = () => | ||
new Promise((resolve) => { | ||
const writeOnLoop = (): Promise<never> => | ||
client | ||
.appendToStream(STREAM_NAME, jsonTestEvents(30_000)) | ||
.then(writeOnLoop); | ||
|
||
writeOnLoop().catch((e) => { | ||
resolve(e); | ||
}); | ||
}); | ||
|
||
const errorPromise = writeUntilError(); | ||
|
||
await node.killNode(node.endpoints[0]); | ||
|
||
const error = await errorPromise; | ||
expect(error).toBeInstanceOf(UnavailableError); | ||
|
||
// wait for any unhandled rejections | ||
await delay(5_000); | ||
} | ||
); | ||
}); |