@@ -628,7 +628,7 @@ public void testNexusOperationTimeout_AfterStart() {
628628 }
629629 }
630630
631- @ Test (timeout = 30000 )
631+ @ Test (timeout = 60000 )
632632 public void testNexusOperationTimeout_AfterCancel () {
633633 String operationId = UUID .randomUUID ().toString ();
634634 CompletableFuture <?> nexusPoller =
@@ -644,7 +644,7 @@ public void testNexusOperationTimeout_AfterCancel() {
644644 pollResp .getTaskToken (),
645645 newScheduleOperationCommand (
646646 defaultScheduleOperationAttributes ()
647- .setScheduleToCloseTimeout (Durations .fromSeconds (22 ))));
647+ .setScheduleToCloseTimeout (Durations .fromSeconds (10 ))));
648648 testWorkflowRule .assertHistoryEvent (
649649 execution .getWorkflowId (), EventType .EVENT_TYPE_NEXUS_OPERATION_SCHEDULED );
650650
@@ -669,24 +669,21 @@ public void testNexusOperationTimeout_AfterCancel() {
669669 .build ();
670670 completeWorkflowTask (pollResp .getTaskToken (), cancelCmd );
671671
672- // Poll for cancellation task but do not complete it
673- PollNexusTaskQueueResponse nexusPollResp = pollNexusTask ().get ();
674- Assert .assertTrue (nexusPollResp .getRequest ().hasCancelOperation ());
675-
676- // Request timeout and long poll deadline are both 10s, so sleep to give some buffer so poll
677- // request doesn't timeout.
678- Thread .sleep (2000 );
679-
680- // Poll for cancellation task again
681- nexusPollResp = pollNexusTask ().get ();
682- Assert .assertTrue (nexusPollResp .getRequest ().hasCancelOperation ());
683-
684- // Request timeout and long poll deadline are both 10s, so sleep to give some buffer so poll
685- // request doesn't timeout.
686- Thread .sleep (2000 );
672+ // The cancel task may not be completed in time, causing a
673+ // NEXUS_OPERATION_CANCEL_REQUEST_FAILED event and a new WFT. Handle any intermediate WFTs
674+ // until the operation actually times out.
675+ while (true ) {
676+ pollResp = pollWorkflowTask ();
677+ events =
678+ testWorkflowRule .getHistoryEvents (
679+ execution .getWorkflowId (), EventType .EVENT_TYPE_NEXUS_OPERATION_TIMED_OUT );
680+ if (!events .isEmpty ()) {
681+ break ;
682+ }
683+ // Not timed out yet, acknowledge the WFT and keep waiting
684+ completeWorkflowTask (pollResp .getTaskToken ());
685+ }
687686
688- // Poll to wait for new task after operation times out
689- pollResp = pollWorkflowTask ();
690687 completeWorkflow (pollResp .getTaskToken ());
691688
692689 events =
@@ -710,18 +707,21 @@ public void testNexusOperationTimeout_AfterCancel() {
710707 }
711708 }
712709
713- @ Test
710+ @ Test ( timeout = 30000 )
714711 public void testNexusOperationScheduleToStartTimeout () {
715712 WorkflowStub stub = newWorkflowStub ("TestNexusOperationScheduleToStartTimeoutWorkflow" );
716713 WorkflowExecution execution = stub .start ();
717714
715+ // Use a longer schedule-to-start timeout so the nexus poll has time to return on real server
716+ int scheduleToStartSeconds = testWorkflowRule .isUseExternalService () ? 10 : 1 ;
717+
718718 // Get first WFT and respond with ScheduleNexusOperation command with schedule-to-start timeout
719719 PollWorkflowTaskQueueResponse pollResp = pollWorkflowTask ();
720720 completeWorkflowTask (
721721 pollResp .getTaskToken (),
722722 newScheduleOperationCommand (
723723 defaultScheduleOperationAttributes ()
724- .setScheduleToStartTimeout (Durations .fromSeconds (1 ))
724+ .setScheduleToStartTimeout (Durations .fromSeconds (scheduleToStartSeconds ))
725725 .setScheduleToCloseTimeout (Durations .fromSeconds (30 ))));
726726 testWorkflowRule .assertHistoryEvent (
727727 execution .getWorkflowId (), EventType .EVENT_TYPE_NEXUS_OPERATION_SCHEDULED );
@@ -746,7 +746,7 @@ public void testNexusOperationScheduleToStartTimeout() {
746746 Assert .assertTrue ("OPERATION_TIMEOUT should be positive" , operationTimeoutMs > 0 );
747747
748748 // Sleep longer than schedule-to-start timeout to trigger the timeout
749- testWorkflowRule .sleep (Duration .ofSeconds (2 ));
749+ testWorkflowRule .sleep (Duration .ofSeconds (scheduleToStartSeconds + 1 ));
750750 } catch (Exception e ) {
751751 Assert .fail (e .getMessage ());
752752 }
@@ -885,8 +885,6 @@ public void testNexusOperationError() {
885885 Assert .assertEquals ("nexus operation completed unsuccessfully" , failure .getMessage ());
886886 io .temporal .api .failure .v1 .Failure cause = failure .getCause ();
887887 Assert .assertEquals ("deliberate test failure" , cause .getMessage ());
888- Assert .assertTrue (cause .hasApplicationFailureInfo ());
889- Assert .assertEquals ("NexusFailure" , cause .getApplicationFailureInfo ().getType ());
890888 } catch (Exception e ) {
891889 Assert .fail (e .getMessage ());
892890 } finally {
@@ -947,9 +945,9 @@ public void testNexusOperationHandlerError() {
947945 assertOperationFailureInfo (failure .getNexusOperationExecutionFailureInfo ());
948946 Assert .assertEquals ("nexus operation completed unsuccessfully" , failure .getMessage ());
949947 io .temporal .api .failure .v1 .Failure cause = failure .getCause ();
950- Assert .assertTrue (cause .getMessage ().endsWith ("deliberate terminal error" ));
951948 Assert .assertTrue (cause .hasNexusHandlerFailureInfo ());
952949 Assert .assertEquals ("BAD_REQUEST" , cause .getNexusHandlerFailureInfo ().getType ());
950+ Assert .assertEquals ("deliberate terminal error" , cause .getCause ().getMessage ());
953951 } catch (Exception e ) {
954952 Assert .fail (e .getMessage ());
955953 } finally {
@@ -1016,9 +1014,9 @@ public void testNexusOperationHandlerTemporalFailure() {
10161014 assertOperationFailureInfo (failure .getNexusOperationExecutionFailureInfo ());
10171015 Assert .assertEquals ("nexus operation completed unsuccessfully" , failure .getMessage ());
10181016 io .temporal .api .failure .v1 .Failure cause = failure .getCause ();
1019- Assert .assertTrue (cause .getMessage ().endsWith ("deliberate terminal error" ));
10201017 Assert .assertTrue (cause .hasNexusHandlerFailureInfo ());
10211018 Assert .assertEquals ("BAD_REQUEST" , cause .getNexusHandlerFailureInfo ().getType ());
1019+ Assert .assertEquals ("deliberate terminal error" , cause .getCause ().getMessage ());
10221020 } catch (Exception e ) {
10231021 Assert .fail (e .getMessage ());
10241022 } finally {
0 commit comments