@@ -42,10 +42,23 @@ export interface TestDefinition<ResultType> {
4242 localRunnerConfig ?: LocalDurableTestRunnerSetupParameters ;
4343}
4444
45+ export interface EventSignatureConfig {
46+ /**
47+ * Due to API delays or other conditions, the number of invocations can change.
48+ * This property sets a threshold where the number of invocations in the actual history
49+ * must be in a specified range based on the expected history.
50+ */
51+ invocationCompletedDifference ?: number ;
52+ }
53+
4554export interface TestHelper {
4655 isTimeSkipping : boolean ;
4756 isCloud : boolean ;
48- assertEventSignatures ( testResult : TestResult , suffix ?: string ) : void ;
57+ assertEventSignatures (
58+ testResult : TestResult ,
59+ suffix ?: string ,
60+ eventSignatureConfig ?: EventSignatureConfig ,
61+ ) : void ;
4962 functionNameMap : FunctionNameMap ;
5063}
5164
@@ -104,10 +117,34 @@ function assertEventSignatures(
104117 actualEvents : Event [ ] ,
105118 expectedEvents : EventSignature [ ] ,
106119 isTimeSkipping : boolean = false ,
120+ eventSignatureConfig ?: EventSignatureConfig ,
107121) {
108122 const actualCounts = countEventSignatures ( actualEvents , isTimeSkipping ) ;
109123 const expectedCounts = countEventSignatures ( expectedEvents , isTimeSkipping ) ;
110124
125+ if ( eventSignatureConfig ?. invocationCompletedDifference ) {
126+ const invocationCompletedSignature = JSON . stringify (
127+ createEventSignature ( { EventType : EventType . InvocationCompleted } ) ,
128+ ) ;
129+
130+ const actualInvocationCompleted = actualCounts . get (
131+ invocationCompletedSignature ,
132+ ) ;
133+ actualCounts . delete ( invocationCompletedSignature ) ;
134+
135+ const expectedInvocationsCompleted = expectedCounts . get (
136+ invocationCompletedSignature ,
137+ ) ;
138+ expectedCounts . delete ( invocationCompletedSignature ) ;
139+
140+ const invocationCompletedDifference = Math . abs (
141+ actualInvocationCompleted - expectedInvocationsCompleted ,
142+ ) ;
143+ expect ( invocationCompletedDifference ) . toBeLessThanOrEqual (
144+ eventSignatureConfig . invocationCompletedDifference ,
145+ ) ;
146+ }
147+
111148 expect ( actualCounts ) . toEqual ( expectedCounts ) ;
112149}
113150
@@ -155,7 +192,11 @@ export function createTests<ResultType>(testDef: TestDefinition<ResultType>) {
155192 const testHelper : TestHelper = {
156193 isTimeSkipping : isTimeSkipping && ! generateHistories ,
157194 isCloud : isIntegrationTest ,
158- assertEventSignatures : ( testResult : TestResult , suffix ) => {
195+ assertEventSignatures : (
196+ testResult : TestResult ,
197+ suffix ,
198+ eventSignatureConfig ,
199+ ) => {
159200 calledAssertEventSignature = true ;
160201
161202 const historyFileBasename = suffix
@@ -188,6 +229,7 @@ export function createTests<ResultType>(testDef: TestDefinition<ResultType>) {
188229 testResult . getHistoryEvents ( ) ,
189230 JSON . parse ( readFileSync ( historyFilePath ) . toString ( "utf-8" ) ) ,
190231 isTimeSkipping ,
232+ eventSignatureConfig ,
191233 ) ;
192234 } ,
193235 functionNameMap : isIntegrationTest
0 commit comments