go.uber.org/cadence@v1.2.9/test/replaytests/sequential_workflow.go (about) 1 // Copyright (c) 2017 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 replaytests 22 23 import ( 24 "context" 25 "fmt" 26 "time" 27 28 "go.uber.org/cadence/activity" 29 "go.uber.org/cadence/workflow" 30 "go.uber.org/zap" 31 ) 32 33 type replayerSampleMessage struct { 34 Message string 35 } 36 37 // replayerHelloWorldWorkflow is a sample workflow that runs replayerHelloWorldActivity. 38 // In the previous version it was running the activity twice, sequentially. 39 // History of a past execution is in sequential.json 40 // Corresponding unit test covers the scenario that new workflow's history records is subset of previous version's history. 41 // 42 // v1: wf started -> call activity -> call activity -> wf complete 43 // v2: wf started -> call activity -> wf complete 44 // 45 // The v2 clearly has determinism issues and should be considered as non-determism error for replay tests. 46 func replayerHelloWorldWorkflow(ctx workflow.Context, inputMsg *replayerSampleMessage) error { 47 ao := workflow.ActivityOptions{ 48 ScheduleToStartTimeout: time.Minute, 49 StartToCloseTimeout: time.Minute, 50 } 51 logger := workflow.GetLogger(ctx) 52 logger.Info("executing replayerHelloWorldWorkflow") 53 ctx = workflow.WithActivityOptions(ctx, ao) 54 55 count := 1 56 for i := 0; i < count; i++ { 57 var greeting string 58 err := workflow.ExecuteActivity(ctx, replayerHelloWorldActivity, inputMsg).Get(ctx, &greeting) 59 if err != nil { 60 logger.Error("replayerHelloWorldActivity is broken ", zap.Error(err)) 61 return err 62 } 63 64 logger.Sugar().Infof("replayerHelloWorldWorkflow is greeting to you %dth time -> ", i, greeting) 65 } 66 67 return nil 68 } 69 70 // replayerHelloWorldActivity takes a sample message input and return a greeting to the caller. 71 func replayerHelloWorldActivity(ctx context.Context, inputMsg *replayerSampleMessage) (string, error) { 72 logger := activity.GetLogger(ctx) 73 logger.Info("executing replayerHelloWorldActivity") 74 75 return fmt.Sprintf("Hello, %s!", inputMsg.Message), nil 76 }