github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/framework/internal/errors/fail_fast_test.go (about)

     1  // Copyright 2022 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language
    12  
    13  package errors
    14  
    15  import (
    16  	"testing"
    17  
    18  	"github.com/pingcap/tiflow/pkg/errors"
    19  	"github.com/stretchr/testify/require"
    20  )
    21  
    22  func TestFailFastWrap(t *testing.T) {
    23  	t.Parallel()
    24  
    25  	// Note: this error is only used for testing.
    26  	// Feel free to replace it with another one.
    27  	testErr := errors.ErrTooManyStatusUpdates.GenWithStackByArgs()
    28  
    29  	err := FailFast(testErr)
    30  	require.True(t, errors.Is(err, errors.ErrTooManyStatusUpdates))
    31  	require.Regexp(t, "ErrTooManyStatusUpdates", err)
    32  
    33  	require.True(t, IsFailFastError(err))
    34  }
    35  
    36  func TestIsFailFastErrorFalse(t *testing.T) {
    37  	t.Parallel()
    38  
    39  	anyErr := errors.New("test")
    40  	require.False(t, IsFailFastError(anyErr))
    41  }
    42  
    43  func TestFailFastWrapNil(t *testing.T) {
    44  	t.Parallel()
    45  
    46  	require.NoError(t, FailFast(nil))
    47  }