Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup mock APIs #16568

Merged
merged 4 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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