@fluidframework/test-runtime-utils
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

@fluidframework/test-runtime-utils

Test utilities for the Fluid Framework Runtime. Include mock implementation of various runtime interfaces, as well as a mock logger for validating a particular log sequence.

Writing unit test for a DDS

Unit tests for DDS fall under three broad categories. The following sections explain how to write a unit test for these categories using the mocks in this package.

Local unit tests

These are tests that do not require a remote DDS and so doesn't need the DDS to be connected. For example, testing that DDS APIs work correctly, local events are correctly fired, summary is generated and loaded correctly, etc. To write a unit test for these scenarios, follow these steps:

  • Create a MockFluidDataStoreRuntime. The MockFluidDataStoreRuntime doesn't really do anything and is just used to create the DDS.
  • Set the MockFluidDataStoreRuntime's local property to true. This will make sure that the ops generated by the DDS are not sent out.
  • Use the MockFluidDataStoreRuntime to create the DDS.

Examples - map, directory, matrix.

Remote unit tests

These are tests that require a remote DDS and need the DDS to be connected. For example, testing that the op is correctly applied on a remote client, local op is correctly ack'd, remote events are correctly fired, etc. To write a unit test for these scenarios, follow these steps:

  • Create a MockFluidDataStoreRuntime.
  • Use the MockFluidDataStoreRuntime to create the DDS.
  • We need the ability to process messages from multiple DDSes / clients. Create a MockContainerRuntimeFactory which stores messages from multiple clients and processes them when required.
  • Create a MockContainerRuntime by calling createContainerRuntime on the MockContainerRuntimeFactory. MockContainerRuntime keeps track of the message and localOpMetadata until it is ack'd.
  • We need to connect and attach the DDS to an IDeltaConnection so it can submit and process messages. Create a MockDeltaConnection by calling createDeltaConnection on the MockContainerRuntime.
  • Use the MockDeltaConnection to connect the DDS.

Examples - sequenceHandler, snapshotVersion.

Reconnection unit tests

These are remote unit tests and in addition they need the capability to disconnect and reconnect the client. For example, testing that on reconnection - DDSes resubmits ops correctly, remote clients receive ops correctly, local clients ack the ops correctly, etc. To write a unit test for these scenarios, follow these steps:

  • Follow all the steps from scenario 2 above with these changes:
    • Create MockContainerRuntimeFactoryForReconnection instead of MockContainerRuntimeFactory.
    • Create MockContainerRuntimeForReconnection instead of MockContainerRuntime.
  • To disconnect the client, set connected = false on the MockContainerRuntimeForReconnection. This will trigger a delete of outstanding messages for this client on the MockContainerRuntimeFactoryForReconnection.
  • To reconnect the client, set connection = true on the MockContainerRuntimeForReconnection. This will trigger a reSubmit call on the DDS to resubmit unack'd / unsent ops.

Examples - sharedString, consensusOrderedCollection, consensusRegisterCollection.

Readme

Keywords

none

Package Sidebar

Install

npm i @fluidframework/test-runtime-utils

Weekly Downloads

10,386

Version

1.4.0

License

MIT

Unpacked Size

368 kB

Total Files

66

Last publish

Collaborators

  • ms-fluid-bot
  • curtisman