@@ -420,6 +420,46 @@ public void testCancelAndRerun() throws IOException {
420420 workflowRun .cancel ();
421421 }
422422
423+ /**
424+ * Test force cancel a run.
425+ *
426+ * @throws IOException
427+ * Signals that an I/O exception has occurred.
428+ */
429+ @ Test
430+ public void testForceCancel () throws IOException {
431+ GHWorkflow workflow = repo .getWorkflow (SLOW_WORKFLOW_PATH );
432+
433+ long latestPreexistingWorkflowRunId = getLatestPreexistingWorkflowRunId ();
434+
435+ workflow .dispatch (MAIN_BRANCH );
436+
437+ // now that we have triggered the workflow run, we will wait until it's in progress and then force cancel it
438+ await ((nonRecordingRepo ) -> getWorkflowRun (nonRecordingRepo ,
439+ SLOW_WORKFLOW_NAME ,
440+ MAIN_BRANCH ,
441+ Status .IN_PROGRESS ,
442+ latestPreexistingWorkflowRunId ).isPresent ());
443+
444+ GHWorkflowRun workflowRun = getWorkflowRun (SLOW_WORKFLOW_NAME ,
445+ MAIN_BRANCH ,
446+ Status .IN_PROGRESS ,
447+ latestPreexistingWorkflowRunId )
448+ .orElseThrow (() -> new IllegalStateException ("We must have a valid workflow run starting from here" ));
449+
450+ assertThat (workflowRun .getId (), notNullValue ());
451+
452+ workflowRun .forceCancel ();
453+ long cancelledWorkflowRunId = workflowRun .getId ();
454+
455+ // let's wait until it's completed
456+ await ((nonRecordingRepo ) -> getWorkflowRunStatus (nonRecordingRepo , cancelledWorkflowRunId ) == Status .COMPLETED );
457+
458+ // let's check that it has been properly cancelled
459+ workflowRun = repo .getWorkflowRun (cancelledWorkflowRunId );
460+ assertThat (workflowRun .getConclusion (), equalTo (Conclusion .CANCELLED ));
461+ }
462+
423463 /**
424464 * Test delete.
425465 *
@@ -591,6 +631,7 @@ public void testManualRunAndBasicInformation() throws IOException {
591631 assertThat (workflowRun .getCheckSuiteUrl ().getPath (), containsString ("/check-suites/" ));
592632 assertThat (workflowRun .getArtifactsUrl ().getPath (), endsWith ("/artifacts" ));
593633 assertThat (workflowRun .getCancelUrl ().getPath (), endsWith ("/cancel" ));
634+ assertThat (workflowRun .getForceCancelUrl ().getPath (), endsWith ("/force-cancel" ));
594635 assertThat (workflowRun .getRerunUrl ().getPath (), endsWith ("/rerun" ));
595636 assertThat (workflowRun .getWorkflowUrl ().getPath (), containsString ("/actions/workflows/" ));
596637 assertThat (workflowRun .getHeadBranch (), equalTo (MAIN_BRANCH ));
0 commit comments