@fluidframework/test-utils 2.0.0-internal.5.3.2 → 2.0.0-internal.6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/dist/TestSummaryUtils.d.ts +2 -10
- package/dist/TestSummaryUtils.d.ts.map +1 -1
- package/dist/TestSummaryUtils.js +15 -22
- package/dist/TestSummaryUtils.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/loaderContainerTracker.js +4 -5
- package/dist/loaderContainerTracker.js.map +1 -1
- package/dist/localCodeLoader.js +5 -2
- package/dist/localCodeLoader.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/testContainerRuntimeFactory.d.ts.map +1 -1
- package/dist/testContainerRuntimeFactory.js +8 -4
- package/dist/testContainerRuntimeFactory.js.map +1 -1
- package/dist/testFluidObject.d.ts +10 -4
- package/dist/testFluidObject.d.ts.map +1 -1
- package/dist/testFluidObject.js +37 -26
- package/dist/testFluidObject.js.map +1 -1
- package/dist/testObjectProvider.d.ts +1 -2
- package/dist/testObjectProvider.d.ts.map +1 -1
- package/dist/testObjectProvider.js +32 -25
- package/dist/testObjectProvider.js.map +1 -1
- package/dist/timeoutUtils.js +3 -6
- package/dist/timeoutUtils.js.map +1 -1
- package/package.json +39 -25
- package/src/TestSummaryUtils.ts +8 -35
- package/src/index.ts +1 -6
- package/src/packageVersion.ts +1 -1
- package/src/testContainerRuntimeFactory.ts +2 -1
- package/src/testFluidObject.ts +48 -42
- package/src/testObjectProvider.ts +16 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testObjectProvider.js","sourceRoot":"","sources":["../src/testObjectProvider.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iFAM+C;AAC/C,u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zB,OAAO;KACP;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,2BAA2B,EAAE,CAAC;IACrD,IAAI,OAAO,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;QACxC,OAAO,IAAI,KAAK,CACf,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,+BAA+B,IAAI,CAAC,SAAS,CAC3D,OAAO,CAAC,gBAAgB,EACxB,SAAS,EACT,CAAC,CACD,EAAE,CACH,CAAC;KACF;IACD,IAAI,OAAO,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;QACxC,OAAO,IAAI,KAAK,CACf,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,+BAA+B,IAAI,CAAC,SAAS,CAC3D,OAAO,CAAC,gBAAgB,EACxB,SAAS,EACT,CAAC,CACD,EAAE,CACH,CAAC;KACF;AACF,CAAC;AA1BD,wEA0BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIContainer,\n\tIHostLoader,\n\tIFluidCodeDetails,\n\tLoaderHeader,\n\tILoader,\n} from \"@fluidframework/container-definitions\";\nimport {\n\tILoaderProps,\n\tLoader,\n\twaitContainerToCatchUp as waitContainerToCatchUp_original,\n} from \"@fluidframework/container-loader\";\nimport { IContainerRuntimeOptions } from \"@fluidframework/container-runtime\";\nimport {\n\tITelemetryGenericEvent,\n\tITelemetryBaseLogger,\n\tITelemetryBaseEvent,\n\tIRequestHeader,\n} from \"@fluidframework/core-interfaces\";\nimport {\n\tIDocumentServiceFactory,\n\tIResolvedUrl,\n\tIUrlResolver,\n} from \"@fluidframework/driver-definitions\";\nimport { ITestDriver, TestDriverTypes } from \"@fluidframework/test-driver-definitions\";\nimport { v4 as uuid } from \"uuid\";\nimport { ChildLogger, MultiSinkLogger, TelemetryLogger } from \"@fluidframework/telemetry-utils\";\nimport { LoaderContainerTracker } from \"./loaderContainerTracker\";\nimport { fluidEntryPoint, LocalCodeLoader } from \"./localCodeLoader\";\nimport { createAndAttachContainer } from \"./localLoader\";\nimport { ChannelFactoryRegistry } from \"./testFluidObject\";\n\nconst defaultCodeDetails: IFluidCodeDetails = {\n\tpackage: \"defaultTestPackage\",\n\tconfig: {},\n};\n\nexport interface IOpProcessingController {\n\tprocessIncoming(...containers: IContainer[]): Promise<void>;\n\tprocessOutgoing(...containers: IContainer[]): Promise<void>;\n\tpauseProcessing(...containers: IContainer[]): Promise<void>;\n\tresumeProcessing(...containers: IContainer[]): void;\n}\n\nexport interface ITestObjectProvider {\n\tcreateFluidEntryPoint: (testContainerConfig?: ITestContainerConfig) => fluidEntryPoint;\n\tcreateLoader(\n\t\tpackageEntries: Iterable<[IFluidCodeDetails, fluidEntryPoint]>,\n\t\tloaderProps?: Partial<ILoaderProps>,\n\t): IHostLoader;\n\tcreateContainer(\n\t\tentryPoint: fluidEntryPoint,\n\t\tloaderProps?: Partial<ILoaderProps>,\n\t): Promise<IContainer>;\n\tloadContainer(\n\t\tentryPoint: fluidEntryPoint,\n\t\tloaderProps?: Partial<ILoaderProps>,\n\t\trequestHeader?: IRequestHeader,\n\t): Promise<IContainer>;\n\n\t/**\n\t * Used to create a test Container. The Loader/ContainerRuntime/DataRuntime might be different versioned.\n\t * In generateLocalCompatTest(), this Container and its runtime will be arbitrarily-versioned.\n\t */\n\tmakeTestLoader(testContainerConfig?: ITestContainerConfig): IHostLoader;\n\tmakeTestContainer(testContainerConfig?: ITestContainerConfig): Promise<IContainer>;\n\tloadTestContainer(\n\t\ttestContainerConfig?: ITestContainerConfig,\n\t\trequestHeader?: IRequestHeader,\n\t): Promise<IContainer>;\n\t/**\n\t *\n\t * @param url - Resolved container URL\n\t */\n\tupdateDocumentId(url: IResolvedUrl | undefined): void;\n\n\tlogger: ITelemetryBaseLogger;\n\tdocumentServiceFactory: IDocumentServiceFactory;\n\turlResolver: IUrlResolver;\n\tdefaultCodeDetails: IFluidCodeDetails;\n\topProcessingController: IOpProcessingController;\n\n\tensureSynchronized(timeoutDuration?: number): Promise<void>;\n\treset(): void;\n\n\tdocumentId: string;\n\tdriver: ITestDriver;\n}\n\nexport enum DataObjectFactoryType {\n\tPrimed, // default\n\tTest,\n}\n\nexport interface ITestContainerConfig {\n\t/** TestFluidDataObject instead of PrimedDataStore */\n\tfluidDataObjectType?: DataObjectFactoryType;\n\n\t/** An array of channel name and DDS factory pair to create on container creation time */\n\tregistry?: ChannelFactoryRegistry;\n\n\t/** Container runtime options for the container instance */\n\truntimeOptions?: IContainerRuntimeOptions;\n\n\t/** Whether this runtime should be instantiated using a mixed-in attributor class */\n\tenableAttribution?: boolean;\n\n\t/** Loader options for the loader used to create containers */\n\tloaderProps?: Partial<ILoaderProps>;\n\n\t/** Temporary flag: simulate read connection using delay connection, default is true */\n\tsimulateReadConnectionUsingDelay?: boolean;\n}\n\nexport const createDocumentId = (): string => uuid();\n\ninterface IDocumentIdStrategy {\n\tget(): string;\n\tupdate(resolvedUrl?: IResolvedUrl): void;\n\treset(): void;\n}\n\n/**\n * Document ID is treated differently by test drivers. The key difference is in generating\n * a new container ID and accessing the container in multi-instance test cases.\n */\nfunction getDocumentIdStrategy(type?: TestDriverTypes): IDocumentIdStrategy {\n\tlet documentId = createDocumentId();\n\tswitch (type) {\n\t\tcase \"odsp\":\n\t\t\treturn {\n\t\t\t\tget: () => documentId,\n\t\t\t\tupdate: () => {}, // do not update the document ID in odsp test cases\n\t\t\t\treset: () => {\n\t\t\t\t\tdocumentId = createDocumentId();\n\t\t\t\t},\n\t\t\t};\n\t\tdefault:\n\t\t\treturn {\n\t\t\t\tget: () => documentId,\n\t\t\t\tupdate: (resolvedUrl?: IResolvedUrl) => {\n\t\t\t\t\t// Extract the document ID from the resolved container's URL and reset the ID property\n\t\t\t\t\tdocumentId = resolvedUrl?.id ?? documentId;\n\t\t\t\t},\n\t\t\t\treset: () => {\n\t\t\t\t\tdocumentId = createDocumentId();\n\t\t\t\t},\n\t\t\t};\n\t}\n}\n\n/**\n * This class tracks events. It allows specifying expected events, which will be looked for in order.\n * It also tracks all unexpected errors.\n * At any point you call reportAndClearTrackedEvents which will provide all unexpected errors, and\n * any expected events that have not occurred.\n */\nexport class EventAndErrorTrackingLogger extends TelemetryLogger {\n\t/**\n\t * Even if these error events are logged, tests should still be allowed to pass\n\t * Additionally, if downgrade is true, then log as generic (e.g. to avoid polluting the e2e test logs)\n\t */\n\tprivate readonly allowedErrors: { eventName: string; downgrade?: true }[] = [\n\t\t// This log was removed in current version as unnecessary, but it's still present in previous versions\n\t\t{\n\t\t\teventName: \"fluid:telemetry:Container:NoRealStorageInDetachedContainer\",\n\t\t\tdowngrade: true,\n\t\t},\n\t\t// This log's category changes depending on the op latency. test results shouldn't be affected but if we see lots we'd like an alert from the logs.\n\t\t{ eventName: \"fluid:telemetry:OpPerf:OpRoundtripTime\" },\n\t];\n\n\tconstructor(private readonly baseLogger: ITelemetryBaseLogger) {\n\t\tsuper();\n\t}\n\n\tprivate readonly expectedEvents: (\n\t\t| { index: number; event: ITelemetryGenericEvent | undefined }\n\t\t| undefined\n\t)[] = [];\n\tprivate readonly unexpectedErrors: ITelemetryBaseEvent[] = [];\n\n\tpublic registerExpectedEvent(...orderedExpectedEvents: ITelemetryGenericEvent[]) {\n\t\tif (this.expectedEvents.length !== 0) {\n\t\t\t// we don't have to error here. just no reason not to. given the events must be\n\t\t\t// ordered it could be tricky to figure out problems around multiple registrations.\n\t\t\tthrow new Error(\n\t\t\t\t\"Expected events already registered.\\n\" +\n\t\t\t\t\t\"Call reportAndClearTrackedEvents to clear them before registering more\",\n\t\t\t);\n\t\t}\n\t\tthis.expectedEvents.push(\n\t\t\t...orderedExpectedEvents.map((event, index) => ({ index, event })),\n\t\t);\n\t}\n\n\tsend(event: ITelemetryBaseEvent): void {\n\t\tconst ee = this.expectedEvents[0]?.event;\n\t\tif (ee?.eventName === event.eventName) {\n\t\t\tlet matches = true;\n\t\t\tfor (const key of Object.keys(ee)) {\n\t\t\t\tif (ee[key] !== event[key]) {\n\t\t\t\t\tmatches = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (matches) {\n\t\t\t\t// we found an expected event\n\t\t\t\t// so remove it from the list of expected events\n\t\t\t\t// and if it is an error, change it to generic\n\t\t\t\t// this helps keep our telemetry clear of\n\t\t\t\t// expected errors.\n\t\t\t\tthis.expectedEvents.shift();\n\t\t\t\tif (event.category === \"error\") {\n\t\t\t\t\tevent.category = \"generic\";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (event.category === \"error\") {\n\t\t\t// Check to see if this error is allowed and if its category should be downgraded\n\t\t\tconst allowedError = this.allowedErrors.find(\n\t\t\t\t({ eventName }) => eventName === event.eventName,\n\t\t\t);\n\n\t\t\tif (allowedError === undefined) {\n\t\t\t\tthis.unexpectedErrors.push(event);\n\t\t\t} else if (allowedError.downgrade) {\n\t\t\t\tevent.category = \"generic\";\n\t\t\t}\n\t\t}\n\n\t\tthis.baseLogger.send(event);\n\t}\n\n\tpublic reportAndClearTrackedEvents() {\n\t\tconst expectedNotFound = this.expectedEvents.splice(0, this.expectedEvents.length);\n\t\tconst unexpectedErrors = this.unexpectedErrors.splice(0, this.unexpectedErrors.length);\n\t\treturn {\n\t\t\texpectedNotFound,\n\t\t\tunexpectedErrors,\n\t\t};\n\t}\n}\n\n/**\n * Shared base class for test object provider. Contain code for loader and container creation and loading\n */\nexport class TestObjectProvider implements ITestObjectProvider {\n\tprivate _loaderContainerTracker = new LoaderContainerTracker();\n\tprivate _documentServiceFactory: IDocumentServiceFactory | undefined;\n\tprivate _urlResolver: IUrlResolver | undefined;\n\tprivate _logger: EventAndErrorTrackingLogger | undefined;\n\tprivate readonly _documentIdStrategy: IDocumentIdStrategy;\n\t// Since documentId doesn't change we can only create/make one container. Call the load functions instead.\n\tprivate _documentCreated = false;\n\n\t/**\n\t * Manage objects for loading and creating container, including the driver, loader, and OpProcessingController\n\t * @param createFluidEntryPoint - callback to create a fluidEntryPoint, with an optional set of channel name\n\t * and factory for TestFluidObject\n\t */\n\tconstructor(\n\t\tpublic readonly LoaderConstructor: typeof Loader,\n\t\tpublic readonly driver: ITestDriver,\n\t\tpublic readonly createFluidEntryPoint: (\n\t\t\ttestContainerConfig?: ITestContainerConfig,\n\t\t) => fluidEntryPoint,\n\t) {\n\t\tthis._documentIdStrategy = getDocumentIdStrategy(driver.type);\n\t}\n\n\tget logger(): EventAndErrorTrackingLogger {\n\t\tif (this._logger === undefined) {\n\t\t\tthis._logger = new EventAndErrorTrackingLogger(\n\t\t\t\tChildLogger.create(getTestLogger?.(), undefined, {\n\t\t\t\t\tall: {\n\t\t\t\t\t\tdriverType: this.driver.type,\n\t\t\t\t\t\tdriverEndpointName: this.driver.endpointName,\n\t\t\t\t\t\tdriverTenantName: this.driver.tenantName,\n\t\t\t\t\t\tdriverUserIndex: this.driver.userIndex,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn this._logger;\n\t}\n\n\tset logger(logger: EventAndErrorTrackingLogger) {\n\t\tthis._logger = logger;\n\t}\n\n\tget documentServiceFactory() {\n\t\tif (!this._documentServiceFactory) {\n\t\t\tthis._documentServiceFactory = this.driver.createDocumentServiceFactory();\n\t\t}\n\t\treturn this._documentServiceFactory;\n\t}\n\n\tget urlResolver() {\n\t\tif (!this._urlResolver) {\n\t\t\tthis._urlResolver = this.driver.createUrlResolver();\n\t\t}\n\t\treturn this._urlResolver;\n\t}\n\n\tget documentId() {\n\t\treturn this._documentIdStrategy.get();\n\t}\n\n\tget defaultCodeDetails() {\n\t\treturn defaultCodeDetails;\n\t}\n\n\tget opProcessingController(): IOpProcessingController {\n\t\treturn this._loaderContainerTracker;\n\t}\n\n\t/**\n\t * Create a loader. Containers created/loaded through this loader will be added to the OpProcessingController.\n\t *\n\t * Only the version of the loader will vary based on compat config. The version of\n\t * containerRuntime/dataRuntime used in fluidEntryPoint will be used as is from what is passed in.\n\t *\n\t * @param packageEntries - list of code details and fluidEntryPoint pairs.\n\t */\n\tpublic createLoader(\n\t\tpackageEntries: Iterable<[IFluidCodeDetails, fluidEntryPoint]>,\n\t\tloaderProps?: Partial<ILoaderProps>,\n\t) {\n\t\tconst multiSinkLogger = new MultiSinkLogger();\n\t\tmultiSinkLogger.addLogger(this.logger);\n\t\tif (loaderProps?.logger !== undefined) {\n\t\t\tmultiSinkLogger.addLogger(loaderProps.logger);\n\t\t}\n\n\t\tconst loader = new this.LoaderConstructor({\n\t\t\t...loaderProps,\n\t\t\tlogger: multiSinkLogger,\n\t\t\tcodeLoader: loaderProps?.codeLoader ?? new LocalCodeLoader(packageEntries),\n\t\t\turlResolver: loaderProps?.urlResolver ?? this.urlResolver,\n\t\t\tdocumentServiceFactory:\n\t\t\t\tloaderProps?.documentServiceFactory ?? this.documentServiceFactory,\n\t\t});\n\t\tthis._loaderContainerTracker.add(loader);\n\t\treturn loader;\n\t}\n\n\t/**\n\t * Create a container using a default document id and code details.\n\t * Container created is automatically added to the OpProcessingController to manage op flow\n\t *\n\t * Only the version of the loader will vary based on compat config. The version of\n\t * containerRuntime/dataRuntime used in fluidEntryPoint will be used as is from what is passed in.\n\t *\n\t * @param packageEntries - list of code details and fluidEntryPoint pairs.\n\t */\n\tpublic async createContainer(entryPoint: fluidEntryPoint, loaderProps?: Partial<ILoaderProps>) {\n\t\tif (this._documentCreated) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Only one container/document can be created. To load the container/document use loadContainer\",\n\t\t\t);\n\t\t}\n\t\tconst loader = this.createLoader([[defaultCodeDetails, entryPoint]], loaderProps);\n\t\tconst container = await createAndAttachContainer(\n\t\t\tdefaultCodeDetails,\n\t\t\tloader,\n\t\t\tthis.driver.createCreateNewRequest(this.documentId),\n\t\t);\n\t\tthis._documentCreated = true;\n\t\t// r11s driver will generate a new ID for the new container.\n\t\t// update the document ID with the actual ID of the attached container.\n\t\tthis._documentIdStrategy.update(container.resolvedUrl);\n\t\treturn container;\n\t}\n\n\tpublic async loadContainer(\n\t\tentryPoint: fluidEntryPoint,\n\t\tloaderProps?: Partial<ILoaderProps>,\n\t\trequestHeader?: IRequestHeader,\n\t): Promise<IContainer> {\n\t\tconst loader = this.createLoader([[defaultCodeDetails, entryPoint]], loaderProps);\n\t\treturn this.resolveContainer(loader, requestHeader);\n\t}\n\n\tprivate async resolveContainer(\n\t\tloader: ILoader,\n\t\trequestHeader?: IRequestHeader,\n\t\tdelay: boolean = true,\n\t) {\n\t\t// Once AB#3889 is done to switch default connection mode to \"read\" on load, we don't need\n\t\t// to load \"delayed\" across the board. Remove the following code.\n\t\tconst delayConnection =\n\t\t\tdelay &&\n\t\t\t(requestHeader === undefined || requestHeader[LoaderHeader.reconnect] !== false);\n\t\tconst headers: IRequestHeader | undefined = delayConnection\n\t\t\t? {\n\t\t\t\t\t[LoaderHeader.loadMode]: { deltaConnection: \"delayed\" },\n\t\t\t\t\t...requestHeader,\n\t\t\t }\n\t\t\t: requestHeader;\n\n\t\tconst container = await loader.resolve({\n\t\t\turl: await this.driver.createContainerUrl(this.documentId),\n\t\t\theaders,\n\t\t});\n\n\t\t// Once AB#3889 is done to switch default connection mode to \"read\" on load, we don't need\n\t\t// to load \"delayed\" across the board. Remove the following code.\n\t\tif (delayConnection) {\n\t\t\t// Older version may not have connect/disconnect. It was add in PR#9439, and available >= 0.59.1000\n\t\t\tconst maybeContainer = container as Partial<IContainer>;\n\t\t\tif (maybeContainer.connect !== undefined) {\n\t\t\t\tcontainer.connect();\n\t\t\t} else {\n\t\t\t\t// back compat. Remove when we don't support < 0.59.1000\n\t\t\t\t(container as any).resume();\n\t\t\t}\n\t\t}\n\t\treturn container;\n\t}\n\n\t/**\n\t * Make a test loader. Containers created/loaded through this loader will be added to the OpProcessingController.\n\t * The version of the loader/containerRuntime/dataRuntime may vary based on compat config of the current run\n\t * @param testContainerConfig - optional configuring the test Container\n\t */\n\tpublic makeTestLoader(testContainerConfig?: ITestContainerConfig) {\n\t\treturn this.createLoader(\n\t\t\t[[defaultCodeDetails, this.createFluidEntryPoint(testContainerConfig)]],\n\t\t\ttestContainerConfig?.loaderProps,\n\t\t);\n\t}\n\n\t/**\n\t * Make a container using a default document id and code details\n\t * Container loaded is automatically added to the OpProcessingController to manage op flow\n\t * @param testContainerConfig - optional configuring the test Container\n\t */\n\tpublic async makeTestContainer(\n\t\ttestContainerConfig?: ITestContainerConfig,\n\t): Promise<IContainer> {\n\t\tif (this._documentCreated) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Only one container/document can be created. To load the container/document use loadTestContainer\",\n\t\t\t);\n\t\t}\n\t\tconst loader = this.makeTestLoader(testContainerConfig);\n\t\tconst container = await createAndAttachContainer(\n\t\t\tdefaultCodeDetails,\n\t\t\tloader,\n\t\t\tthis.driver.createCreateNewRequest(this.documentId),\n\t\t);\n\t\tthis._documentCreated = true;\n\t\t// r11s driver will generate a new ID for the new container.\n\t\t// update the document ID with the actual ID of the attached container.\n\t\tthis._documentIdStrategy.update(container.resolvedUrl);\n\t\treturn container;\n\t}\n\n\t/**\n\t * Load a container using a default document id and code details.\n\t * IContainer loaded is automatically added to the OpProcessingController to manage op flow\n\t * @param testContainerConfig - optional configuring the test Container\n\t * @param requestHeader - optional headers to be supplied to the loader\n\t */\n\tpublic async loadTestContainer(\n\t\ttestContainerConfig?: ITestContainerConfig,\n\t\trequestHeader?: IRequestHeader,\n\t): Promise<IContainer> {\n\t\tconst loader = this.makeTestLoader(testContainerConfig);\n\n\t\tconst container = await this.resolveContainer(\n\t\t\tloader,\n\t\t\trequestHeader,\n\t\t\ttestContainerConfig?.simulateReadConnectionUsingDelay,\n\t\t);\n\t\tawait this.waitContainerToCatchUp(container);\n\n\t\treturn container;\n\t}\n\n\tpublic reset() {\n\t\tthis._loaderContainerTracker.reset();\n\t\tthis._documentServiceFactory = undefined;\n\t\tthis._urlResolver = undefined;\n\t\tthis._documentIdStrategy.reset();\n\t\tconst logError = getUnexpectedLogErrorException(this._logger);\n\t\tif (logError) {\n\t\t\tthrow logError;\n\t\t}\n\t\tthis._logger = undefined;\n\t\tthis._documentCreated = false;\n\t}\n\n\tpublic async ensureSynchronized(): Promise<void> {\n\t\treturn this._loaderContainerTracker.ensureSynchronized();\n\t}\n\n\tpublic async waitContainerToCatchUp(container: IContainer) {\n\t\t// The original waitContainerToCatchUp() from container loader uses either Container.resume()\n\t\t// or Container.connect() as part of its implementation. However, resume() was deprecated\n\t\t// and eventually replaced with connect(). To avoid issues during LTS compatibility testing\n\t\t// with older container versions issues, we use resume() when connect() is unavailable.\n\t\tif ((container as any).connect === undefined) {\n\t\t\t(container as any).connect = (container as any).resume;\n\t\t}\n\n\t\treturn waitContainerToCatchUp_original(container);\n\t}\n\n\tupdateDocumentId(resolvedUrl: IResolvedUrl | undefined) {\n\t\tthis._documentIdStrategy.update(resolvedUrl);\n\t}\n\n\tpublic resetLoaderContainerTracker(syncSummarizerClients: boolean = false) {\n\t\tthis._loaderContainerTracker.reset();\n\t\tthis._loaderContainerTracker = new LoaderContainerTracker(syncSummarizerClients);\n\t}\n}\n\nexport function getUnexpectedLogErrorException(\n\tlogger: EventAndErrorTrackingLogger | undefined,\n\tprefix?: string,\n) {\n\tif (logger === undefined) {\n\t\treturn;\n\t}\n\tconst results = logger.reportAndClearTrackedEvents();\n\tif (results.unexpectedErrors.length > 0) {\n\t\treturn new Error(\n\t\t\t`${prefix ?? \"\"}Unexpected Errors in Logs:\\n${JSON.stringify(\n\t\t\t\tresults.unexpectedErrors,\n\t\t\t\tundefined,\n\t\t\t\t2,\n\t\t\t)}`,\n\t\t);\n\t}\n\tif (results.expectedNotFound.length > 0) {\n\t\treturn new Error(\n\t\t\t`${prefix ?? \"\"}Expected Events not found:\\n${JSON.stringify(\n\t\t\t\tresults.expectedNotFound,\n\t\t\t\tundefined,\n\t\t\t\t2,\n\t\t\t)}`,\n\t\t);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"testObjectProvider.js","sourceRoot":"","sources":["../src/testObjectProvider.ts"],"names":[],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MAAM,GAAG,CAAC,EAAE;QACxC,OAAO,IAAI,KAAK,CACf,GAAG,MAAM,IAAI,EAAE,+BAA+B,IAAI,CAAC,SAAS,CAC3D,OAAO,CAAC,gBAAgB,EACxB,SAAS,EACT,CAAC,CACD,EAAE,CACH,CAAC;KACF;AACF,CAAC;AA1BD,wEA0BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIContainer,\n\tIHostLoader,\n\tIFluidCodeDetails,\n\tLoaderHeader,\n\tILoader,\n} from \"@fluidframework/container-definitions\";\nimport {\n\tILoaderProps,\n\tLoader,\n\twaitContainerToCatchUp as waitContainerToCatchUp_original,\n} from \"@fluidframework/container-loader\";\nimport { IContainerRuntimeOptions } from \"@fluidframework/container-runtime\";\nimport {\n\tITelemetryGenericEvent,\n\tITelemetryBaseLogger,\n\tITelemetryBaseEvent,\n\tIRequestHeader,\n} from \"@fluidframework/core-interfaces\";\nimport {\n\tIDocumentServiceFactory,\n\tIResolvedUrl,\n\tIUrlResolver,\n} from \"@fluidframework/driver-definitions\";\nimport { ITestDriver, TestDriverTypes } from \"@fluidframework/test-driver-definitions\";\nimport { v4 as uuid } from \"uuid\";\nimport { createChildLogger, createMultiSinkLogger } from \"@fluidframework/telemetry-utils\";\nimport { LoaderContainerTracker } from \"./loaderContainerTracker\";\nimport { fluidEntryPoint, LocalCodeLoader } from \"./localCodeLoader\";\nimport { createAndAttachContainer } from \"./localLoader\";\nimport { ChannelFactoryRegistry } from \"./testFluidObject\";\n\nconst defaultCodeDetails: IFluidCodeDetails = {\n\tpackage: \"defaultTestPackage\",\n\tconfig: {},\n};\n\nexport interface IOpProcessingController {\n\tprocessIncoming(...containers: IContainer[]): Promise<void>;\n\tprocessOutgoing(...containers: IContainer[]): Promise<void>;\n\tpauseProcessing(...containers: IContainer[]): Promise<void>;\n\tresumeProcessing(...containers: IContainer[]): void;\n}\n\nexport interface ITestObjectProvider {\n\tcreateFluidEntryPoint: (testContainerConfig?: ITestContainerConfig) => fluidEntryPoint;\n\tcreateLoader(\n\t\tpackageEntries: Iterable<[IFluidCodeDetails, fluidEntryPoint]>,\n\t\tloaderProps?: Partial<ILoaderProps>,\n\t): IHostLoader;\n\tcreateContainer(\n\t\tentryPoint: fluidEntryPoint,\n\t\tloaderProps?: Partial<ILoaderProps>,\n\t): Promise<IContainer>;\n\tloadContainer(\n\t\tentryPoint: fluidEntryPoint,\n\t\tloaderProps?: Partial<ILoaderProps>,\n\t\trequestHeader?: IRequestHeader,\n\t): Promise<IContainer>;\n\n\t/**\n\t * Used to create a test Container. The Loader/ContainerRuntime/DataRuntime might be different versioned.\n\t * In generateLocalCompatTest(), this Container and its runtime will be arbitrarily-versioned.\n\t */\n\tmakeTestLoader(testContainerConfig?: ITestContainerConfig): IHostLoader;\n\tmakeTestContainer(testContainerConfig?: ITestContainerConfig): Promise<IContainer>;\n\tloadTestContainer(\n\t\ttestContainerConfig?: ITestContainerConfig,\n\t\trequestHeader?: IRequestHeader,\n\t): Promise<IContainer>;\n\t/**\n\t *\n\t * @param url - Resolved container URL\n\t */\n\tupdateDocumentId(url: IResolvedUrl | undefined): void;\n\n\tlogger: ITelemetryBaseLogger;\n\tdocumentServiceFactory: IDocumentServiceFactory;\n\turlResolver: IUrlResolver;\n\tdefaultCodeDetails: IFluidCodeDetails;\n\topProcessingController: IOpProcessingController;\n\n\tensureSynchronized(timeoutDuration?: number): Promise<void>;\n\treset(): void;\n\n\tdocumentId: string;\n\tdriver: ITestDriver;\n}\n\nexport enum DataObjectFactoryType {\n\tPrimed, // default\n\tTest,\n}\n\nexport interface ITestContainerConfig {\n\t/** TestFluidDataObject instead of PrimedDataStore */\n\tfluidDataObjectType?: DataObjectFactoryType;\n\n\t/** An array of channel name and DDS factory pair to create on container creation time */\n\tregistry?: ChannelFactoryRegistry;\n\n\t/** Container runtime options for the container instance */\n\truntimeOptions?: IContainerRuntimeOptions;\n\n\t/** Whether this runtime should be instantiated using a mixed-in attributor class */\n\tenableAttribution?: boolean;\n\n\t/** Loader options for the loader used to create containers */\n\tloaderProps?: Partial<ILoaderProps>;\n\n\t/** Temporary flag: simulate read connection using delay connection, default is true */\n\tsimulateReadConnectionUsingDelay?: boolean;\n}\n\nexport const createDocumentId = (): string => uuid();\n\ninterface IDocumentIdStrategy {\n\tget(): string;\n\tupdate(resolvedUrl?: IResolvedUrl): void;\n\treset(): void;\n}\n\n/**\n * Document ID is treated differently by test drivers. The key difference is in generating\n * a new container ID and accessing the container in multi-instance test cases.\n */\nfunction getDocumentIdStrategy(type?: TestDriverTypes): IDocumentIdStrategy {\n\tlet documentId = createDocumentId();\n\tswitch (type) {\n\t\tcase \"odsp\":\n\t\t\treturn {\n\t\t\t\tget: () => documentId,\n\t\t\t\tupdate: () => {}, // do not update the document ID in odsp test cases\n\t\t\t\treset: () => {\n\t\t\t\t\tdocumentId = createDocumentId();\n\t\t\t\t},\n\t\t\t};\n\t\tdefault:\n\t\t\treturn {\n\t\t\t\tget: () => documentId,\n\t\t\t\tupdate: (resolvedUrl?: IResolvedUrl) => {\n\t\t\t\t\t// Extract the document ID from the resolved container's URL and reset the ID property\n\t\t\t\t\tdocumentId = resolvedUrl?.id ?? documentId;\n\t\t\t\t},\n\t\t\t\treset: () => {\n\t\t\t\t\tdocumentId = createDocumentId();\n\t\t\t\t},\n\t\t\t};\n\t}\n}\n\n/**\n * This class tracks events. It allows specifying expected events, which will be looked for in order.\n * It also tracks all unexpected errors.\n * At any point you call reportAndClearTrackedEvents which will provide all unexpected errors, and\n * any expected events that have not occurred.\n */\nexport class EventAndErrorTrackingLogger implements ITelemetryBaseLogger {\n\t/**\n\t * Even if these error events are logged, tests should still be allowed to pass\n\t * Additionally, if downgrade is true, then log as generic (e.g. to avoid polluting the e2e test logs)\n\t */\n\tprivate readonly allowedErrors: { eventName: string; downgrade?: true }[] = [\n\t\t// This log was removed in current version as unnecessary, but it's still present in previous versions\n\t\t{\n\t\t\teventName: \"fluid:telemetry:Container:NoRealStorageInDetachedContainer\",\n\t\t\tdowngrade: true,\n\t\t},\n\t\t// This log's category changes depending on the op latency. test results shouldn't be affected but if we see lots we'd like an alert from the logs.\n\t\t{ eventName: \"fluid:telemetry:OpPerf:OpRoundtripTime\" },\n\t];\n\n\tconstructor(private readonly baseLogger: ITelemetryBaseLogger) {}\n\n\tprivate readonly expectedEvents: (\n\t\t| { index: number; event: ITelemetryGenericEvent | undefined }\n\t\t| undefined\n\t)[] = [];\n\tprivate readonly unexpectedErrors: ITelemetryBaseEvent[] = [];\n\n\tpublic registerExpectedEvent(...orderedExpectedEvents: ITelemetryGenericEvent[]) {\n\t\tif (this.expectedEvents.length !== 0) {\n\t\t\t// we don't have to error here. just no reason not to. given the events must be\n\t\t\t// ordered it could be tricky to figure out problems around multiple registrations.\n\t\t\tthrow new Error(\n\t\t\t\t\"Expected events already registered.\\n\" +\n\t\t\t\t\t\"Call reportAndClearTrackedEvents to clear them before registering more\",\n\t\t\t);\n\t\t}\n\t\tthis.expectedEvents.push(\n\t\t\t...orderedExpectedEvents.map((event, index) => ({ index, event })),\n\t\t);\n\t}\n\n\tsend(event: ITelemetryBaseEvent): void {\n\t\tconst ee = this.expectedEvents[0]?.event;\n\t\tif (ee?.eventName === event.eventName) {\n\t\t\tlet matches = true;\n\t\t\tfor (const key of Object.keys(ee)) {\n\t\t\t\tif (ee[key] !== event[key]) {\n\t\t\t\t\tmatches = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (matches) {\n\t\t\t\t// we found an expected event\n\t\t\t\t// so remove it from the list of expected events\n\t\t\t\t// and if it is an error, change it to generic\n\t\t\t\t// this helps keep our telemetry clear of\n\t\t\t\t// expected errors.\n\t\t\t\tthis.expectedEvents.shift();\n\t\t\t\tif (event.category === \"error\") {\n\t\t\t\t\tevent.category = \"generic\";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (event.category === \"error\") {\n\t\t\t// Check to see if this error is allowed and if its category should be downgraded\n\t\t\tconst allowedError = this.allowedErrors.find(\n\t\t\t\t({ eventName }) => eventName === event.eventName,\n\t\t\t);\n\n\t\t\tif (allowedError === undefined) {\n\t\t\t\tthis.unexpectedErrors.push(event);\n\t\t\t} else if (allowedError.downgrade) {\n\t\t\t\tevent.category = \"generic\";\n\t\t\t}\n\t\t}\n\n\t\tthis.baseLogger.send(event);\n\t}\n\n\tpublic reportAndClearTrackedEvents() {\n\t\tconst expectedNotFound = this.expectedEvents.splice(0, this.expectedEvents.length);\n\t\tconst unexpectedErrors = this.unexpectedErrors.splice(0, this.unexpectedErrors.length);\n\t\treturn {\n\t\t\texpectedNotFound,\n\t\t\tunexpectedErrors,\n\t\t};\n\t}\n}\n\n/**\n * Shared base class for test object provider. Contain code for loader and container creation and loading\n */\nexport class TestObjectProvider implements ITestObjectProvider {\n\tprivate _loaderContainerTracker = new LoaderContainerTracker();\n\tprivate _documentServiceFactory: IDocumentServiceFactory | undefined;\n\tprivate _urlResolver: IUrlResolver | undefined;\n\tprivate _logger: EventAndErrorTrackingLogger | undefined;\n\tprivate readonly _documentIdStrategy: IDocumentIdStrategy;\n\t// Since documentId doesn't change we can only create/make one container. Call the load functions instead.\n\tprivate _documentCreated = false;\n\n\t/**\n\t * Manage objects for loading and creating container, including the driver, loader, and OpProcessingController\n\t * @param createFluidEntryPoint - callback to create a fluidEntryPoint, with an optional set of channel name\n\t * and factory for TestFluidObject\n\t */\n\tconstructor(\n\t\tpublic readonly LoaderConstructor: typeof Loader,\n\t\tpublic readonly driver: ITestDriver,\n\t\tpublic readonly createFluidEntryPoint: (\n\t\t\ttestContainerConfig?: ITestContainerConfig,\n\t\t) => fluidEntryPoint,\n\t) {\n\t\tthis._documentIdStrategy = getDocumentIdStrategy(driver.type);\n\t}\n\n\tget logger(): EventAndErrorTrackingLogger {\n\t\tif (this._logger === undefined) {\n\t\t\tthis._logger = new EventAndErrorTrackingLogger(\n\t\t\t\tcreateChildLogger({\n\t\t\t\t\tlogger: getTestLogger?.(),\n\t\t\t\t\tproperties: {\n\t\t\t\t\t\tall: {\n\t\t\t\t\t\t\tdriverType: this.driver.type,\n\t\t\t\t\t\t\tdriverEndpointName: this.driver.endpointName,\n\t\t\t\t\t\t\tdriverTenantName: this.driver.tenantName,\n\t\t\t\t\t\t\tdriverUserIndex: this.driver.userIndex,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn this._logger;\n\t}\n\n\tset logger(logger: EventAndErrorTrackingLogger) {\n\t\tthis._logger = logger;\n\t}\n\n\tget documentServiceFactory() {\n\t\tif (!this._documentServiceFactory) {\n\t\t\tthis._documentServiceFactory = this.driver.createDocumentServiceFactory();\n\t\t}\n\t\treturn this._documentServiceFactory;\n\t}\n\n\tget urlResolver() {\n\t\tif (!this._urlResolver) {\n\t\t\tthis._urlResolver = this.driver.createUrlResolver();\n\t\t}\n\t\treturn this._urlResolver;\n\t}\n\n\tget documentId() {\n\t\treturn this._documentIdStrategy.get();\n\t}\n\n\tget defaultCodeDetails() {\n\t\treturn defaultCodeDetails;\n\t}\n\n\tget opProcessingController(): IOpProcessingController {\n\t\treturn this._loaderContainerTracker;\n\t}\n\n\t/**\n\t * Create a loader. Containers created/loaded through this loader will be added to the OpProcessingController.\n\t *\n\t * Only the version of the loader will vary based on compat config. The version of\n\t * containerRuntime/dataRuntime used in fluidEntryPoint will be used as is from what is passed in.\n\t *\n\t * @param packageEntries - list of code details and fluidEntryPoint pairs.\n\t */\n\tpublic createLoader(\n\t\tpackageEntries: Iterable<[IFluidCodeDetails, fluidEntryPoint]>,\n\t\tloaderProps?: Partial<ILoaderProps>,\n\t) {\n\t\tconst logger = createMultiSinkLogger({\n\t\t\tloggers: [this.logger, loaderProps?.logger],\n\t\t});\n\n\t\tconst loader = new this.LoaderConstructor({\n\t\t\t...loaderProps,\n\t\t\tlogger,\n\t\t\tcodeLoader: loaderProps?.codeLoader ?? new LocalCodeLoader(packageEntries),\n\t\t\turlResolver: loaderProps?.urlResolver ?? this.urlResolver,\n\t\t\tdocumentServiceFactory:\n\t\t\t\tloaderProps?.documentServiceFactory ?? this.documentServiceFactory,\n\t\t});\n\t\tthis._loaderContainerTracker.add(loader);\n\t\treturn loader;\n\t}\n\n\t/**\n\t * Create a container using a default document id and code details.\n\t * Container created is automatically added to the OpProcessingController to manage op flow\n\t *\n\t * Only the version of the loader will vary based on compat config. The version of\n\t * containerRuntime/dataRuntime used in fluidEntryPoint will be used as is from what is passed in.\n\t *\n\t * @param packageEntries - list of code details and fluidEntryPoint pairs.\n\t */\n\tpublic async createContainer(entryPoint: fluidEntryPoint, loaderProps?: Partial<ILoaderProps>) {\n\t\tif (this._documentCreated) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Only one container/document can be created. To load the container/document use loadContainer\",\n\t\t\t);\n\t\t}\n\t\tconst loader = this.createLoader([[defaultCodeDetails, entryPoint]], loaderProps);\n\t\tconst container = await createAndAttachContainer(\n\t\t\tdefaultCodeDetails,\n\t\t\tloader,\n\t\t\tthis.driver.createCreateNewRequest(this.documentId),\n\t\t);\n\t\tthis._documentCreated = true;\n\t\t// r11s driver will generate a new ID for the new container.\n\t\t// update the document ID with the actual ID of the attached container.\n\t\tthis._documentIdStrategy.update(container.resolvedUrl);\n\t\treturn container;\n\t}\n\n\tpublic async loadContainer(\n\t\tentryPoint: fluidEntryPoint,\n\t\tloaderProps?: Partial<ILoaderProps>,\n\t\trequestHeader?: IRequestHeader,\n\t): Promise<IContainer> {\n\t\tconst loader = this.createLoader([[defaultCodeDetails, entryPoint]], loaderProps);\n\t\treturn this.resolveContainer(loader, requestHeader);\n\t}\n\n\tprivate async resolveContainer(\n\t\tloader: ILoader,\n\t\trequestHeader?: IRequestHeader,\n\t\tdelay: boolean = true,\n\t) {\n\t\t// Once AB#3889 is done to switch default connection mode to \"read\" on load, we don't need\n\t\t// to load \"delayed\" across the board. Remove the following code.\n\t\tconst delayConnection =\n\t\t\tdelay &&\n\t\t\t(requestHeader === undefined || requestHeader[LoaderHeader.reconnect] !== false);\n\t\tconst headers: IRequestHeader | undefined = delayConnection\n\t\t\t? {\n\t\t\t\t\t[LoaderHeader.loadMode]: { deltaConnection: \"delayed\" },\n\t\t\t\t\t...requestHeader,\n\t\t\t }\n\t\t\t: requestHeader;\n\n\t\tconst container = await loader.resolve({\n\t\t\turl: await this.driver.createContainerUrl(this.documentId),\n\t\t\theaders,\n\t\t});\n\n\t\t// Once AB#3889 is done to switch default connection mode to \"read\" on load, we don't need\n\t\t// to load \"delayed\" across the board. Remove the following code.\n\t\tif (delayConnection) {\n\t\t\t// Older version may not have connect/disconnect. It was add in PR#9439, and available >= 0.59.1000\n\t\t\tconst maybeContainer = container as Partial<IContainer>;\n\t\t\tif (maybeContainer.connect !== undefined) {\n\t\t\t\tcontainer.connect();\n\t\t\t} else {\n\t\t\t\t// back compat. Remove when we don't support < 0.59.1000\n\t\t\t\t(container as any).resume();\n\t\t\t}\n\t\t}\n\t\treturn container;\n\t}\n\n\t/**\n\t * Make a test loader. Containers created/loaded through this loader will be added to the OpProcessingController.\n\t * The version of the loader/containerRuntime/dataRuntime may vary based on compat config of the current run\n\t * @param testContainerConfig - optional configuring the test Container\n\t */\n\tpublic makeTestLoader(testContainerConfig?: ITestContainerConfig) {\n\t\treturn this.createLoader(\n\t\t\t[[defaultCodeDetails, this.createFluidEntryPoint(testContainerConfig)]],\n\t\t\ttestContainerConfig?.loaderProps,\n\t\t);\n\t}\n\n\t/**\n\t * Make a container using a default document id and code details\n\t * Container loaded is automatically added to the OpProcessingController to manage op flow\n\t * @param testContainerConfig - optional configuring the test Container\n\t */\n\tpublic async makeTestContainer(\n\t\ttestContainerConfig?: ITestContainerConfig,\n\t): Promise<IContainer> {\n\t\tif (this._documentCreated) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Only one container/document can be created. To load the container/document use loadTestContainer\",\n\t\t\t);\n\t\t}\n\t\tconst loader = this.makeTestLoader(testContainerConfig);\n\t\tconst container = await createAndAttachContainer(\n\t\t\tdefaultCodeDetails,\n\t\t\tloader,\n\t\t\tthis.driver.createCreateNewRequest(this.documentId),\n\t\t);\n\t\tthis._documentCreated = true;\n\t\t// r11s driver will generate a new ID for the new container.\n\t\t// update the document ID with the actual ID of the attached container.\n\t\tthis._documentIdStrategy.update(container.resolvedUrl);\n\t\treturn container;\n\t}\n\n\t/**\n\t * Load a container using a default document id and code details.\n\t * IContainer loaded is automatically added to the OpProcessingController to manage op flow\n\t * @param testContainerConfig - optional configuring the test Container\n\t * @param requestHeader - optional headers to be supplied to the loader\n\t */\n\tpublic async loadTestContainer(\n\t\ttestContainerConfig?: ITestContainerConfig,\n\t\trequestHeader?: IRequestHeader,\n\t): Promise<IContainer> {\n\t\tconst loader = this.makeTestLoader(testContainerConfig);\n\n\t\tconst container = await this.resolveContainer(\n\t\t\tloader,\n\t\t\trequestHeader,\n\t\t\ttestContainerConfig?.simulateReadConnectionUsingDelay,\n\t\t);\n\t\tawait this.waitContainerToCatchUp(container);\n\n\t\treturn container;\n\t}\n\n\tpublic reset() {\n\t\tthis._loaderContainerTracker.reset();\n\t\tthis._documentServiceFactory = undefined;\n\t\tthis._urlResolver = undefined;\n\t\tthis._documentIdStrategy.reset();\n\t\tconst logError = getUnexpectedLogErrorException(this._logger);\n\t\tif (logError) {\n\t\t\tthrow logError;\n\t\t}\n\t\tthis._logger = undefined;\n\t\tthis._documentCreated = false;\n\t}\n\n\tpublic async ensureSynchronized(): Promise<void> {\n\t\treturn this._loaderContainerTracker.ensureSynchronized();\n\t}\n\n\tpublic async waitContainerToCatchUp(container: IContainer) {\n\t\t// The original waitContainerToCatchUp() from container loader uses either Container.resume()\n\t\t// or Container.connect() as part of its implementation. However, resume() was deprecated\n\t\t// and eventually replaced with connect(). To avoid issues during LTS compatibility testing\n\t\t// with older container versions issues, we use resume() when connect() is unavailable.\n\t\tif ((container as any).connect === undefined) {\n\t\t\t(container as any).connect = (container as any).resume;\n\t\t}\n\n\t\treturn waitContainerToCatchUp_original(container);\n\t}\n\n\tupdateDocumentId(resolvedUrl: IResolvedUrl | undefined) {\n\t\tthis._documentIdStrategy.update(resolvedUrl);\n\t}\n\n\tpublic resetLoaderContainerTracker(syncSummarizerClients: boolean = false) {\n\t\tthis._loaderContainerTracker.reset();\n\t\tthis._loaderContainerTracker = new LoaderContainerTracker(syncSummarizerClients);\n\t}\n}\n\nexport function getUnexpectedLogErrorException(\n\tlogger: EventAndErrorTrackingLogger | undefined,\n\tprefix?: string,\n) {\n\tif (logger === undefined) {\n\t\treturn;\n\t}\n\tconst results = logger.reportAndClearTrackedEvents();\n\tif (results.unexpectedErrors.length > 0) {\n\t\treturn new Error(\n\t\t\t`${prefix ?? \"\"}Unexpected Errors in Logs:\\n${JSON.stringify(\n\t\t\t\tresults.unexpectedErrors,\n\t\t\t\tundefined,\n\t\t\t\t2,\n\t\t\t)}`,\n\t\t);\n\t}\n\tif (results.expectedNotFound.length > 0) {\n\t\treturn new Error(\n\t\t\t`${prefix ?? \"\"}Expected Events not found:\\n${JSON.stringify(\n\t\t\t\tresults.expectedNotFound,\n\t\t\t\tundefined,\n\t\t\t\t2,\n\t\t\t)}`,\n\t\t);\n\t}\n}\n"]}
|
package/dist/timeoutUtils.js
CHANGED
|
@@ -111,25 +111,23 @@ exports.timeoutAwait = timeoutAwait;
|
|
|
111
111
|
* @returns A new promise that will complete when the given executor resolves or the timeout expires.
|
|
112
112
|
*/
|
|
113
113
|
async function timeoutPromise(executor, timeoutOptions = {}) {
|
|
114
|
-
var _a;
|
|
115
114
|
// create the timeout error outside the async task, so its callstack includes
|
|
116
115
|
// the original call site, this makes it easier to debug
|
|
117
116
|
const err = timeoutOptions.reject === false
|
|
118
117
|
? undefined
|
|
119
|
-
: new Error(
|
|
118
|
+
: new Error(timeoutOptions.errorMsg ?? "Timed out");
|
|
120
119
|
const executorPromise = getTimeoutPromise(executor, timeoutOptions, err);
|
|
121
120
|
const currentTestTimeout = TestTimeout.getInstance();
|
|
122
121
|
if (currentTestTimeout === undefined) {
|
|
123
122
|
return executorPromise;
|
|
124
123
|
}
|
|
125
124
|
return Promise.race([executorPromise, currentTestTimeout.getPromise()]).catch((e) => {
|
|
126
|
-
var _a;
|
|
127
125
|
if (e === currentTestTimeout) {
|
|
128
126
|
if (timeoutOptions.reject !== false) {
|
|
129
127
|
// If the rejection is because of the timeout then
|
|
130
128
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
131
129
|
const errorObject = err;
|
|
132
|
-
errorObject.message = `${
|
|
130
|
+
errorObject.message = `${timeoutOptions.errorMsg ?? "Test timed out"} (${currentTestTimeout.getTimeout()}ms)`;
|
|
133
131
|
throw errorObject;
|
|
134
132
|
}
|
|
135
133
|
return timeoutOptions.value;
|
|
@@ -140,8 +138,7 @@ async function timeoutPromise(executor, timeoutOptions = {}) {
|
|
|
140
138
|
exports.timeoutPromise = timeoutPromise;
|
|
141
139
|
// Create a promise based on the timeout options
|
|
142
140
|
async function getTimeoutPromise(executor, timeoutOptions, err) {
|
|
143
|
-
|
|
144
|
-
const timeout = (_a = timeoutOptions.durationMs) !== null && _a !== void 0 ? _a : 0;
|
|
141
|
+
const timeout = timeoutOptions.durationMs ?? 0;
|
|
145
142
|
if (timeout <= 0 || !Number.isFinite(timeout)) {
|
|
146
143
|
return new Promise(executor);
|
|
147
144
|
}
|
package/dist/timeoutUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeoutUtils.js","sourceRoot":"","sources":["../src/timeoutUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAgE;AAEhE,2CAA2C;AAC9B,QAAA,wBAAwB,GAAG,GAAG,CAAC;AAE5C,MAAM,UAAU,GAAG,EAAE,CAAC,CAAC,2CAA2C;AAElE,yGAAyG;AACzG,uHAAuH;AACvH,sGAAsG;AACtG,uBAAuB;AACvB,0EAA0E;AAC1E,MAAM,WAAW;IAgChB;QA/BQ,YAAO,GAAW,CAAC,CAAC;QAGpB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ACtD,GAAsB;;IAEtB,MAAM,OAAO,GAAG,MAAA,cAAc,CAAC,UAAU,mCAAI,CAAC,CAAC;IAC/C,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QAC9C,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;KAC7B;IAED,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzC,MAAM,iBAAiB,GAAG,GAAG,EAAE;YAC9B,oEAAoE;YACpE,MAAM,WAAW,GAAG,GAAI,CAAC;YACzB,WAAW,CAAC,OAAO,GAAG,GAAG,WAAW,CAAC,OAAO,KAAK,OAAO,KAAK,CAAC;YAC9D,MAAM,CAAC,GAAG,CAAC,CAAC;QACb,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,UAAU,CACvB,GAAG,EAAE,CACJ,cAAc,CAAC,MAAM,KAAK,KAAK;YAC9B,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC;YAC/B,CAAC,CAAC,iBAAiB,EAAE,EACvB,OAAO,CACP,CAAC;QAEF,QAAQ,CACP,CAAC,KAAK,EAAE,EAAE;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,EACD,CAAC,MAAM,EAAE,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,MAAM,CAAC,CAAC;QAChB,CAAC,CACD,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Deferred } from \"@fluidframework/common-utils\";\n\n// @deprecated this value is no longer used\nexport const defaultTimeoutDurationMs = 250;\n\nconst timeBuffer = 15; // leave 15 ms leeway for finish processing\n\n// TestTimeout class that manages tracking of test timeout. It creates a timer when timeout is in effect,\n// and provides a promise that will be rejected some time (as defined by `timeBuffer`) before the test timeout happens.\n// This will ensure that async awaits in tests do not end up timing out the tests but resolve / reject\n// before that happens.\n// Once rejected, a new TestTimeout object will be create for the timeout.\nclass TestTimeout {\n\tprivate timeout: number = 0;\n\tprivate timer: NodeJS.Timeout | undefined;\n\tprivate readonly deferred: Deferred<void>;\n\tprivate rejected = false;\n\n\tprivate static instance: TestTimeout = new TestTimeout();\n\tpublic static reset(runnable: Mocha.Runnable) {\n\t\tTestTimeout.clear();\n\t\tTestTimeout.instance.resetTimer(runnable);\n\t}\n\n\tpublic static clear() {\n\t\tif (TestTimeout.instance.rejected) {\n\t\t\tTestTimeout.instance = new TestTimeout();\n\t\t} else {\n\t\t\tTestTimeout.instance.clearTimer();\n\t\t}\n\t}\n\n\tpublic static getInstance() {\n\t\treturn TestTimeout.instance;\n\t}\n\n\tpublic async getPromise() {\n\t\treturn this.deferred.promise;\n\t}\n\n\tpublic getTimeout() {\n\t\treturn this.timeout;\n\t}\n\n\tprivate constructor() {\n\t\tthis.deferred = new Deferred();\n\t\t// Ignore rejection for timeout promise if no one is waiting for it.\n\t\tthis.deferred.promise.catch(() => {});\n\t}\n\n\tprivate resetTimer(runnable: Mocha.Runnable) {\n\t\tassert(!this.timer, \"clearTimer should have been called before reset\");\n\t\tassert(!this.deferred.isCompleted, \"can't reset a completed TestTimeout\");\n\n\t\t// Check the test timeout setting\n\t\tconst timeout = runnable.timeout();\n\t\tif (!(Number.isFinite(timeout) && timeout > 0)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// subtract a buffer\n\t\tthis.timeout = Math.max(timeout - timeBuffer, 1);\n\n\t\t// Set up timer to reject near the test timeout.\n\t\tthis.timer = setTimeout(() => {\n\t\t\tthis.deferred.reject(this);\n\t\t\tthis.rejected = true;\n\t\t}, this.timeout);\n\t}\n\tprivate clearTimer() {\n\t\tif (this.timer) {\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = undefined;\n\t\t}\n\t}\n}\n\n// only register if we are running with mocha-test-setup loaded\nif (globalThis.getMochaModule !== undefined) {\n\t// patching resetTimeout and clearTimeout on the runnable object\n\t// so we can track when test timeout are enforced\n\tconst mochaModule = globalThis.getMochaModule() as typeof Mocha;\n\tconst runnablePrototype = mochaModule.Runnable.prototype;\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tconst oldResetTimeoutFunc = runnablePrototype.resetTimeout;\n\trunnablePrototype.resetTimeout = function (this: Mocha.Runnable) {\n\t\toldResetTimeoutFunc.call(this);\n\t\tTestTimeout.reset(this);\n\t};\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tconst oldClearTimeoutFunc = runnablePrototype.clearTimeout;\n\trunnablePrototype.clearTimeout = function (this: Mocha.Runnable) {\n\t\tTestTimeout.clear();\n\t\toldClearTimeoutFunc.call(this);\n\t};\n}\n\nexport interface TimeoutWithError {\n\t/**\n\t * Timeout duration in milliseconds, if it is great than 0 and not Infinity\n\t * If it is undefined, then it will use test timeout if we are in side the test function\n\t * Otherwise, there is no timeout\n\t */\n\tdurationMs?: number;\n\treject?: true;\n\terrorMsg?: string;\n}\nexport interface TimeoutWithValue<T = void> {\n\t/**\n\t * Timeout duration in milliseconds, if it is great than 0 and not Infinity\n\t * If it is undefined, then it will use test timeout if we are in side the test function\n\t * Otherwise, there is no timeout\n\t */\n\tdurationMs?: number;\n\treject: false;\n\tvalue: T;\n}\n\nexport type PromiseExecutor<T = void> = (\n\tresolve: (value: T | PromiseLike<T>) => void,\n\treject: (reason?: any) => void,\n) => void;\n\n/**\n * Wraps the given promise around with promise that will complete after a specific timeout if the original promise does\n * not resolve by then. By default, it uses the mocha test timeout and complete the promise just before that so that\n * tests don't time out because of unpredictable awaits.\n * The timeout can be overridden via timeoutOptions but it's recommended to use the default value.\n * @param promise - The promise to be awaited.\n * @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior\n * when the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a\n * specific value.\n * @returns A new promise that will complete when the given promise resolves or the timeout expires.\n */\nexport async function timeoutAwait<T = void>(\n\tpromise: PromiseLike<T>,\n\ttimeoutOptions: TimeoutWithError | TimeoutWithValue<T> = {},\n): Promise<T> {\n\treturn Promise.race([promise, timeoutPromise<T>(() => {}, timeoutOptions)]);\n}\n\n/**\n * Creates a promise from the given executor that will complete after a specific timeout. By default, it uses the mocha\n * test timeout and complete the promise just before that so that tests don't time out because of unpredictable awaits.\n * The timeout can be overridden via timeoutOptions but it's recommended to use the default value.\n * @param executor - The executor for the promise.\n * @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when\n * the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.\n * @returns A new promise that will complete when the given executor resolves or the timeout expires.\n */\nexport async function timeoutPromise<T = void>(\n\texecutor: (\n\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\treject: (reason?: any) => void,\n\t) => void,\n\ttimeoutOptions: TimeoutWithError | TimeoutWithValue<T> = {},\n): Promise<T> {\n\t// create the timeout error outside the async task, so its callstack includes\n\t// the original call site, this makes it easier to debug\n\tconst err =\n\t\ttimeoutOptions.reject === false\n\t\t\t? undefined\n\t\t\t: new Error(timeoutOptions.errorMsg ?? \"Timed out\");\n\tconst executorPromise = getTimeoutPromise(executor, timeoutOptions, err);\n\n\tconst currentTestTimeout = TestTimeout.getInstance();\n\tif (currentTestTimeout === undefined) {\n\t\treturn executorPromise;\n\t}\n\n\treturn Promise.race([executorPromise, currentTestTimeout.getPromise()]).catch((e) => {\n\t\tif (e === currentTestTimeout) {\n\t\t\tif (timeoutOptions.reject !== false) {\n\t\t\t\t// If the rejection is because of the timeout then\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst errorObject = err!;\n\t\t\t\terrorObject.message = `${\n\t\t\t\t\ttimeoutOptions.errorMsg ?? \"Test timed out\"\n\t\t\t\t} (${currentTestTimeout.getTimeout()}ms)`;\n\t\t\t\tthrow errorObject;\n\t\t\t}\n\t\t\treturn timeoutOptions.value;\n\t\t}\n\t\tthrow e;\n\t}) as Promise<T>;\n}\n\n// Create a promise based on the timeout options\nasync function getTimeoutPromise<T = void>(\n\texecutor: (\n\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\treject: (reason?: any) => void,\n\t) => void,\n\ttimeoutOptions: TimeoutWithError | TimeoutWithValue<T>,\n\terr: Error | undefined,\n) {\n\tconst timeout = timeoutOptions.durationMs ?? 0;\n\tif (timeout <= 0 || !Number.isFinite(timeout)) {\n\t\treturn new Promise(executor);\n\t}\n\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst timeoutRejections = () => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst errorObject = err!;\n\t\t\terrorObject.message = `${errorObject.message} (${timeout}ms)`;\n\t\t\treject(err);\n\t\t};\n\t\tconst timer = setTimeout(\n\t\t\t() =>\n\t\t\t\ttimeoutOptions.reject === false\n\t\t\t\t\t? resolve(timeoutOptions.value)\n\t\t\t\t\t: timeoutRejections(),\n\t\t\ttimeout,\n\t\t);\n\n\t\texecutor(\n\t\t\t(value) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve(value);\n\t\t\t},\n\t\t\t(reason) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\treject(reason);\n\t\t\t},\n\t\t);\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"timeoutUtils.js","sourceRoot":"","sources":["../src/timeoutUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAgE;AAEhE,2CAA2C;AAC9B,QAAA,wBAAwB,GAAG,GAAG,CAAC;AAE5C,MAAM,UAAU,GAAG,EAAE,CAAC,CAAC,2CAA2C;AAElE,yGAAyG;AACzG,uHAAuH;AACvH,sGAAsG;AACtG,uBAAuB;AACvB,0EAA0E;AAC1E,MAAM,WAAW;IAgChB;QA/BQ,YAAO,GAAW,CAAC,CAAC;QAGpB,aAAQ,GAAG,KAAK,CAAC;QA6Bx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UAAU,IAAI,CAAC,CAAC;IAC/C,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QAC9C,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;KAC7B;IAED,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzC,MAAM,iBAAiB,GAAG,GAAG,EAAE;YAC9B,oEAAoE;YACpE,MAAM,WAAW,GAAG,GAAI,CAAC;YACzB,WAAW,CAAC,OAAO,GAAG,GAAG,WAAW,CAAC,OAAO,KAAK,OAAO,KAAK,CAAC;YAC9D,MAAM,CAAC,GAAG,CAAC,CAAC;QACb,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,UAAU,CACvB,GAAG,EAAE,CACJ,cAAc,CAAC,MAAM,KAAK,KAAK;YAC9B,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC;YAC/B,CAAC,CAAC,iBAAiB,EAAE,EACvB,OAAO,CACP,CAAC;QAEF,QAAQ,CACP,CAAC,KAAK,EAAE,EAAE;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,EACD,CAAC,MAAM,EAAE,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,MAAM,CAAC,CAAC;QAChB,CAAC,CACD,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Deferred } from \"@fluidframework/common-utils\";\n\n// @deprecated this value is no longer used\nexport const defaultTimeoutDurationMs = 250;\n\nconst timeBuffer = 15; // leave 15 ms leeway for finish processing\n\n// TestTimeout class that manages tracking of test timeout. It creates a timer when timeout is in effect,\n// and provides a promise that will be rejected some time (as defined by `timeBuffer`) before the test timeout happens.\n// This will ensure that async awaits in tests do not end up timing out the tests but resolve / reject\n// before that happens.\n// Once rejected, a new TestTimeout object will be create for the timeout.\nclass TestTimeout {\n\tprivate timeout: number = 0;\n\tprivate timer: NodeJS.Timeout | undefined;\n\tprivate readonly deferred: Deferred<void>;\n\tprivate rejected = false;\n\n\tprivate static instance: TestTimeout = new TestTimeout();\n\tpublic static reset(runnable: Mocha.Runnable) {\n\t\tTestTimeout.clear();\n\t\tTestTimeout.instance.resetTimer(runnable);\n\t}\n\n\tpublic static clear() {\n\t\tif (TestTimeout.instance.rejected) {\n\t\t\tTestTimeout.instance = new TestTimeout();\n\t\t} else {\n\t\t\tTestTimeout.instance.clearTimer();\n\t\t}\n\t}\n\n\tpublic static getInstance() {\n\t\treturn TestTimeout.instance;\n\t}\n\n\tpublic async getPromise() {\n\t\treturn this.deferred.promise;\n\t}\n\n\tpublic getTimeout() {\n\t\treturn this.timeout;\n\t}\n\n\tprivate constructor() {\n\t\tthis.deferred = new Deferred();\n\t\t// Ignore rejection for timeout promise if no one is waiting for it.\n\t\tthis.deferred.promise.catch(() => {});\n\t}\n\n\tprivate resetTimer(runnable: Mocha.Runnable) {\n\t\tassert(!this.timer, \"clearTimer should have been called before reset\");\n\t\tassert(!this.deferred.isCompleted, \"can't reset a completed TestTimeout\");\n\n\t\t// Check the test timeout setting\n\t\tconst timeout = runnable.timeout();\n\t\tif (!(Number.isFinite(timeout) && timeout > 0)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// subtract a buffer\n\t\tthis.timeout = Math.max(timeout - timeBuffer, 1);\n\n\t\t// Set up timer to reject near the test timeout.\n\t\tthis.timer = setTimeout(() => {\n\t\t\tthis.deferred.reject(this);\n\t\t\tthis.rejected = true;\n\t\t}, this.timeout);\n\t}\n\tprivate clearTimer() {\n\t\tif (this.timer) {\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = undefined;\n\t\t}\n\t}\n}\n\n// only register if we are running with mocha-test-setup loaded\nif (globalThis.getMochaModule !== undefined) {\n\t// patching resetTimeout and clearTimeout on the runnable object\n\t// so we can track when test timeout are enforced\n\tconst mochaModule = globalThis.getMochaModule() as typeof Mocha;\n\tconst runnablePrototype = mochaModule.Runnable.prototype;\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tconst oldResetTimeoutFunc = runnablePrototype.resetTimeout;\n\trunnablePrototype.resetTimeout = function (this: Mocha.Runnable) {\n\t\toldResetTimeoutFunc.call(this);\n\t\tTestTimeout.reset(this);\n\t};\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tconst oldClearTimeoutFunc = runnablePrototype.clearTimeout;\n\trunnablePrototype.clearTimeout = function (this: Mocha.Runnable) {\n\t\tTestTimeout.clear();\n\t\toldClearTimeoutFunc.call(this);\n\t};\n}\n\nexport interface TimeoutWithError {\n\t/**\n\t * Timeout duration in milliseconds, if it is great than 0 and not Infinity\n\t * If it is undefined, then it will use test timeout if we are in side the test function\n\t * Otherwise, there is no timeout\n\t */\n\tdurationMs?: number;\n\treject?: true;\n\terrorMsg?: string;\n}\nexport interface TimeoutWithValue<T = void> {\n\t/**\n\t * Timeout duration in milliseconds, if it is great than 0 and not Infinity\n\t * If it is undefined, then it will use test timeout if we are in side the test function\n\t * Otherwise, there is no timeout\n\t */\n\tdurationMs?: number;\n\treject: false;\n\tvalue: T;\n}\n\nexport type PromiseExecutor<T = void> = (\n\tresolve: (value: T | PromiseLike<T>) => void,\n\treject: (reason?: any) => void,\n) => void;\n\n/**\n * Wraps the given promise around with promise that will complete after a specific timeout if the original promise does\n * not resolve by then. By default, it uses the mocha test timeout and complete the promise just before that so that\n * tests don't time out because of unpredictable awaits.\n * The timeout can be overridden via timeoutOptions but it's recommended to use the default value.\n * @param promise - The promise to be awaited.\n * @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior\n * when the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a\n * specific value.\n * @returns A new promise that will complete when the given promise resolves or the timeout expires.\n */\nexport async function timeoutAwait<T = void>(\n\tpromise: PromiseLike<T>,\n\ttimeoutOptions: TimeoutWithError | TimeoutWithValue<T> = {},\n): Promise<T> {\n\treturn Promise.race([promise, timeoutPromise<T>(() => {}, timeoutOptions)]);\n}\n\n/**\n * Creates a promise from the given executor that will complete after a specific timeout. By default, it uses the mocha\n * test timeout and complete the promise just before that so that tests don't time out because of unpredictable awaits.\n * The timeout can be overridden via timeoutOptions but it's recommended to use the default value.\n * @param executor - The executor for the promise.\n * @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when\n * the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value.\n * @returns A new promise that will complete when the given executor resolves or the timeout expires.\n */\nexport async function timeoutPromise<T = void>(\n\texecutor: (\n\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\treject: (reason?: any) => void,\n\t) => void,\n\ttimeoutOptions: TimeoutWithError | TimeoutWithValue<T> = {},\n): Promise<T> {\n\t// create the timeout error outside the async task, so its callstack includes\n\t// the original call site, this makes it easier to debug\n\tconst err =\n\t\ttimeoutOptions.reject === false\n\t\t\t? undefined\n\t\t\t: new Error(timeoutOptions.errorMsg ?? \"Timed out\");\n\tconst executorPromise = getTimeoutPromise(executor, timeoutOptions, err);\n\n\tconst currentTestTimeout = TestTimeout.getInstance();\n\tif (currentTestTimeout === undefined) {\n\t\treturn executorPromise;\n\t}\n\n\treturn Promise.race([executorPromise, currentTestTimeout.getPromise()]).catch((e) => {\n\t\tif (e === currentTestTimeout) {\n\t\t\tif (timeoutOptions.reject !== false) {\n\t\t\t\t// If the rejection is because of the timeout then\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst errorObject = err!;\n\t\t\t\terrorObject.message = `${\n\t\t\t\t\ttimeoutOptions.errorMsg ?? \"Test timed out\"\n\t\t\t\t} (${currentTestTimeout.getTimeout()}ms)`;\n\t\t\t\tthrow errorObject;\n\t\t\t}\n\t\t\treturn timeoutOptions.value;\n\t\t}\n\t\tthrow e;\n\t}) as Promise<T>;\n}\n\n// Create a promise based on the timeout options\nasync function getTimeoutPromise<T = void>(\n\texecutor: (\n\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\treject: (reason?: any) => void,\n\t) => void,\n\ttimeoutOptions: TimeoutWithError | TimeoutWithValue<T>,\n\terr: Error | undefined,\n) {\n\tconst timeout = timeoutOptions.durationMs ?? 0;\n\tif (timeout <= 0 || !Number.isFinite(timeout)) {\n\t\treturn new Promise(executor);\n\t}\n\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst timeoutRejections = () => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst errorObject = err!;\n\t\t\terrorObject.message = `${errorObject.message} (${timeout}ms)`;\n\t\t\treject(err);\n\t\t};\n\t\tconst timer = setTimeout(\n\t\t\t() =>\n\t\t\t\ttimeoutOptions.reject === false\n\t\t\t\t\t? resolve(timeoutOptions.value)\n\t\t\t\t\t: timeoutRejections(),\n\t\t\ttimeout,\n\t\t);\n\n\t\texecutor(\n\t\t\t(value) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve(value);\n\t\t\t},\n\t\t\t(reason) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\treject(reason);\n\t\t\t},\n\t\t);\n\t});\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/test-utils",
|
|
3
|
-
"version": "2.0.0-internal.
|
|
3
|
+
"version": "2.0.0-internal.6.0.0",
|
|
4
4
|
"description": "Utilities for Fluid tests",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -35,43 +35,43 @@
|
|
|
35
35
|
"temp-directory": "nyc/.nyc_output"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@fluidframework/aqueduct": ">=2.0.0-internal.
|
|
38
|
+
"@fluidframework/aqueduct": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
39
39
|
"@fluidframework/common-utils": "^1.1.1",
|
|
40
|
-
"@fluidframework/container-definitions": ">=2.0.0-internal.
|
|
41
|
-
"@fluidframework/container-loader": ">=2.0.0-internal.
|
|
42
|
-
"@fluidframework/container-runtime": ">=2.0.0-internal.
|
|
43
|
-
"@fluidframework/container-runtime-definitions": ">=2.0.0-internal.
|
|
44
|
-
"@fluidframework/core-interfaces": ">=2.0.0-internal.
|
|
45
|
-
"@fluidframework/datastore": ">=2.0.0-internal.
|
|
46
|
-
"@fluidframework/datastore-definitions": ">=2.0.0-internal.
|
|
47
|
-
"@fluidframework/driver-definitions": ">=2.0.0-internal.
|
|
48
|
-
"@fluidframework/driver-utils": ">=2.0.0-internal.
|
|
49
|
-
"@fluidframework/local-driver": ">=2.0.0-internal.
|
|
50
|
-
"@fluidframework/map": ">=2.0.0-internal.
|
|
40
|
+
"@fluidframework/container-definitions": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
41
|
+
"@fluidframework/container-loader": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
42
|
+
"@fluidframework/container-runtime": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
43
|
+
"@fluidframework/container-runtime-definitions": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
44
|
+
"@fluidframework/core-interfaces": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
45
|
+
"@fluidframework/datastore": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
46
|
+
"@fluidframework/datastore-definitions": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
47
|
+
"@fluidframework/driver-definitions": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
48
|
+
"@fluidframework/driver-utils": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
49
|
+
"@fluidframework/local-driver": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
50
|
+
"@fluidframework/map": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
51
51
|
"@fluidframework/protocol-definitions": "^1.1.0",
|
|
52
|
-
"@fluidframework/request-handler": ">=2.0.0-internal.
|
|
53
|
-
"@fluidframework/routerlicious-driver": ">=2.0.0-internal.
|
|
54
|
-
"@fluidframework/runtime-definitions": ">=2.0.0-internal.
|
|
55
|
-
"@fluidframework/runtime-utils": ">=2.0.0-internal.
|
|
56
|
-
"@fluidframework/telemetry-utils": ">=2.0.0-internal.
|
|
57
|
-
"@fluidframework/test-driver-definitions": ">=2.0.0-internal.
|
|
58
|
-
"@fluidframework/test-runtime-utils": ">=2.0.0-internal.
|
|
52
|
+
"@fluidframework/request-handler": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
53
|
+
"@fluidframework/routerlicious-driver": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
54
|
+
"@fluidframework/runtime-definitions": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
55
|
+
"@fluidframework/runtime-utils": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
56
|
+
"@fluidframework/telemetry-utils": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
57
|
+
"@fluidframework/test-driver-definitions": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
58
|
+
"@fluidframework/test-runtime-utils": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
59
59
|
"best-random": "^1.0.0",
|
|
60
60
|
"debug": "^4.1.1",
|
|
61
61
|
"uuid": "^8.3.1"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@fluid-tools/build-cli": "^0.21.0",
|
|
65
|
-
"@fluidframework/build-common": "^
|
|
65
|
+
"@fluidframework/build-common": "^2.0.0",
|
|
66
66
|
"@fluidframework/build-tools": "^0.21.0",
|
|
67
67
|
"@fluidframework/eslint-config-fluid": "^2.0.0",
|
|
68
|
-
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.
|
|
68
|
+
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.6.0.0 <2.0.0-internal.6.1.0",
|
|
69
69
|
"@fluidframework/test-utils-previous": "npm:@fluidframework/test-utils@2.0.0-internal.5.2.0",
|
|
70
70
|
"@microsoft/api-extractor": "^7.34.4",
|
|
71
71
|
"@types/debug": "^4.1.5",
|
|
72
72
|
"@types/diff": "^3.5.1",
|
|
73
73
|
"@types/mocha": "^9.1.1",
|
|
74
|
-
"@types/node": "^
|
|
74
|
+
"@types/node": "^16.18.38",
|
|
75
75
|
"@types/random-js": "^1.0.31",
|
|
76
76
|
"@types/uuid": "^8.3.0",
|
|
77
77
|
"concurrently": "^7.6.0",
|
|
@@ -90,7 +90,21 @@
|
|
|
90
90
|
"typescript": "~4.5.5"
|
|
91
91
|
},
|
|
92
92
|
"typeValidation": {
|
|
93
|
-
"broken": {
|
|
93
|
+
"broken": {
|
|
94
|
+
"ClassDeclaration_TestFluidObject": {
|
|
95
|
+
"forwardCompat": false
|
|
96
|
+
},
|
|
97
|
+
"ClassDeclaration_EventAndErrorTrackingLogger": {
|
|
98
|
+
"backCompat": false
|
|
99
|
+
},
|
|
100
|
+
"ClassDeclaration_TestObjectProvider": {
|
|
101
|
+
"backCompat": false
|
|
102
|
+
},
|
|
103
|
+
"RemovedFunctionDeclaration_createSummarizerWithTestConfig": {
|
|
104
|
+
"forwardCompat": false,
|
|
105
|
+
"backCompat": false
|
|
106
|
+
}
|
|
107
|
+
}
|
|
94
108
|
},
|
|
95
109
|
"scripts": {
|
|
96
110
|
"build": "fluid-build . --task build",
|
|
@@ -100,7 +114,7 @@
|
|
|
100
114
|
"build:genver": "gen-version",
|
|
101
115
|
"build:test": "tsc --project ./src/test/tsconfig.json",
|
|
102
116
|
"ci:build:docs": "api-extractor run --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/* ../../../_api-extractor-temp/",
|
|
103
|
-
"clean": "rimraf dist lib *.tsbuildinfo *.build.log",
|
|
117
|
+
"clean": "rimraf --glob \"dist\" \"lib\" \"*.tsbuildinfo\" \"*.build.log\"",
|
|
104
118
|
"eslint": "eslint --format stylish src",
|
|
105
119
|
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
106
120
|
"format": "npm run prettier:fix",
|
package/src/TestSummaryUtils.ts
CHANGED
|
@@ -6,11 +6,7 @@
|
|
|
6
6
|
import { ContainerRuntimeFactoryWithDefaultDataStore } from "@fluidframework/aqueduct";
|
|
7
7
|
import { assert } from "@fluidframework/common-utils";
|
|
8
8
|
import { IContainer, IHostLoader, LoaderHeader } from "@fluidframework/container-definitions";
|
|
9
|
-
import {
|
|
10
|
-
IGCRuntimeOptions,
|
|
11
|
-
ISummarizer,
|
|
12
|
-
ISummaryRuntimeOptions,
|
|
13
|
-
} from "@fluidframework/container-runtime";
|
|
9
|
+
import { ISummarizer, ISummaryRuntimeOptions } from "@fluidframework/container-runtime";
|
|
14
10
|
import { ITelemetryBaseLogger, FluidObject, IRequest } from "@fluidframework/core-interfaces";
|
|
15
11
|
import { DriverHeader } from "@fluidframework/driver-definitions";
|
|
16
12
|
import {
|
|
@@ -18,8 +14,8 @@ import {
|
|
|
18
14
|
IFluidDataStoreFactory,
|
|
19
15
|
NamedFluidDataStoreRegistryEntries,
|
|
20
16
|
} from "@fluidframework/runtime-definitions";
|
|
21
|
-
import { requestFluidObject } from "@fluidframework/runtime-utils";
|
|
22
17
|
import { IConfigProviderBase } from "@fluidframework/telemetry-utils";
|
|
18
|
+
import { requestFluidObject } from "@fluidframework/runtime-utils";
|
|
23
19
|
import { ITestContainerConfig, ITestObjectProvider } from "./testObjectProvider";
|
|
24
20
|
import { mockConfigProvider } from "./TestConfigs";
|
|
25
21
|
import { waitForContainerConnection } from "./containerUtils";
|
|
@@ -108,51 +104,28 @@ export async function createSummarizerFromFactory(
|
|
|
108
104
|
return createSummarizerCore(container, loader, summaryVersion);
|
|
109
105
|
}
|
|
110
106
|
|
|
111
|
-
/**
|
|
112
|
-
* Creates a summarizer client from the given container and returns the summarizer client's IContainer and ISummarizer.
|
|
113
|
-
* The ISummarizer can be used to generate on-demand summaries. The IContainer can be used to fetch data stores, etc.
|
|
114
|
-
*/
|
|
115
|
-
export async function createSummarizer(
|
|
116
|
-
provider: ITestObjectProvider,
|
|
117
|
-
container: IContainer,
|
|
118
|
-
summaryVersion?: string,
|
|
119
|
-
gcOptions?: IGCRuntimeOptions,
|
|
120
|
-
configProvider: IConfigProviderBase = mockConfigProvider(),
|
|
121
|
-
logger?: ITelemetryBaseLogger,
|
|
122
|
-
): Promise<{ container: IContainer; summarizer: ISummarizer }> {
|
|
123
|
-
const testContainerConfig: ITestContainerConfig = {
|
|
124
|
-
runtimeOptions: {
|
|
125
|
-
summaryOptions: defaultSummaryOptions,
|
|
126
|
-
gcOptions,
|
|
127
|
-
},
|
|
128
|
-
loaderProps: { configProvider, logger },
|
|
129
|
-
};
|
|
130
|
-
const loader = provider.makeTestLoader(testContainerConfig);
|
|
131
|
-
return createSummarizerCore(container, loader, summaryVersion);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
107
|
/**
|
|
135
108
|
* Creates a summarizer client from the given container and returns the summarizer client's IContainer and ISummarizer.
|
|
136
109
|
* The ISummarizer can be used to generate on-demand summaries. The IContainer can be used to fetch data stores, etc.
|
|
137
110
|
*
|
|
138
111
|
* Can pass in a test config provider to enable/disable features.
|
|
139
112
|
*/
|
|
140
|
-
export async function
|
|
113
|
+
export async function createSummarizer(
|
|
141
114
|
provider: ITestObjectProvider,
|
|
142
115
|
container: IContainer,
|
|
143
|
-
config
|
|
116
|
+
config?: ITestContainerConfig,
|
|
144
117
|
summaryVersion?: string,
|
|
145
118
|
logger?: ITelemetryBaseLogger,
|
|
146
119
|
): Promise<{ container: IContainer; summarizer: ISummarizer }> {
|
|
147
120
|
const testContainerConfig: ITestContainerConfig = {
|
|
148
121
|
...config,
|
|
149
122
|
runtimeOptions: {
|
|
150
|
-
...config
|
|
151
|
-
summaryOptions: defaultSummaryOptions,
|
|
123
|
+
...config?.runtimeOptions,
|
|
124
|
+
summaryOptions: config?.runtimeOptions?.summaryOptions ?? defaultSummaryOptions,
|
|
152
125
|
},
|
|
153
126
|
loaderProps: {
|
|
154
|
-
...config
|
|
155
|
-
configProvider: config
|
|
127
|
+
...config?.loaderProps,
|
|
128
|
+
configProvider: config?.loaderProps?.configProvider ?? mockConfigProvider(),
|
|
156
129
|
logger,
|
|
157
130
|
},
|
|
158
131
|
};
|
package/src/index.ts
CHANGED
|
@@ -29,12 +29,7 @@ export {
|
|
|
29
29
|
ITestObjectProvider,
|
|
30
30
|
TestObjectProvider,
|
|
31
31
|
} from "./testObjectProvider";
|
|
32
|
-
export {
|
|
33
|
-
createSummarizer,
|
|
34
|
-
createSummarizerFromFactory,
|
|
35
|
-
summarizeNow,
|
|
36
|
-
createSummarizerWithTestConfig,
|
|
37
|
-
} from "./TestSummaryUtils";
|
|
32
|
+
export { createSummarizer, createSummarizerFromFactory, summarizeNow } from "./TestSummaryUtils";
|
|
38
33
|
export {
|
|
39
34
|
defaultTimeoutDurationMs,
|
|
40
35
|
timeoutAwait,
|
package/src/packageVersion.ts
CHANGED
|
@@ -52,7 +52,8 @@ export const createTestContainerRuntimeFactory = (
|
|
|
52
52
|
public async instantiateFromExisting(runtime: ContainerRuntime): Promise<void> {
|
|
53
53
|
// Validate we can load root data stores.
|
|
54
54
|
// We should be able to load any data store that was created in initializeFirstTime!
|
|
55
|
-
await runtime.
|
|
55
|
+
await (runtime.getAliasedDataStoreEntryPoint?.("default") ??
|
|
56
|
+
runtime.getRootDataStore("default"));
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
async preInitialize(
|
package/src/testFluidObject.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
IRequest,
|
|
9
9
|
IResponse,
|
|
10
10
|
IFluidHandle,
|
|
11
|
-
IFluidRouter,
|
|
12
11
|
FluidObject,
|
|
13
12
|
IProvideFluidRouter,
|
|
14
13
|
} from "@fluidframework/core-interfaces";
|
|
@@ -32,20 +31,7 @@ import { ITestFluidObject } from "./interfaces";
|
|
|
32
31
|
* The shared objects can be retrieved by passing the key of the entry to getSharedObject.
|
|
33
32
|
* It exposes the IFluidDataStoreContext and IFluidDataStoreRuntime.
|
|
34
33
|
*/
|
|
35
|
-
export class TestFluidObject implements ITestFluidObject
|
|
36
|
-
public static async load(
|
|
37
|
-
runtime: IFluidDataStoreRuntime,
|
|
38
|
-
channel: IFluidDataStoreChannel,
|
|
39
|
-
context: IFluidDataStoreContext,
|
|
40
|
-
factoryEntries: Map<string, IChannelFactory>,
|
|
41
|
-
existing: boolean,
|
|
42
|
-
) {
|
|
43
|
-
const fluidObject = new TestFluidObject(runtime, channel, context, factoryEntries);
|
|
44
|
-
await fluidObject.initialize(existing);
|
|
45
|
-
|
|
46
|
-
return fluidObject;
|
|
47
|
-
}
|
|
48
|
-
|
|
34
|
+
export class TestFluidObject implements ITestFluidObject {
|
|
49
35
|
public get ITestFluidObject() {
|
|
50
36
|
return this;
|
|
51
37
|
}
|
|
@@ -54,6 +40,9 @@ export class TestFluidObject implements ITestFluidObject, IFluidRouter {
|
|
|
54
40
|
return this;
|
|
55
41
|
}
|
|
56
42
|
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
|
|
45
|
+
*/
|
|
57
46
|
public get IFluidRouter() {
|
|
58
47
|
return this;
|
|
59
48
|
}
|
|
@@ -64,6 +53,7 @@ export class TestFluidObject implements ITestFluidObject, IFluidRouter {
|
|
|
64
53
|
|
|
65
54
|
public root!: ISharedMap;
|
|
66
55
|
private readonly innerHandle: IFluidHandle<this>;
|
|
56
|
+
private initializeP: Promise<void> | undefined;
|
|
67
57
|
|
|
68
58
|
/**
|
|
69
59
|
* Creates a new TestFluidObject.
|
|
@@ -100,23 +90,39 @@ export class TestFluidObject implements ITestFluidObject, IFluidRouter {
|
|
|
100
90
|
throw new Error(`Shared object with id ${id} not found.`);
|
|
101
91
|
}
|
|
102
92
|
|
|
93
|
+
/**
|
|
94
|
+
* @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
|
|
95
|
+
*/
|
|
103
96
|
public async request(request: IRequest): Promise<IResponse> {
|
|
104
97
|
return defaultFluidObjectRequestHandler(this, request);
|
|
105
98
|
}
|
|
106
99
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
public async initialize(existing: boolean) {
|
|
101
|
+
const doInitialization = async () => {
|
|
102
|
+
if (!existing) {
|
|
103
|
+
this.root = SharedMap.create(this.runtime, "root");
|
|
104
|
+
|
|
105
|
+
this.factoryEntriesMap.forEach(
|
|
106
|
+
(sharedObjectFactory: IChannelFactory, key: string) => {
|
|
107
|
+
const sharedObject = this.runtime.createChannel(
|
|
108
|
+
key,
|
|
109
|
+
sharedObjectFactory.type,
|
|
110
|
+
);
|
|
111
|
+
this.root.set(key, sharedObject.handle);
|
|
112
|
+
},
|
|
113
|
+
);
|
|
110
114
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this.root.set(key, sharedObject.handle);
|
|
114
|
-
});
|
|
115
|
+
this.root.bindToContext();
|
|
116
|
+
}
|
|
115
117
|
|
|
116
|
-
this.root.
|
|
118
|
+
this.root = (await this.runtime.getChannel("root")) as ISharedMap;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
if (this.initializeP === undefined) {
|
|
122
|
+
this.initializeP = doInitialization();
|
|
117
123
|
}
|
|
118
124
|
|
|
119
|
-
|
|
125
|
+
return this.initializeP;
|
|
120
126
|
}
|
|
121
127
|
}
|
|
122
128
|
|
|
@@ -178,18 +184,16 @@ export class TestFluidObjectFactory implements IFluidDataStoreFactory {
|
|
|
178
184
|
dataTypes.set(sharedMapFactory.type, sharedMapFactory);
|
|
179
185
|
|
|
180
186
|
// Add the object factories to the list to be sent to data store runtime.
|
|
181
|
-
for (const
|
|
182
|
-
const factory = entry[1];
|
|
187
|
+
for (const [, factory] of this.factoryEntries) {
|
|
183
188
|
dataTypes.set(factory.type, factory);
|
|
184
189
|
}
|
|
185
190
|
|
|
186
191
|
// Create a map from the factory entries with entries that don't have the id as undefined. This will be
|
|
187
192
|
// passed to the Fluid object.
|
|
188
193
|
const factoryEntriesMapForObject = new Map<string, IChannelFactory>();
|
|
189
|
-
for (const
|
|
190
|
-
const id = entry[0];
|
|
194
|
+
for (const [id, factory] of this.factoryEntries) {
|
|
191
195
|
if (id !== undefined) {
|
|
192
|
-
factoryEntriesMapForObject.set(id,
|
|
196
|
+
factoryEntriesMapForObject.set(id, factory);
|
|
193
197
|
}
|
|
194
198
|
}
|
|
195
199
|
|
|
@@ -205,20 +209,22 @@ export class TestFluidObjectFactory implements IFluidDataStoreFactory {
|
|
|
205
209
|
},
|
|
206
210
|
);
|
|
207
211
|
|
|
208
|
-
|
|
212
|
+
const runtime = new runtimeClass(context, dataTypes, existing, async () => {
|
|
213
|
+
await instance.initialize(true);
|
|
214
|
+
return instance;
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const instance: TestFluidObject = new TestFluidObject(
|
|
218
|
+
runtime, // runtime
|
|
219
|
+
runtime, // channel
|
|
209
220
|
context,
|
|
210
|
-
|
|
211
|
-
existing,
|
|
212
|
-
async (dataStoreRuntime: IFluidDataStoreRuntime) =>
|
|
213
|
-
TestFluidObject.load(
|
|
214
|
-
dataStoreRuntime,
|
|
215
|
-
// This works because 'runtime' is an instance of runtimeClass (which is a FluidDataStoreRuntime and
|
|
216
|
-
// thus implements IFluidDataStoreChannel) which passes itself as the parameter to this function.
|
|
217
|
-
dataStoreRuntime as FluidDataStoreRuntime,
|
|
218
|
-
context,
|
|
219
|
-
factoryEntriesMapForObject,
|
|
220
|
-
existing,
|
|
221
|
-
),
|
|
221
|
+
factoryEntriesMapForObject,
|
|
222
222
|
);
|
|
223
|
+
|
|
224
|
+
if (!existing) {
|
|
225
|
+
await instance.initialize(false);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return runtime;
|
|
223
229
|
}
|
|
224
230
|
}
|