FluidFramework icon indicating copy to clipboard operation
FluidFramework copied to clipboard

tests(staging-mode): Add basic unit test coverage for changes to ContainerRuntime and related code

Open markfields opened this issue 8 months ago • 0 comments

Fixes AB#1596 Fixes AB#32404

Description

The recent addition of Staging Mode has test coverage via Local Server Stress Tests, but the refactoring and other changes to core classes like ContainerRuntime and PendingStateManager don't have unit test coverage.

This PR adds the tests listed below.

ContainerRuntime unit tests

New describe block: Staging Mode:

  • it("entering and exiting updates inStagingMode flag")
  • it("entering staging mode twice not allowed")
  • it("cannot enter staging mode while attaching")
  • it("cannot enter staging mode while detached")
  • it("commitChanges submits staged ops")
  • it("discardChanges drops staged ops")
  • it("discardChanges resets isDirty state")

PendingStateManager unit tests

New describe block: replayPendingStates

  • it("should replay all pending states as batches [batch sizes: ..., ...]") (parameterized, many cases)
  • it("should replay only staged batches when committingStagedBatches is true")
  • it("should throw if replayPendingStates is called twice for same clientId without committingStagedBatches")
  • it("should set squash flag when replayPendingStates is called with squash: true")

New describe block: popStagedBatches

  • it("should pop all staged batch messages in LIFO order and invoke callback")
  • it("should not pop unstaged messages")
  • it("should not invoke callback for empty batch or messages without runtimeOp")
  • it("should do nothing if there are no staged messages")

Reviewer Guidance

There are some small changes to the code files, almost entirely minor benign things like comments, renames, trivial refactors.

There is one behavior change, which is to fix a bug I discovered when adding tests. It fixes an infinite loop in PendingStateManager.popStagedBatches that would happen if a batch became empty during staging mode and then we discarded changes.

markfields avatar May 28 '25 22:05 markfields