Clean up deterministic tests

This commit is contained in:
Andras Schmelczer 2026-03-28 11:12:43 +00:00
parent 7b9287ca52
commit f36a84b275
113 changed files with 1366 additions and 3835 deletions

View file

@ -1,42 +1,9 @@
import type { ClientState, TestDefinition } from "../test-definition";
import { assert } from "../utils/assert";
/**
* EDGE CASE: Rapid create-update-delete cycle tests coalescing correctness.
*
* When events arrive faster than the queue can process them, coalescing
* determines the final action. This tests the full cycle:
*
* create + update = create (content read at sync time)
* create + delete = noop
*
* So a create-update-delete sequence should coalesce to noop and never
* reach the server at all.
*
* But then a new create follows:
* noop + create = create
*
* The final file should be synced correctly.
*/
function verifyFinalState(state: ClientState): void {
assert(
state.files.size === 1,
`Expected 1 file, got ${state.files.size}: ${Array.from(state.files.keys()).join(", ")}`
);
assert(state.files.has("cycle.md"), "Expected cycle.md to exist");
const content = state.files.get("cycle.md") ?? "";
assert(
content === "final creation",
`Expected "final creation", got: "${content}"`
);
}
import type { TestDefinition } from "../test-definition";
export const rapidCreateUpdateDeleteCycleTest: TestDefinition = {
name: "Rapid Create-Update-Delete-Create Cycle",
description:
"Client 0 rapidly creates, updates, deletes, then re-creates a file. " +
"The event coalescing should correctly reduce this to a single create " +
"of the final content. Client 1 should see only the final file.",
"Client 0 rapidly creates, updates, deletes, then re-creates a file while the server is paused. " +
"After the server resumes, client 1 must see only the final file.",
clients: 2,
steps: [
{ type: "enable-sync", client: 0 },
@ -44,10 +11,8 @@ export const rapidCreateUpdateDeleteCycleTest: TestDefinition = {
{ type: "sync" },
{ type: "barrier" },
// Pause server so all operations coalesce before being processed
{ type: "pause-server" },
// Rapid cycle: create → update → delete
{
type: "create",
client: 0,
@ -62,7 +27,6 @@ export const rapidCreateUpdateDeleteCycleTest: TestDefinition = {
},
{ type: "delete", client: 0, path: "cycle.md" },
// Re-create with final content
{
type: "create",
client: 0,
@ -70,11 +34,13 @@ export const rapidCreateUpdateDeleteCycleTest: TestDefinition = {
content: "final creation"
},
// Resume server
{ type: "resume-server" },
{ type: "sync" },
{ type: "barrier" },
{ type: "assert-consistent", verify: verifyFinalState }
{
type: "assert-consistent",
verify: (s) => s.assertFileCount(1).assertContent("cycle.md", "final creation"),
}
]
};