Skip to content

Commit

Permalink
Cleanup mock APIs (#16568)
Browse files Browse the repository at this point in the history
## Description

These capabilities have been added as optional in `main` for
compatibility reasons. In `next` we can make them required.

Leftover from
[AB#4980](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/4980)
  • Loading branch information
andre4i authored Jul 31, 2023
1 parent f66242c commit e43927f
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
7 changes: 7 additions & 0 deletions .changeset/evil-rooms-deny.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions api-report/test-runtime-utils.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<IMockContainerRuntimeOptions>;
// (undocumented)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions packages/dds/map/src/test/mocha/rebasing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
5 changes: 0 additions & 5 deletions packages/dds/sequence/src/test/rebasing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions packages/runtime/test-runtime-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@
"broken": {
"ClassDeclaration_MockFluidDataStoreContext": {
"backCompat": false
},
"ClassDeclaration_MockContainerRuntime": {
"forwardCompat": false
},
"ClassDeclaration_MockContainerRuntimeForReconnection": {
"forwardCompat": false
},
"ClassDeclaration_MockFluidDataStoreRuntime": {
"forwardCompat": false
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions packages/runtime/test-runtime-utils/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ declare function get_old_ClassDeclaration_MockContainerRuntime():
declare function use_current_ClassDeclaration_MockContainerRuntime(
use: TypeOnly<current.MockContainerRuntime>);
use_current_ClassDeclaration_MockContainerRuntime(
// @ts-expect-error compatibility expected to be broken
get_old_ClassDeclaration_MockContainerRuntime());

/*
Expand Down Expand Up @@ -167,6 +168,7 @@ declare function get_old_ClassDeclaration_MockContainerRuntimeForReconnection():
declare function use_current_ClassDeclaration_MockContainerRuntimeForReconnection(
use: TypeOnly<current.MockContainerRuntimeForReconnection>);
use_current_ClassDeclaration_MockContainerRuntimeForReconnection(
// @ts-expect-error compatibility expected to be broken
get_old_ClassDeclaration_MockContainerRuntimeForReconnection());

/*
Expand Down Expand Up @@ -312,6 +314,7 @@ declare function get_old_ClassDeclaration_MockFluidDataStoreRuntime():
declare function use_current_ClassDeclaration_MockFluidDataStoreRuntime(
use: TypeOnly<current.MockFluidDataStoreRuntime>);
use_current_ClassDeclaration_MockFluidDataStoreRuntime(
// @ts-expect-error compatibility expected to be broken
get_old_ClassDeclaration_MockFluidDataStoreRuntime());

/*
Expand Down

0 comments on commit e43927f

Please sign in to comment.