go.uber.org/cadence@v1.2.9/internal/internal_retry_test.go (about) 1 // Copyright (c) 2017-2021 Uber Technologies Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package internal 22 23 import ( 24 "errors" 25 "testing" 26 27 "github.com/stretchr/testify/assert" 28 29 s "go.uber.org/cadence/.gen/go/shared" 30 ) 31 32 func TestErrRetries(t *testing.T) { 33 t.Run("retryable", func(t *testing.T) { 34 for _, err := range []error{ 35 // service-busy means "retry later", which is still transient/retryable. 36 // callers with retries MUST detect this separately and delay before retrying, 37 // and ideally we'll return a minimum time-to-wait in errors in the future. 38 &s.ServiceBusyError{}, 39 40 &s.InternalServiceError{}, // fallback error type from server, "unknown" = "retry might work" 41 errors.New("unrecognized"), // fallback error type elsewhere, "unknown" = "retry might work" 42 43 // below are all server-side internal errors and should never be exposed, they're just included 44 // to be explicit about current behavior (without intentionally deciding on any of them). 45 // retry by default, like any other unknown error. it shouldn't lead to incorrect behavior. 46 &s.CurrentBranchChangedError{}, 47 &s.RetryTaskV2Error{}, 48 &s.RemoteSyncMatchedError{}, 49 &s.InternalDataInconsistencyError{}, 50 } { 51 retryable := isServiceTransientError(err) 52 assert.True(t, retryable, "%T should be transient", err) 53 } 54 }) 55 t.Run("terminal", func(t *testing.T) { 56 for _, err := range []error{ 57 &s.AccessDeniedError{}, // access won't be granted immediately 58 &s.BadRequestError{}, // bad requests don't become good 59 &s.CancellationAlreadyRequestedError{}, // can only cancel once 60 &s.ClientVersionNotSupportedError{}, // clients don't magically upgrade 61 &s.DomainAlreadyExistsError{}, // re-creating again won't work 62 &s.DomainNotActiveError{}, // may actually succeed, but very unlikely to work immediately 63 &s.EntityNotExistsError{}, // may actually succeed, but very unlikely to work immediately 64 &s.FeatureNotEnabledError{}, // features won't magically enable 65 &s.LimitExceededError{}, // adding +1 to a value does not move it below its limit 66 &s.QueryFailedError{}, // arguable, this could be considered "unknown" and retryable 67 &s.WorkflowExecutionAlreadyCompletedError{}, // completed workflows won't uncomplete 68 &s.WorkflowExecutionAlreadyStartedError{}, // started workflows could complete quickly, but re-starting may not be desirable 69 70 errShutdown, // shutdowns can't be stopped 71 } { 72 retryable := isServiceTransientError(err) 73 assert.False(t, retryable, "%T should be fatal", err) 74 } 75 }) 76 }