@@ -42,16 +42,9 @@ import { encode } from '@temporalio/common/lib/encoding';
4242import { signalSchedulingWorkflow } from './activities/helpers' ;
4343import { activityStartedSignal } from './workflows/definitions' ;
4444import * as workflows from './workflows' ;
45- import {
46- Context ,
47- createLocalTestEnvironment ,
48- hasActivityHeartbeat ,
49- helpers ,
50- makeTestFunction ,
51- setActivityState ,
52- } from './helpers-integration' ;
45+ import { Context , createLocalTestEnvironment , helpers , makeTestFunction } from './helpers-integration' ;
5346import { overrideSdkInternalFlag } from './mock-internal-flags' ;
54- import { heartbeatCancellationDetailsActivity } from './activities/heartbeat-cancellation-details' ;
47+ import { ActivityState , heartbeatCancellationDetailsActivity } from './activities/heartbeat-cancellation-details' ;
5548import { loadHistory , RUN_TIME_SKIPPING_TESTS , waitUntil } from './helpers' ;
5649
5750const test = makeTestFunction ( {
@@ -1441,51 +1434,33 @@ test('Workflow can return root workflow', async (t) => {
14411434 } ) ;
14421435} ) ;
14431436
1444- export async function heartbeatPauseWorkflow (
1445- activityId : string ,
1446- catchErr : boolean ,
1447- maximumAttempts : number
1437+ export async function heartbeatCancellationWorkflow (
1438+ state : ActivityState
14481439) : Promise < ActivityCancellationDetails | undefined > {
14491440 const { heartbeatCancellationDetailsActivity } = workflow . proxyActivities ( {
14501441 startToCloseTimeout : '5s' ,
1451- activityId,
14521442 retry : {
1453- maximumAttempts,
1443+ maximumAttempts : 2 ,
14541444 } ,
14551445 heartbeatTimeout : '1s' ,
14561446 } ) ;
14571447
1458- return await heartbeatCancellationDetailsActivity ( catchErr ) ;
1448+ return await heartbeatCancellationDetailsActivity ( state ) ;
14591449}
14601450
14611451test ( 'Activity pause returns expected cancellation details' , async ( t ) => {
1462- const { createWorker, startWorkflow } = helpers ( t ) ;
1463-
1452+ const { createWorker, executeWorkflow } = helpers ( t ) ;
14641453 const worker = await createWorker ( {
14651454 activities : {
14661455 heartbeatCancellationDetailsActivity,
14671456 } ,
14681457 } ) ;
14691458
14701459 await worker . runUntil ( async ( ) => {
1471- const testActivityId = randomUUID ( ) ;
1472- const handle = await startWorkflow ( heartbeatPauseWorkflow , {
1473- args : [ testActivityId , true , 1 ] ,
1460+ const result = await executeWorkflow ( heartbeatCancellationWorkflow , {
1461+ args : [ { pause : true } ] ,
14741462 } ) ;
14751463
1476- // Wait for activity to appear in pending activities AND start heartbeating
1477- await waitUntil ( async ( ) => {
1478- const { raw } = await handle . describe ( ) ;
1479- const activityInfo = raw . pendingActivities ?. find ( ( act ) => act . activityId === testActivityId ) ;
1480- // Check both: activity exists and has heartbeated
1481- return ! ! ( activityInfo && ( await hasActivityHeartbeat ( handle , testActivityId , 'heartbeated' ) ) ) ;
1482- } , 10000 ) ;
1483-
1484- // Now pause the activity
1485- await setActivityState ( handle , testActivityId , 'pause' ) ;
1486- // Get the result - should contain pause cancellation details
1487- const result = await handle . result ( ) ;
1488-
14891464 t . deepEqual ( result , {
14901465 cancelRequested : false ,
14911466 notFound : false ,
@@ -1498,7 +1473,7 @@ test('Activity pause returns expected cancellation details', async (t) => {
14981473} ) ;
14991474
15001475test ( 'Activity can be cancelled via pause and retry after unpause' , async ( t ) => {
1501- const { createWorker, startWorkflow } = helpers ( t ) ;
1476+ const { createWorker, executeWorkflow } = helpers ( t ) ;
15021477
15031478 const worker = await createWorker ( {
15041479 activities : {
@@ -1507,46 +1482,25 @@ test('Activity can be cancelled via pause and retry after unpause', async (t) =>
15071482 } ) ;
15081483
15091484 await worker . runUntil ( async ( ) => {
1510- const testActivityId = randomUUID ( ) ;
1511- const handle = await startWorkflow ( heartbeatPauseWorkflow , { args : [ testActivityId , false , 2 ] } ) ;
1512-
1513- // Wait for it to exist and heartbeat
1514- await waitUntil ( async ( ) => {
1515- const { raw } = await handle . describe ( ) ;
1516- const activityInfo = raw . pendingActivities ?. find ( ( act ) => act . activityId === testActivityId ) ;
1517- return ! ! ( activityInfo && ( await hasActivityHeartbeat ( handle , testActivityId , 'heartbeated' ) ) ) ;
1518- } , 10000 ) ;
1519-
1520- await setActivityState ( handle , testActivityId , 'pause' ) ;
1521- await waitUntil ( async ( ) => hasActivityHeartbeat ( handle , testActivityId , 'finally-complete' ) , 10000 ) ;
1522- await setActivityState ( handle , testActivityId , 'unpause' ) ;
1523-
1524- const result = await handle . result ( ) ;
1485+ const result = await executeWorkflow ( heartbeatCancellationWorkflow , {
1486+ args : [ { pause : true , unpause : true , shouldRetry : true } ] ,
1487+ } ) ;
1488+ // Note that we expect the result to be null because unpausing an activity
1489+ // resets the activity context (akin to starting the activity anew)
15251490 t . true ( result == null ) ;
15261491 } ) ;
15271492} ) ;
15281493
1529- test ( 'Activity reset returns expected cancellation details' , async ( t ) => {
1530- const { createWorker, startWorkflow } = helpers ( t ) ;
1494+ test ( 'Activity reset without retry returns expected cancellation details' , async ( t ) => {
1495+ const { createWorker, executeWorkflow } = helpers ( t ) ;
15311496 const worker = await createWorker ( {
15321497 activities : {
15331498 heartbeatCancellationDetailsActivity,
15341499 } ,
15351500 } ) ;
15361501
15371502 await worker . runUntil ( async ( ) => {
1538- const testActivityId = randomUUID ( ) ;
1539- const handle = await startWorkflow ( heartbeatPauseWorkflow , { args : [ testActivityId , true , 1 ] } ) ;
1540-
1541- // Wait for it to exist and heartbeat
1542- await waitUntil ( async ( ) => {
1543- const { raw } = await handle . describe ( ) ;
1544- const activityInfo = raw . pendingActivities ?. find ( ( act ) => act . activityId === testActivityId ) ;
1545- return ! ! ( activityInfo && ( await hasActivityHeartbeat ( handle , testActivityId , 'heartbeated' ) ) ) ;
1546- } , 10000 ) ;
1547-
1548- await setActivityState ( handle , testActivityId , 'reset' ) ;
1549- const result = await handle . result ( ) ;
1503+ const result = await executeWorkflow ( heartbeatCancellationWorkflow , { args : [ { reset : true } ] } ) ;
15501504 t . deepEqual ( result , {
15511505 cancelRequested : false ,
15521506 notFound : false ,
@@ -1558,27 +1512,30 @@ test('Activity reset returns expected cancellation details', async (t) => {
15581512 } ) ;
15591513} ) ;
15601514
1561- test ( 'Activity set as both paused and reset returns expected cancellation details' , async ( t ) => {
1562- const { createWorker, startWorkflow } = helpers ( t ) ;
1515+ test ( 'Activity reset with retry returns expected cancellation details' , async ( t ) => {
1516+ const { createWorker, executeWorkflow } = helpers ( t ) ;
15631517 const worker = await createWorker ( {
15641518 activities : {
15651519 heartbeatCancellationDetailsActivity,
15661520 } ,
15671521 } ) ;
15681522
15691523 await worker . runUntil ( async ( ) => {
1570- const testActivityId = randomUUID ( ) ;
1571- const handle = await startWorkflow ( heartbeatPauseWorkflow , { args : [ testActivityId , true , 1 ] } ) ;
1524+ const result = await executeWorkflow ( heartbeatCancellationWorkflow , { args : [ { reset : true , shouldRetry : true } ] } ) ;
1525+ t . true ( result == null ) ;
1526+ } ) ;
1527+ } ) ;
15721528
1573- // Wait for it to exist and heartbeat
1574- await waitUntil ( async ( ) => {
1575- const { raw } = await handle . describe ( ) ;
1576- const activityInfo = raw . pendingActivities ?. find ( ( act ) => act . activityId === testActivityId ) ;
1577- return ! ! ( activityInfo && ( await hasActivityHeartbeat ( handle , testActivityId , 'heartbeated' ) ) ) ;
1578- } , 10000 ) ;
1529+ test ( 'Activity paused and reset returns expected cancellation details' , async ( t ) => {
1530+ const { createWorker, executeWorkflow } = helpers ( t ) ;
1531+ const worker = await createWorker ( {
1532+ activities : {
1533+ heartbeatCancellationDetailsActivity,
1534+ } ,
1535+ } ) ;
15791536
1580- await setActivityState ( handle , testActivityId , 'pause & reset' ) ;
1581- const result = await handle . result ( ) ;
1537+ await worker . runUntil ( async ( ) => {
1538+ const result = await executeWorkflow ( heartbeatCancellationWorkflow , { args : [ { pause : true , reset : true } ] } ) ;
15821539 t . deepEqual ( result , {
15831540 cancelRequested : false ,
15841541 notFound : false ,
0 commit comments