/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import { TestDriverTypes } from "@fluid-internal/test-driver-definitions"; import { OptionsMatrix, booleanCases, generatePairwiseOptions, numberCases, } from "@fluid-private/test-pairwise-generator"; import { ILoaderOptions } from "@fluidframework/container-definitions/internal"; import { CompressionAlgorithms, disabledCompressionConfig, IGCRuntimeOptions, ISummaryRuntimeOptions, type ContainerRuntimeOptionsInternal, type IContainerRuntimeOptionsInternal, } from "@fluidframework/container-runtime/internal"; import { ConfigTypes } from "@fluidframework/core-interfaces"; import { LoggingError } from "@fluidframework/telemetry-utils/internal"; import type { OptionOverride, TestConfiguration } from "./testConfigFile.js"; interface ILoaderOptionsExperimental extends ILoaderOptions { enableOfflineSnapshotRefresh?: boolean; snapshotRefreshTimeoutMs?: number; } const loaderOptionsMatrix: OptionsMatrix = { cache: booleanCases, client: [undefined], provideScopeLoader: booleanCases, maxClientLeaveWaitTime: numberCases, enableOfflineSnapshotRefresh: booleanCases, snapshotRefreshTimeoutMs: [undefined, 60 * 5 * 1000 /* 5min */], }; export function applyOverrides>( options: OptionsMatrix, optionsOverrides: Partial> | undefined, ): OptionsMatrix { const realOptions: OptionsMatrix = { ...options }; if (optionsOverrides !== undefined) { // The cast is required because TS5 infers that 'key' must be in the set 'keyof T' and // notes that the type 'Partial>' may contain additional keys not in T. for (const key of Object.keys(optionsOverrides) as (string & keyof T)[]) { const override = optionsOverrides[key]; if (override !== undefined) { if (Array.isArray(override)) { realOptions[key] = override; } else { throw new LoggingError( `Override for ${key} is not array: ${JSON.stringify(optionsOverrides)}`, ); } } } } return realOptions; } export const generateLoaderOptions = ( seed: number, overrides: Partial> | undefined, ): ILoaderOptionsExperimental[] => { return generatePairwiseOptions( applyOverrides(loaderOptionsMatrix, overrides), seed, ); }; const gcOptionsMatrix: OptionsMatrix = { runFullGC: booleanCases, sessionExpiryTimeoutMs: [undefined], // Don't want sessions to expire at a fixed time enableGCSweep: [undefined], // Don't need coverage here, GC sweep is tested separately sweepGracePeriodMs: [undefined], // Don't need coverage here, GC sweep is tested separately }; const summaryOptionsMatrix: OptionsMatrix = { initialSummarizerDelayMs: numberCases, summaryConfigOverrides: [undefined], }; export function generateRuntimeOptions( seed: number, overrides: Partial> | undefined, ): IContainerRuntimeOptionsInternal[] { const gcOptions = generatePairwiseOptions( applyOverrides(gcOptionsMatrix, overrides?.gcOptions as any), seed, ); const summaryOptions = generatePairwiseOptions( applyOverrides(summaryOptionsMatrix, overrides?.summaryOptions as any), seed, ); // Warning: this appears to incorrectly use `undefined` as a value in the options matrix // with `exactOptionalPropertyTypes` disabled and thus not complaining. Note that `undefined` // is a valid option for `enableRuntimeIdCompressor`. Probably should replace `undefined` // with a sentinel symbol assuming `undefined` does mean something to overall processing. const runtimeOptionsMatrix: OptionsMatrix = { gcOptions: [undefined, ...gcOptions], summaryOptions: [undefined, ...summaryOptions], loadSequenceNumberVerification: [undefined], flushMode: [undefined], compressionOptions: [ { minimumBatchSizeInBytes: 500, compressionAlgorithm: CompressionAlgorithms.lz4 }, ], maxBatchSizeInBytes: [716800], // Compressed payloads exceeding this size will be chunked into messages of exactly this size chunkSizeInBytes: [204800], enableRuntimeIdCompressor: ["on", undefined, "delayed"], enableGroupedBatching: [true, false], createBlobPayloadPending: [true, undefined], explicitSchemaControl: [true, false], disableSchemaUpgrade: [false], stagingModeAutoFlushThreshold: [undefined], }; const pairwiseOptions = generatePairwiseOptions( applyOverrides(runtimeOptionsMatrix, { ...overrides, gcOptions: undefined, summaryOptions: undefined, }), seed, ); // Override compressionOptions to disable it if Grouped Batching is disabled pairwiseOptions.map((options) => { if (options.enableGroupedBatching === false) { ( options as { // Remove readonly modifier to allow overriding -readonly [P in keyof ContainerRuntimeOptionsInternal]: ContainerRuntimeOptionsInternal[P]; } ).compressionOptions = disabledCompressionConfig; } }); // Override explicitSchemaControl to enabled if createBlobPayloadPending is enabled pairwiseOptions.map((options) => { if (options.createBlobPayloadPending) { ( options as { // Remove readonly modifier to allow overriding -readonly [P in keyof ContainerRuntimeOptionsInternal]: ContainerRuntimeOptionsInternal[P]; } ).explicitSchemaControl = true; } }); return pairwiseOptions; } export function generateConfigurations( seed: number, overrides: OptionsMatrix> | undefined, ): Record[] { if (overrides === undefined) { return [{}]; } return generatePairwiseOptions>(overrides, seed); } /** * Extracts the appropriate option override from test configuration based on driver type and endpoint. * * @param testConfig - the ILoadTestConfig to extract the Option Override from * @param driverType - the DriverType being used in the test, used to determine which option override to pick * @param endpoint - the Endpoint being used in the test, used to determine which option override to pick * @returns an option override */ export function getOptionOverride( testConfig: TestConfiguration | undefined, driverType: TestDriverTypes, endpoint: string | undefined, ): OptionOverride | undefined { // Specifically using an all or nothing strategy as that's how our current test config options are written today // We first search for the key driverType-endpoint, if that doesn't exist then we just key on the driverType const driverEndpointOverride = `${driverType}-${endpoint}`; return ( testConfig?.optionOverrides?.[driverEndpointOverride] ?? testConfig?.optionOverrides?.[driverType] ); }