import assert from "assert" ; import { ContainerRuntimeFactoryWithDefaultDataStore , DataObject , DataObjectFactory , } from "@fluidframework/aqueduct" ; import { TelemetryNullLogger } from "@fluidframework/common-utils" ; import { ITelemetryBaseEvent } from "@fluidframework/common-definitions" ; import { IContainer } from "@fluidframework/container-definitions" ; import { ISummaryConfiguration } from "@fluidframework/protocol-definitions" ; import { requestFluidObject } from "@fluidframework/runtime-utils" ; import { ITestObjectProvider } from "@fluidframework/test-utils" ; import { describeNoCompat } from "@fluidframework/test-version-utils" ; import { IContainerRuntimeOptions , SummaryCollection } from "@fluidframework/container-runtime" ; import { MockLogger } from "@fluidframework/telemetry-utils" ; import { IContainerRuntimeBase } from "@fluidframework/runtime-definitions" ; import { IRequest } from "@fluidframework/core-interfaces" ; class TestDataObject extends DataObject { public get _root ( ) { return this . root ; } public get _runtime ( ) { return this . runtime ; } public get _context ( ) { return this . context ; } } describeNoCompat ( "Generate Summary Stats" , ( getTestObjectProvider ) => { let provider ; const dataObjectFactory = new DataObjectFactory ( "TestDataObject" , TestDataObject , [ ] , [ ] ) ; const IdleDetectionTime = 100 ; const summaryConfigOverrides = { idleTime : IdleDetectionTime , maxTime : IdleDetectionTime * 12 } ; const runtimeOptions = { summaryOptions : { initialSummarizerDelayMs : 10 , summaryConfigOverrides } , gcOptions : { gcAllowed : true } } ; const innerRequestHandler = async ( request , runtime ) => runtime . IFluidHandleContext . resolveHandle ( request ) ; const runtimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore ( dataObjectFactory , [ [ dataObjectFactory . type , Promise . resolve ( dataObjectFactory ) ] , ] , undefined , [ innerRequestHandler ] , runtimeOptions ) ; let mainContainer ; let mainDataStore ; let summaryCollection ; let mockLogger ; returns async function waitForSummary ( ) { await provider . ensureSynchronized ( ) ; const sequenceNumber = mainContainer . deltaManager . lastSequenceNumber ; await summaryCollection . waitSummaryAck ( sequenceNumber ) ; return sequenceNumber ; } function getGenerateSummaryEvent ( sequenceNumber ) { for ( const event of mockLogger . events ) { if ( event . eventName === "fluid:telemetry:Summarizer:Running:GenerateSummary" && event . referenceSequenceNumber ? event . referenceSequenceNumber >= sequenceNumber : false ) { return event ; } } } const createContainer = async ( logger ) : Promise < IContainer > => provider . createContainer ( runtimeFactory , { logger } ) ; beforeEach ( async ( ) => { provider = getTestObjectProvider ( ) ; mockLogger = new MockLogger ( ) ; mainContainer = await createContainer ( mockLogger ) ; mainDataStore = await requestFluidObject < TestDataObject > ( mainContainer , "default" ) ; mainDataStore . _root . set ( "test" , "value" ) ; await provider . ensureSynchronized ( ) ; summaryCollection = new SummaryCollection ( mainContainer . deltaManager , new TelemetryNullLogger ( ) ) ; } ) ; it ( "should generate correct summary stats with summarizing once" , async ( ) => { const directoryKey = "dataStore2" ; const dataStore2 = await dataObjectFactory . createInstance ( mainDataStore . _context . containerRuntime ) ; mainDataStore . _root . set ( directoryKey , dataStore2 . handle ) ; const sequenceNumber = await waitForSummary ( ) ; const summaryEvent = getGenerateSummaryEvent ( sequenceNumber ) ; assert ( summaryEvent !== undefined , "generate summary event is undefined" ) ; assert . strictEqual ( summaryEvent . dataStoreCount , 2 , "wrong data store count" ) ; assert . strictEqual ( summaryEvent . summarizedDataStoreCount , 2 , "summarized data store count is wrong" ) ; } ) ; it ( "should generate correct summary stats with changed and unchanged data stores" , async ( ) => { const dataStore2 = await dataObjectFactory . createInstance ( mainDataStore . _context . containerRuntime ) ; const dataStore3 = await dataObjectFactory . createInstance ( mainDataStore . _context . containerRuntime ) ; const dataStore4 = await dataObjectFactory . createInstance ( mainDataStore . _context . containerRuntime ) ; const dataStore5 = await dataObjectFactory . createInstance ( mainDataStore . _context . containerRuntime ) ; const dataStore6 = await dataObjectFactory . createInstance ( mainDataStore . _context . containerRuntime ) ; mainDataStore . _root . set ( "dataStore2" , dataStore2 . handle ) ; mainDataStore . _root . set ( "dataStore3" , dataStore3 . handle ) ; mainDataStore . _root . set ( "dataStore4" , dataStore4 . handle ) ; mainDataStore . _root . set ( "dataStore5" , dataStore5 . handle ) ; mainDataStore . _root . set ( "dataStore6" , dataStore6 . handle ) ; let sequenceNumber = await waitForSummary ( ) ; let summaryEvent = getGenerateSummaryEvent ( sequenceNumber ) ; assert ( summaryEvent !== undefined , "generate summary event is undefined" ) ; assert . strictEqual ( summaryEvent . dataStoreCount , 6 , "wrong data store count" ) ; assert . strictEqual ( summaryEvent . summarizedDataStoreCount , 6 , "summarized data store count is wrong" ) ; mainDataStore . _root . delete ( "dataStore2" ) ; sequenceNumber = await waitForSummary ( ) ; summaryEvent = getGenerateSummaryEvent ( sequenceNumber ) ; assert ( summaryEvent !== undefined , "generate summary event is undefined" ) ; assert . strictEqual ( summaryEvent . dataStoreCount , 6 , "wrong data store count" ) ; assert . strictEqual ( summaryEvent . summarizedDataStoreCount , 2 , "summarized data store count is wrong" ) ; mainDataStore . _root . delete ( "dataStore3" ) ; mainDataStore . _root . delete ( "dataStore4" ) ; mainDataStore . _root . delete ( "dataStore5" ) ; sequenceNumber = await waitForSummary ( ) ; summaryEvent = getGenerateSummaryEvent ( sequenceNumber ) ; assert ( summaryEvent !== undefined , "generate summary event is undefined" ) ; assert . strictEqual ( summaryEvent . dataStoreCount , 6 , "wrong data store count" ) ; assert . strictEqual ( summaryEvent . summarizedDataStoreCount , 4 , "summarized data store count is wrong" ) ; } ) ; } ) ;