@@ -2912,6 +2912,38 @@ func TestTerminateExecution_DatabaseError(t *testing.T) {
2912
2912
assert .EqualError (t , err , expectedError .Error ())
2913
2913
}
2914
2914
2915
+ func TestTerminateExecution_AlreadyTerminated (t * testing.T ) {
2916
+ var expectedError = errors .New ("expected error" )
2917
+
2918
+ mockExecutor := workflowengineMocks.WorkflowExecutor {}
2919
+ mockExecutor .OnAbortMatch (mock .Anything , mock .Anything ).Return (expectedError )
2920
+ mockExecutor .OnID ().Return ("customMockExecutor" )
2921
+ r := plugins .NewRegistry ()
2922
+ r .RegisterDefault (plugins .PluginIDWorkflowExecutor , & mockExecutor )
2923
+
2924
+ repository := repositoryMocks .NewMockRepository ()
2925
+ repository .ExecutionRepo ().(* repositoryMocks.MockExecutionRepo ).SetGetCallback (
2926
+ func (ctx context.Context , input interfaces.Identifier ) (models.Execution , error ) {
2927
+ return models.Execution {
2928
+ Phase : core .WorkflowExecution_SUCCEEDED .String (),
2929
+ }, nil
2930
+ })
2931
+ execManager := NewExecutionManager (repository , r , getMockExecutionsConfigProvider (), getMockStorageForExecTest (context .Background ()), mockScope .NewTestScope (), mockScope .NewTestScope (), & mockPublisher , mockExecutionRemoteURL , nil , nil , nil , nil , & eventWriterMocks.WorkflowExecutionEventWriter {})
2932
+ resp , err := execManager .TerminateExecution (context .Background (), admin.ExecutionTerminateRequest {
2933
+ Id : & core.WorkflowExecutionIdentifier {
2934
+ Project : "project" ,
2935
+ Domain : "domain" ,
2936
+ Name : "name" ,
2937
+ },
2938
+ Cause : "abort cause" ,
2939
+ })
2940
+
2941
+ assert .Nil (t , resp )
2942
+ s , ok := status .FromError (err )
2943
+ assert .True (t , ok )
2944
+ assert .Equal (t , codes .PermissionDenied , s .Code ())
2945
+ }
2946
+
2915
2947
func TestGetExecutionData (t * testing.T ) {
2916
2948
repository := repositoryMocks .NewMockRepository ()
2917
2949
startedAt := time .Date (2018 , 8 , 30 , 0 , 0 , 0 , 0 , time .UTC )
0 commit comments