import { strict as assert } from "assert" ; import { EventEmitter } from "events" ; import { Deferred } from "@fluidframework/common-utils" ; import { IContext , IQueuedMessage , ILogger , IContextErrorData } from "@fluidframework/server-services-core" ; import { Lumberjack , TestEngine1 } from "@fluidframework/server-services-telemetry" ; import { DebugLogger } from "./logger" ; interface IWaitOffset { deferred : Deferred < void > ; value : number ; } export class TestContext extends EventEmitter implements IContext { public offset : number = - 1 ; private waits : IWaitOffset [ ] = [ ] ; constructor ( public readonly log = DebugLogger . create ( "fluid-server:TestContext" ) ) { super ( ) ; const lumberjackEngine = new TestEngine1 ( ) ; if ( ! Lumberjack . isSetupCompleted ( ) ) { Lumberjack . setup ( [ lumberjackEngine ] ) ; } } public checkpoint ( queuedMessage ) { assert ( queuedMessage . offset > this . offset , `${ queuedMessage . offset } > ${ this . offset }` ) ; this . offset = queuedMessage . offset ; this . waits = this . waits . filter ( ( wait ) => { if ( wait . value <= queuedMessage . offset ) { wait . deferred . resolve ( ) ; return false ; } else { return true ; } } ) ; } public error ( error , errorData ) { this . emit ( "error" , error , errorData ) ; } public waitForOffset ( value ) { if ( value <= this . offset ) { return Promise . resolve ( ) ; } const deferred = new Deferred < void > ( ) ; this . waits . push ( { deferred , value } ) ; return deferred . promise ; } public getContextError ( ) { return ; } }