@@ -15,7 +15,8 @@ import { activityStartedSignal } from './workflows/definitions';
1515import * as workflows from './workflows' ;
1616import { Context , helpers , makeTestFunction } from './helpers-integration' ;
1717import { overrideSdkInternalFlag } from './mock-internal-flags' ;
18- import { asSdkLoggerSink , loadHistory , RUN_TIME_SKIPPING_TESTS } from './helpers' ;
18+ import { asSdkLoggerSink , loadHistory , RUN_TIME_SKIPPING_TESTS , waitUntil } from './helpers' ;
19+ import asyncRetry from 'async-retry' ;
1920
2021const test = makeTestFunction ( {
2122 workflowsPath : __filename ,
@@ -1274,27 +1275,36 @@ test('Count workflow executions', async (t) => {
12741275 const worker = await createWorker ( ) ;
12751276 const client = t . context . env . client ;
12761277
1277- await worker . runUntil ( async ( ) => {
1278- // Run 3 workflows that complete.
1279- for ( let i = 0 ; i < 3 ; i ++ ) {
1280- await executeWorkflow ( completableWorkflow , { args : [ true ] } ) ;
1281- }
1282- } ) ;
1283-
12841278 // Run 2 workflows that don't complete
12851279 // (use startWorkflow to avoid waiting for workflows to complete, which they never will)
12861280 for ( let i = 0 ; i < 2 ; i ++ ) {
12871281 await startWorkflow ( completableWorkflow , { args : [ false ] } ) ;
12881282 }
12891283
1290- const actual = await client . workflow . count ( `TaskQueue = '${ taskQueue } ' GROUP BY ExecutionStatus` ) ;
1291- const expected : CountWorkflowExecution = {
1284+ await worker . runUntil ( async ( ) => {
1285+ try {
1286+ // Run 3 workflows that complete.
1287+ await Promise . all ( [
1288+ executeWorkflow ( completableWorkflow , { args : [ true ] } ) ,
1289+ executeWorkflow ( completableWorkflow , { args : [ true ] } ) ,
1290+ executeWorkflow ( completableWorkflow , { args : [ true ] } )
1291+ ] )
1292+ } catch ( err ) {
1293+ throw new Error ( 'executing workflow unexpectedly failed' )
1294+ } ;
1295+ } ) ;
1296+
1297+ const actualTotal = await client . workflow . count ( `TaskQueue = '${ taskQueue } '` ) ;
1298+ t . deepEqual ( actualTotal , { count : 5 , groups : [ ] } ) ;
1299+
1300+ const expectedByExecutionStatus : CountWorkflowExecution = {
12921301 count : 5 ,
12931302 groups : [
1294- { count : 2 , group_values : [ [ 'Runningggg ' ] ] } ,
1295- { count : 3 , group_values : [ [ 'Completedddd ' ] ] } ,
1303+ { count : 2 , groupValues : [ [ 'Running ' ] ] } ,
1304+ { count : 3 , groupValues : [ [ 'Completed ' ] ] } ,
12961305 ] ,
12971306 } ;
1298-
1299- t . deepEqual ( expected , actual ) ;
1307+
1308+ const actualByExecutionStatus = await client . workflow . count ( `TaskQueue = '${ taskQueue } ' GROUP BY ExecutionStatus` ) ;
1309+ t . deepEqual ( actualByExecutionStatus , expectedByExecutionStatus ) ;
13001310} ) ;
0 commit comments