diff --git a/.changeset/evil-rooms-deny.md b/.changeset/evil-rooms-deny.md new file mode 100644 index 000000000000..b83c7c6b282d --- /dev/null +++ b/.changeset/evil-rooms-deny.md @@ -0,0 +1,7 @@ +--- +"@fluidframework/test-runtime-utils": major +--- + +`MockContainerRuntime` has two new required methods, `flush()` and `rebase()`. `MockFluidDataStoreRuntime` has one new required method, `createDeltaConnection`. + +To enable testing scenarios involving batches of ops, `MockContainerRuntime` has two new required methods, `flush()` and `rebase()`. Depending on the `IMockContainerRuntimeOptions` supplied to the mock runtime, these two new methods must be used accordingly. For the same reason, `MockFluidDataStoreRuntime` implements the `createDeltaConnection` method, along with managing the mock delta connection lifecycle in a single place. diff --git a/api-report/test-runtime-utils.api.md b/api-report/test-runtime-utils.api.md index 3ddad30e7677..8736ebb48554 100644 --- a/api-report/test-runtime-utils.api.md +++ b/api-report/test-runtime-utils.api.md @@ -113,7 +113,7 @@ export class MockContainerRuntime { dirty(): void; // (undocumented) protected readonly factory: MockContainerRuntimeFactory; - flush?(): void; + flush(): void; // (undocumented) protected readonly overrides?: { minimumSequenceNumber?: number | undefined; @@ -122,7 +122,7 @@ export class MockContainerRuntime { protected readonly pendingMessages: IMockContainerRuntimePendingMessage[]; // (undocumented) process(message: ISequencedDocumentMessage): void; - rebase?(): void; + rebase(): void; protected get referenceSequenceNumber(): number; protected runtimeOptions: Required; // (undocumented) @@ -408,7 +408,7 @@ export class MockFluidDataStoreRuntime extends EventEmitter implements IFluidDat // (undocumented) createChannel(id: string, type: string): IChannel; // (undocumented) - createDeltaConnection?(): MockDeltaConnection; + createDeltaConnection(): MockDeltaConnection; // (undocumented) deltaManager: MockDeltaManager; // (undocumented) diff --git a/packages/dds/map/src/test/mocha/rebasing.spec.ts b/packages/dds/map/src/test/mocha/rebasing.spec.ts index 30df4ba1ef75..76d9baa9c4c2 100644 --- a/packages/dds/map/src/test/mocha/rebasing.spec.ts +++ b/packages/dds/map/src/test/mocha/rebasing.spec.ts @@ -63,11 +63,6 @@ describe("Rebasing", () => { }); it("Rebasing ops maintains eventual consistency", () => { - assert(containerRuntime1.rebase !== undefined, "Unsupported test-utils version"); - assert(containerRuntime1.flush !== undefined, "Unsupported test-utils version"); - assert(containerRuntime2.rebase !== undefined, "Unsupported test-utils version"); - assert(containerRuntime2.flush !== undefined, "Unsupported test-utils version"); - const keyCount = 10; for (let i = 0; i < keyCount; i++) { map1.set(`${i}`, map1.size); @@ -169,11 +164,6 @@ describe("Rebasing", () => { }; it("Rebasing ops maintains eventual consistency", () => { - assert(containerRuntime1.rebase !== undefined, "Unsupported test-utils version"); - assert(containerRuntime1.flush !== undefined, "Unsupported test-utils version"); - assert(containerRuntime2.rebase !== undefined, "Unsupported test-utils version"); - assert(containerRuntime2.flush !== undefined, "Unsupported test-utils version"); - dir2.on("valueChanged", (changed) => { if (changed.key === "key") { dir2.set("valueChanged", "valueChanged"); diff --git a/packages/dds/sequence/src/test/rebasing.spec.ts b/packages/dds/sequence/src/test/rebasing.spec.ts index e338feca1d87..5a0a48ce8567 100644 --- a/packages/dds/sequence/src/test/rebasing.spec.ts +++ b/packages/dds/sequence/src/test/rebasing.spec.ts @@ -71,11 +71,6 @@ import { SharedStringFactory } from "../sequenceFactory"; }); it("Rebasing ops maintains eventual consistency", async () => { - assert(containerRuntime1.rebase !== undefined, "Unsupported test-utils version"); - assert(containerRuntime1.flush !== undefined, "Unsupported test-utils version"); - assert(containerRuntime2.rebase !== undefined, "Unsupported test-utils version"); - assert(containerRuntime2.flush !== undefined, "Unsupported test-utils version"); - sharedString1.insertText(0, "ad"); sharedString1.insertText(1, "c"); containerRuntime1.flush(); diff --git a/packages/runtime/test-runtime-utils/package.json b/packages/runtime/test-runtime-utils/package.json index 77a4c77b5c05..17a8097d1089 100644 --- a/packages/runtime/test-runtime-utils/package.json +++ b/packages/runtime/test-runtime-utils/package.json @@ -104,6 +104,15 @@ "broken": { "ClassDeclaration_MockFluidDataStoreContext": { "backCompat": false + }, + "ClassDeclaration_MockContainerRuntime": { + "forwardCompat": false + }, + "ClassDeclaration_MockContainerRuntimeForReconnection": { + "forwardCompat": false + }, + "ClassDeclaration_MockFluidDataStoreRuntime": { + "forwardCompat": false } } } diff --git a/packages/runtime/test-runtime-utils/src/mocks.ts b/packages/runtime/test-runtime-utils/src/mocks.ts index 3348b71bcf54..a2057301f37b 100644 --- a/packages/runtime/test-runtime-utils/src/mocks.ts +++ b/packages/runtime/test-runtime-utils/src/mocks.ts @@ -182,10 +182,6 @@ export class MockContainerRuntime { } public createDeltaConnection(): MockDeltaConnection { - assert( - this.dataStoreRuntime.createDeltaConnection !== undefined, - "Unsupported datastore runtime version", - ); const deltaConnection = this.dataStoreRuntime.createDeltaConnection(); this.deltaConnections.push(deltaConnection); return deltaConnection; @@ -223,7 +219,7 @@ export class MockContainerRuntime { * If flush mode is set to FlushMode.TurnBased, it will send all messages queued since the last time * this method was called. Otherwise, calling the method does nothing. */ - public flush?() { + public flush() { if (this.runtimeOptions.flushMode !== FlushMode.TurnBased) { return; } @@ -240,7 +236,7 @@ export class MockContainerRuntime { * * The method requires `runtimeOptions.enableGroupedBatching` to be enabled. */ - public rebase?() { + public rebase() { if (this.runtimeOptions.flushMode !== FlushMode.TurnBased) { return; } @@ -594,7 +590,7 @@ export class MockFluidDataStoreRuntime public quorum = new MockQuorumClients(); public containerRuntime?: MockContainerRuntime; private readonly deltaConnections: MockDeltaConnection[] = []; - public createDeltaConnection?(): MockDeltaConnection { + public createDeltaConnection(): MockDeltaConnection { const deltaConnection = new MockDeltaConnection( (messageContent: any, localOpMetadata: unknown) => this.submitMessageInternal(messageContent, localOpMetadata), diff --git a/packages/runtime/test-runtime-utils/src/test/types/validateTestRuntimeUtilsPrevious.generated.ts b/packages/runtime/test-runtime-utils/src/test/types/validateTestRuntimeUtilsPrevious.generated.ts index 1cf379793462..3338c2db0342 100644 --- a/packages/runtime/test-runtime-utils/src/test/types/validateTestRuntimeUtilsPrevious.generated.ts +++ b/packages/runtime/test-runtime-utils/src/test/types/validateTestRuntimeUtilsPrevious.generated.ts @@ -95,6 +95,7 @@ declare function get_old_ClassDeclaration_MockContainerRuntime(): declare function use_current_ClassDeclaration_MockContainerRuntime( use: TypeOnly); use_current_ClassDeclaration_MockContainerRuntime( + // @ts-expect-error compatibility expected to be broken get_old_ClassDeclaration_MockContainerRuntime()); /* @@ -167,6 +168,7 @@ declare function get_old_ClassDeclaration_MockContainerRuntimeForReconnection(): declare function use_current_ClassDeclaration_MockContainerRuntimeForReconnection( use: TypeOnly); use_current_ClassDeclaration_MockContainerRuntimeForReconnection( + // @ts-expect-error compatibility expected to be broken get_old_ClassDeclaration_MockContainerRuntimeForReconnection()); /* @@ -312,6 +314,7 @@ declare function get_old_ClassDeclaration_MockFluidDataStoreRuntime(): declare function use_current_ClassDeclaration_MockFluidDataStoreRuntime( use: TypeOnly); use_current_ClassDeclaration_MockFluidDataStoreRuntime( + // @ts-expect-error compatibility expected to be broken get_old_ClassDeclaration_MockFluidDataStoreRuntime()); /*