Skip to content

Commit 81130d3

Browse files
scottn12Copilot
andauthored
improvement(test-runtime-utils): Add flushSomeMessages() to MockContainerRuntime (#25330)
## Description This PR adds `flushSomeMessages()` to `MockContainerRuntime`. Similar to `flush` but will only flush the specified number of messages queued since the last time `flush` or `flushSomeMessages` was called. This is intended to help simulate staging mode scenarios where we may want to flush the pending ops queued prior to entering staging mode and not flush the ops queued since entering staging mode. --------- Co-authored-by: Copilot <[email protected]>
1 parent 6583182 commit 81130d3

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

packages/runtime/test-runtime-utils/api-report/test-runtime-utils.legacy.beta.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class MockContainerRuntime extends TypedEventEmitter<IContainerRuntimeEve
7373
// (undocumented)
7474
finalizeIdRange(range: IdCreationRange): void;
7575
flush(): void;
76+
flushSomeMessages(numMessages: number): void;
7677
// (undocumented)
7778
get isDirty(): boolean;
7879
protected maybeProcessIdAllocationMessage(message: ISequencedDocumentMessage): boolean;

packages/runtime/test-runtime-utils/package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,17 @@
153153
"typescript": "~5.4.5"
154154
},
155155
"typeValidation": {
156-
"broken": {},
156+
"broken": {
157+
"Class_MockFluidDataStoreRuntime": {
158+
"forwardCompat": false
159+
},
160+
"Class_MockContainerRuntimeForReconnection": {
161+
"forwardCompat": false
162+
},
163+
"Class_MockContainerRuntime": {
164+
"forwardCompat": false
165+
}
166+
},
157167
"entrypoint": "legacy"
158168
}
159169
}

packages/runtime/test-runtime-utils/src/mocks.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,21 @@ export class MockContainerRuntime extends TypedEventEmitter<IContainerRuntimeEve
337337

338338
/**
339339
* If flush mode is set to FlushMode.TurnBased, it will send all messages queued since the last time
340-
* this method was called. Otherwise, calling the method does nothing.
340+
* this method (or `flushSomeMessages`) was called. Otherwise, calling the method does nothing.
341341
*/
342342
public flush() {
343+
this.flushSomeMessages(this.outbox.length);
344+
}
345+
346+
/**
347+
* If flush mode is set to FlushMode.TurnBased, it will send the specified number of messages from the outbox
348+
* queued since the last time this (or `flush`) was called. Otherwise, calling the method does nothing.
349+
* This can be useful when simulating staging mode, and we only want to flush certain messages.
350+
*/
351+
public flushSomeMessages(numMessages: number): void {
352+
if (!Number.isInteger(numMessages) || numMessages < 0) {
353+
throw new Error("flushSomeMessages: numMessages must be a non-negative integer");
354+
}
343355
if (this.runtimeOptions.flushMode !== FlushMode.TurnBased) {
344356
return;
345357
}
@@ -352,10 +364,11 @@ export class MockContainerRuntime extends TypedEventEmitter<IContainerRuntimeEve
352364
this.idAllocationOutbox.push(idAllocationOp);
353365
}
354366

367+
const actualMessagesToSubmit = this.outbox.splice(0, numMessages);
368+
355369
// As with the runtime behavior, we need to send the idAllocationOps first
356-
const messagesToSubmit = this.idAllocationOutbox.concat(this.outbox);
370+
const messagesToSubmit = this.idAllocationOutbox.concat(actualMessagesToSubmit);
357371
this.idAllocationOutbox.length = 0;
358-
this.outbox.length = 0;
359372

360373
let fakeClientSequenceNumber = 1;
361374
messagesToSubmit.forEach((message) => {

packages/runtime/test-runtime-utils/src/test/types/validateTestRuntimeUtilsPrevious.generated.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ declare type current_as_old_for_Class_MockAudience = requireAssignableTo<TypeOnl
4040
* typeValidation.broken:
4141
* "Class_MockContainerRuntime": {"forwardCompat": false}
4242
*/
43+
// @ts-expect-error compatibility expected to be broken
4344
declare type old_as_current_for_Class_MockContainerRuntime = requireAssignableTo<TypeOnly<old.MockContainerRuntime>, TypeOnly<current.MockContainerRuntime>>
4445

4546
/*
@@ -94,6 +95,7 @@ declare type current_as_old_for_Class_MockContainerRuntimeFactoryForReconnection
9495
* typeValidation.broken:
9596
* "Class_MockContainerRuntimeForReconnection": {"forwardCompat": false}
9697
*/
98+
// @ts-expect-error compatibility expected to be broken
9799
declare type old_as_current_for_Class_MockContainerRuntimeForReconnection = requireAssignableTo<TypeOnly<old.MockContainerRuntimeForReconnection>, TypeOnly<current.MockContainerRuntimeForReconnection>>
98100

99101
/*
@@ -184,6 +186,7 @@ declare type current_as_old_for_Class_MockFluidDataStoreContext = requireAssigna
184186
* typeValidation.broken:
185187
* "Class_MockFluidDataStoreRuntime": {"forwardCompat": false}
186188
*/
189+
// @ts-expect-error compatibility expected to be broken
187190
declare type old_as_current_for_Class_MockFluidDataStoreRuntime = requireAssignableTo<TypeOnly<old.MockFluidDataStoreRuntime>, TypeOnly<current.MockFluidDataStoreRuntime>>
188191

189192
/*

0 commit comments

Comments
 (0)