go.temporal.io/server@v1.23.0/common/persistence/workflow_state_status_validator_test.go (about)

     1  // The MIT License
     2  //
     3  // Copyright (c) 2020 Temporal Technologies Inc.  All rights reserved.
     4  //
     5  // Copyright (c) 2020 Uber Technologies, Inc.
     6  //
     7  // Permission is hereby granted, free of charge, to any person obtaining a copy
     8  // of this software and associated documentation files (the "Software"), to deal
     9  // in the Software without restriction, including without limitation the rights
    10  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  // copies of the Software, and to permit persons to whom the Software is
    12  // furnished to do so, subject to the following conditions:
    13  //
    14  // The above copyright notice and this permission notice shall be included in
    15  // all copies or substantial portions of the Software.
    16  //
    17  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    18  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    19  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    20  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    21  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    22  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    23  // THE SOFTWARE.
    24  
    25  package persistence
    26  
    27  import (
    28  	"testing"
    29  
    30  	"github.com/stretchr/testify/require"
    31  	"github.com/stretchr/testify/suite"
    32  	enumspb "go.temporal.io/api/enums/v1"
    33  
    34  	enumsspb "go.temporal.io/server/api/enums/v1"
    35  )
    36  
    37  type (
    38  	workflowStateStatusSuite struct {
    39  		suite.Suite
    40  		*require.Assertions
    41  	}
    42  )
    43  
    44  func TestWorkflowStateStatusSuite(t *testing.T) {
    45  	s := new(workflowStateStatusSuite)
    46  	suite.Run(t, s)
    47  }
    48  
    49  func (s *workflowStateStatusSuite) SetupSuite() {
    50  }
    51  
    52  func (s *workflowStateStatusSuite) TearDownSuite() {
    53  
    54  }
    55  
    56  func (s *workflowStateStatusSuite) SetupTest() {
    57  	s.Assertions = require.New(s.T())
    58  }
    59  
    60  func (s *workflowStateStatusSuite) TearDownTest() {
    61  
    62  }
    63  
    64  func (s *workflowStateStatusSuite) TestCreateWorkflowStateStatus_WorkflowStateCreated() {
    65  	statuses := []enumspb.WorkflowExecutionStatus{
    66  		enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
    67  		enumspb.WORKFLOW_EXECUTION_STATUS_FAILED,
    68  		enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED,
    69  		enumspb.WORKFLOW_EXECUTION_STATUS_TERMINATED,
    70  		enumspb.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW,
    71  		enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT,
    72  	}
    73  
    74  	s.NoError(ValidateCreateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_CREATED, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
    75  
    76  	for _, status := range statuses {
    77  		s.NotNil(ValidateCreateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_CREATED, status))
    78  	}
    79  }
    80  
    81  func (s *workflowStateStatusSuite) TestCreateWorkflowStateStatus_WorkflowStateRunning() {
    82  	statuses := []enumspb.WorkflowExecutionStatus{
    83  		enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
    84  		enumspb.WORKFLOW_EXECUTION_STATUS_FAILED,
    85  		enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED,
    86  		enumspb.WORKFLOW_EXECUTION_STATUS_TERMINATED,
    87  		enumspb.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW,
    88  		enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT,
    89  	}
    90  
    91  	s.NoError(ValidateCreateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_RUNNING, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
    92  
    93  	for _, status := range statuses {
    94  		s.NotNil(ValidateCreateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_RUNNING, status))
    95  	}
    96  }
    97  
    98  func (s *workflowStateStatusSuite) TestCreateWorkflowStateStatus_WorkflowStateCompleted() {
    99  	statuses := []enumspb.WorkflowExecutionStatus{
   100  		enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
   101  		enumspb.WORKFLOW_EXECUTION_STATUS_FAILED,
   102  		enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED,
   103  		enumspb.WORKFLOW_EXECUTION_STATUS_TERMINATED,
   104  		enumspb.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW,
   105  		enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT,
   106  	}
   107  
   108  	s.Error(ValidateCreateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
   109  
   110  	for _, status := range statuses {
   111  		s.NoError(ValidateCreateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED, status))
   112  	}
   113  }
   114  
   115  func (s *workflowStateStatusSuite) TestCreateWorkflowStateStatus_WorkflowStateZombie() {
   116  	statuses := []enumspb.WorkflowExecutionStatus{
   117  		enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
   118  		enumspb.WORKFLOW_EXECUTION_STATUS_FAILED,
   119  		enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED,
   120  		enumspb.WORKFLOW_EXECUTION_STATUS_TERMINATED,
   121  		enumspb.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW,
   122  		enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT,
   123  	}
   124  
   125  	s.NoError(ValidateCreateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_ZOMBIE, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
   126  
   127  	for _, status := range statuses {
   128  		s.Error(ValidateCreateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_ZOMBIE, status))
   129  	}
   130  }
   131  
   132  func (s *workflowStateStatusSuite) TestUpdateWorkflowStateStatus_WorkflowStateCreated() {
   133  	statuses := []enumspb.WorkflowExecutionStatus{
   134  		enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
   135  		enumspb.WORKFLOW_EXECUTION_STATUS_FAILED,
   136  		enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED,
   137  		enumspb.WORKFLOW_EXECUTION_STATUS_TERMINATED,
   138  		enumspb.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW,
   139  		enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT,
   140  	}
   141  
   142  	s.NoError(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_CREATED, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
   143  
   144  	for _, status := range statuses {
   145  		s.Error(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_CREATED, status))
   146  	}
   147  }
   148  
   149  func (s *workflowStateStatusSuite) TestUpdateWorkflowStateStatus_WorkflowStateRunning() {
   150  	statuses := []enumspb.WorkflowExecutionStatus{
   151  		enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
   152  		enumspb.WORKFLOW_EXECUTION_STATUS_FAILED,
   153  		enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED,
   154  		enumspb.WORKFLOW_EXECUTION_STATUS_TERMINATED,
   155  		enumspb.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW,
   156  		enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT,
   157  	}
   158  
   159  	s.NoError(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_RUNNING, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
   160  
   161  	for _, status := range statuses {
   162  		s.Error(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_RUNNING, status))
   163  	}
   164  }
   165  
   166  func (s *workflowStateStatusSuite) TestUpdateWorkflowStateStatus_WorkflowStateCompleted() {
   167  	statuses := []enumspb.WorkflowExecutionStatus{
   168  		enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
   169  		enumspb.WORKFLOW_EXECUTION_STATUS_FAILED,
   170  		enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED,
   171  		enumspb.WORKFLOW_EXECUTION_STATUS_TERMINATED,
   172  		enumspb.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW,
   173  		enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT,
   174  	}
   175  
   176  	s.Error(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
   177  
   178  	for _, status := range statuses {
   179  		s.NoError(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED, status))
   180  	}
   181  }
   182  
   183  func (s *workflowStateStatusSuite) TestUpdateWorkflowStateStatus_WorkflowStateZombie() {
   184  	statuses := []enumspb.WorkflowExecutionStatus{
   185  		enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
   186  		enumspb.WORKFLOW_EXECUTION_STATUS_FAILED,
   187  		enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED,
   188  		enumspb.WORKFLOW_EXECUTION_STATUS_TERMINATED,
   189  		enumspb.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW,
   190  		enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT,
   191  	}
   192  
   193  	s.NoError(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_ZOMBIE, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
   194  
   195  	for _, status := range statuses {
   196  		s.Error(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_ZOMBIE, status))
   197  	}
   198  }