@@ -31,9 +31,11 @@ import (
3131 "time"
3232
3333 "github.com/golang/mock/gomock"
34+ "github.com/opentracing/opentracing-go"
3435 "github.com/stretchr/testify/assert"
3536 "github.com/stretchr/testify/require"
3637 "github.com/stretchr/testify/suite"
38+ "github.com/uber-go/tally"
3739 "go.uber.org/cadence/.gen/go/cadence/workflowservicetest"
3840 "go.uber.org/cadence/.gen/go/shared"
3941 "go.uber.org/cadence/internal/common"
@@ -1133,6 +1135,129 @@ func TestActivityNilArgs_WithDataConverter(t *testing.T) {
11331135 require .Error (t , err ) // testDataConverter cannot encode nil value
11341136}
11351137
1138+ func TestWorkerOptionDefaults (t * testing.T ) {
1139+ domain := "worker-options-test"
1140+ taskList := "worker-options-tl"
1141+ worker := newAggregatedWorker (nil , domain , taskList , WorkerOptions {})
1142+ aggWorker , ok := worker .(* aggregatedWorker )
1143+ require .True (t , ok )
1144+
1145+ decisionWorker , ok := aggWorker .workflowWorker .(* workflowWorker )
1146+ require .True (t , ok )
1147+ require .True (t , decisionWorker .executionParameters .Identity != "" )
1148+ require .NotNil (t , decisionWorker .executionParameters .Logger )
1149+ require .NotNil (t , decisionWorker .executionParameters .MetricsScope )
1150+ require .Nil (t , decisionWorker .executionParameters .ContextPropagators )
1151+
1152+ expected := workerExecutionParameters {
1153+ TaskList : taskList ,
1154+ MaxConcurrentActivityPollers : defaultConcurrentPollRoutineSize ,
1155+ MaxConcurrentDecisionPollers : defaultConcurrentPollRoutineSize ,
1156+ ConcurrentLocalActivityExecutionSize : defaultMaxConcurrentLocalActivityExecutionSize ,
1157+ ConcurrentActivityExecutionSize : defaultMaxConcurrentActivityExecutionSize ,
1158+ ConcurrentDecisionTaskExecutionSize : defaultMaxConcurrentTaskExecutionSize ,
1159+ WorkerActivitiesPerSecond : defaultTaskListActivitiesPerSecond ,
1160+ WorkerDecisionTasksPerSecond : defaultWorkerTaskExecutionRate ,
1161+ TaskListActivitiesPerSecond : defaultTaskListActivitiesPerSecond ,
1162+ WorkerLocalActivitiesPerSecond : defaultWorkerLocalActivitiesPerSecond ,
1163+ StickyScheduleToStartTimeout : stickyDecisionScheduleToStartTimeoutSeconds * time .Second ,
1164+ DataConverter : getDefaultDataConverter (),
1165+ Tracer : opentracing.NoopTracer {},
1166+ Logger : decisionWorker .executionParameters .Logger ,
1167+ MetricsScope : decisionWorker .executionParameters .MetricsScope ,
1168+ Identity : decisionWorker .executionParameters .Identity ,
1169+ UserContext : decisionWorker .executionParameters .UserContext ,
1170+ }
1171+
1172+ assertWorkerExecutionParamsEqual (t , expected , decisionWorker .executionParameters )
1173+
1174+ activityWorker , ok := aggWorker .activityWorker .(* activityWorker )
1175+ require .True (t , ok )
1176+ require .True (t , activityWorker .executionParameters .Identity != "" )
1177+ require .NotNil (t , activityWorker .executionParameters .Logger )
1178+ require .NotNil (t , activityWorker .executionParameters .MetricsScope )
1179+ require .Nil (t , activityWorker .executionParameters .ContextPropagators )
1180+ assertWorkerExecutionParamsEqual (t , expected , activityWorker .executionParameters )
1181+ }
1182+
1183+ func TestWorkerOptionNonDefaults (t * testing.T ) {
1184+ domain := "worker-options-test"
1185+ taskList := "worker-options-tl"
1186+
1187+ options := WorkerOptions {
1188+ Identity : "143@worker-options-test-1" ,
1189+ TaskListActivitiesPerSecond : 8888 ,
1190+ MaxConcurrentSessionExecutionSize : 3333 ,
1191+ MaxConcurrentDecisionTaskExecutionSize : 2222 ,
1192+ MaxConcurrentActivityExecutionSize : 1111 ,
1193+ MaxConcurrentLocalActivityExecutionSize : 101 ,
1194+ MaxConcurrentDecisionTaskPollers : 11 ,
1195+ MaxConcurrentActivityTaskPollers : 12 ,
1196+ WorkerLocalActivitiesPerSecond : 222 ,
1197+ WorkerDecisionTasksPerSecond : 111 ,
1198+ WorkerActivitiesPerSecond : 99 ,
1199+ StickyScheduleToStartTimeout : 555 * time .Minute ,
1200+ DataConverter : & defaultDataConverter {},
1201+ BackgroundActivityContext : context .Background (),
1202+ Logger : zap .NewNop (),
1203+ MetricsScope : tally .NoopScope ,
1204+ Tracer : opentracing.NoopTracer {},
1205+ }
1206+
1207+ worker := newAggregatedWorker (nil , domain , taskList , options )
1208+ aggWorker , ok := worker .(* aggregatedWorker )
1209+ require .True (t , ok )
1210+
1211+ decisionWorker , ok := aggWorker .workflowWorker .(* workflowWorker )
1212+ require .True (t , len (decisionWorker .executionParameters .ContextPropagators ) > 0 )
1213+ require .True (t , ok )
1214+
1215+ expected := workerExecutionParameters {
1216+ TaskList : taskList ,
1217+ MaxConcurrentActivityPollers : options .MaxConcurrentActivityTaskPollers ,
1218+ MaxConcurrentDecisionPollers : options .MaxConcurrentDecisionTaskPollers ,
1219+ ConcurrentLocalActivityExecutionSize : options .MaxConcurrentLocalActivityExecutionSize ,
1220+ ConcurrentActivityExecutionSize : options .MaxConcurrentActivityExecutionSize ,
1221+ ConcurrentDecisionTaskExecutionSize : options .MaxConcurrentDecisionTaskExecutionSize ,
1222+ WorkerActivitiesPerSecond : options .WorkerActivitiesPerSecond ,
1223+ WorkerDecisionTasksPerSecond : options .WorkerDecisionTasksPerSecond ,
1224+ TaskListActivitiesPerSecond : options .TaskListActivitiesPerSecond ,
1225+ WorkerLocalActivitiesPerSecond : options .WorkerLocalActivitiesPerSecond ,
1226+ StickyScheduleToStartTimeout : options .StickyScheduleToStartTimeout ,
1227+ DataConverter : options .DataConverter ,
1228+ Tracer : options .Tracer ,
1229+ Logger : options .Logger ,
1230+ MetricsScope : options .MetricsScope ,
1231+ Identity : options .Identity ,
1232+ }
1233+
1234+ assertWorkerExecutionParamsEqual (t , expected , decisionWorker .executionParameters )
1235+
1236+ activityWorker , ok := aggWorker .activityWorker .(* activityWorker )
1237+ require .True (t , ok )
1238+ require .True (t , len (activityWorker .executionParameters .ContextPropagators ) > 0 )
1239+ assertWorkerExecutionParamsEqual (t , expected , activityWorker .executionParameters )
1240+ }
1241+
1242+ func assertWorkerExecutionParamsEqual (t * testing.T , paramsA workerExecutionParameters , paramsB workerExecutionParameters ) {
1243+ require .Equal (t , paramsA .TaskList , paramsA .TaskList )
1244+ require .Equal (t , paramsA .Identity , paramsB .Identity )
1245+ require .Equal (t , paramsA .DataConverter , paramsB .DataConverter )
1246+ require .Equal (t , paramsA .Tracer , paramsB .Tracer )
1247+ require .Equal (t , paramsA .ConcurrentLocalActivityExecutionSize , paramsB .ConcurrentLocalActivityExecutionSize )
1248+ require .Equal (t , paramsA .ConcurrentActivityExecutionSize , paramsB .ConcurrentActivityExecutionSize )
1249+ require .Equal (t , paramsA .ConcurrentDecisionTaskExecutionSize , paramsB .ConcurrentDecisionTaskExecutionSize )
1250+ require .Equal (t , paramsA .WorkerActivitiesPerSecond , paramsB .WorkerActivitiesPerSecond )
1251+ require .Equal (t , paramsA .WorkerDecisionTasksPerSecond , paramsB .WorkerDecisionTasksPerSecond )
1252+ require .Equal (t , paramsA .TaskListActivitiesPerSecond , paramsB .TaskListActivitiesPerSecond )
1253+ require .Equal (t , paramsA .StickyScheduleToStartTimeout , paramsB .StickyScheduleToStartTimeout )
1254+ require .Equal (t , paramsA .MaxConcurrentDecisionPollers , paramsB .MaxConcurrentDecisionPollers )
1255+ require .Equal (t , paramsA .MaxConcurrentActivityPollers , paramsB .MaxConcurrentActivityPollers )
1256+ require .Equal (t , paramsA .NonDeterministicWorkflowPolicy , paramsB .NonDeterministicWorkflowPolicy )
1257+ require .Equal (t , paramsA .EnableLoggingInReplay , paramsB .EnableLoggingInReplay )
1258+ require .Equal (t , paramsA .DisableStickyExecution , paramsB .DisableStickyExecution )
1259+ }
1260+
11361261/*
11371262var testWorkflowID1 = s.WorkflowExecution{WorkflowId: common.StringPtr("testWID"), RunId: common.StringPtr("runID")}
11381263var testWorkflowID2 = s.WorkflowExecution{WorkflowId: common.StringPtr("testWID2"), RunId: common.StringPtr("runID2")}
0 commit comments