示例#1
0
func TestOnChildStarted(t *testing.T) {
	decider := func(ctx *FSMContext, h *swf.HistoryEvent, data interface{}) Outcome {
		return ctx.Goto("some-state", data, ctx.EmptyDecisions())
	}

	composedDecider := OnChildStarted(decider)

	for _, et := range s.SWFHistoryEventTypes() {
		ctx := deciderTestContext()
		switch et {
		case enums.EventTypeChildWorkflowExecutionStarted:
			event := s.EventFromPayload(129, &swf.ChildWorkflowExecutionStartedEventAttributes{})
			data := new(TestData)
			outcome := composedDecider(ctx, event, data)
			expected := decider(ctx, event, data)
			if !reflect.DeepEqual(outcome, expected) {
				t.Fatal("Outcomes not equal", outcome, expected)
			}
		default:
			event := &swf.HistoryEvent{
				EventType: s.S(et),
			}
			if composedDecider(ctx, event, new(TestData)).State != "" {
				t.Fatal("Non nil decision")
			}
		}
	}
}
示例#2
0
func testContextWithActivity(scheduledEventId int, event *swf.ActivityTaskScheduledEventAttributes) func() *FSMContext {
	return func() *FSMContext {
		correlator := &EventCorrelator{}
		correlator.Serializer = JSONStateSerializer{}
		correlator.Track(s.EventFromPayload(scheduledEventId, event))
		ctx := deciderTestContext()
		ctx.eventCorrelator = correlator
		return ctx
	}
}
示例#3
0
func TestFSMWhenInPreprocStateAndPreprocSuccessfullyCompletesExpectsWorkflowComplete(t *testing.T) {
	// arrange
	simulationStateManager := &simulationStateManager{}
	simulationStateManager.FSM = simulationStateManager.setupFSM()

	serializedState := &fsm.SerializedState{}
	serializedState.StateName = "preproc"
	serializedState.StateData = simulationStateManager.FSM.Serialize(testData)
	serializedState.StateVersion = 1

	markerRecordedEvent := sugar.EventFromPayload(5, &swf.MarkerRecordedEventAttributes{
		MarkerName: sugar.S(fsm.StateMarker),
		Details:    sugar.S(simulationStateManager.FSM.Serialize(serializedState)),
	})

	preprocResult := `{"CustomerId":1,"SimulationResultId":172,"S3SimulationFolder":"Customer_1/simulation172_2016-01-22","FileLocation":"Customer_1/simulation172_2016-01-22/b308147a-a73c-493f-bf10-478219419057_scanpattern.zip","ZoxFileLocation":"Customer_1/simulation172_2016-01-22/035c0f01-d53a-4b36-bbaa-21650a0e2a64_voxel.zip","CoarseZoxFileLocation":"Customer_1/simulation172_2016-01-22/035c0f01-d53a-4b36-bbaa-21650a0e2a64_voxel.zip","MediumZoxFileLocation":"Customer_1/simulation172_2016-01-22/035c0f01-d53a-4b36-bbaa-21650a0e2a64_voxel.zip","FineZoxFileLocation":"Customer_1/simulation172_2016-01-22/035c0f01-d53a-4b36-bbaa-21650a0e2a64_voxel.zip","sizeX":0.001,"sizeY":0.001,"sizeZ":0.001}`
	events := []*swf.HistoryEvent{
		&swf.HistoryEvent{EventType: sugar.S("DecisionTaskStarted"), EventId: sugar.I(9)},
		&swf.HistoryEvent{EventType: sugar.S("DecisionTaskScheduled"), EventId: sugar.I(8)},
		sugar.EventFromPayload(7, &swf.ActivityTaskCompletedEventAttributes{
			ScheduledEventId: sugar.I(6),
			Result:           sugar.S(preprocResult),
		}),
		sugar.EventFromPayload(6, &swf.ActivityTaskScheduledEventAttributes{
			ActivityId:   sugar.S(testActivityInfo.ActivityId),
			ActivityType: testActivityInfo.ActivityType,
		}),
		markerRecordedEvent,
	}
	first := testDecisionTask(5, events)

	// act
	_, decisions, _, err := simulationStateManager.Tick(first)

	// assert
	assert.Nil(t, err, "Should be no errors")
	assert.NotNil(t, decisions, "Should have returned some decisions")
	assert.True(t, Find(decisions, workflowCompletedPredicate), "Should have completed the workflow")
	workflowCopmletedDecision := FindDecision(decisions, workflowCompletedPredicate)
	assert.Equal(t, preprocResult, *workflowCopmletedDecision.CompleteWorkflowExecutionDecisionAttributes.Result, "Should have passed the result from preproc onto next decision")
}
示例#4
0
func TestFSMWhenInPreprocStateAndPreprocFailsExpectsWorkflowFailed(t *testing.T) {
	// arrange
	simulationStateManager := &simulationStateManager{}
	simulationStateManager.FSM = simulationStateManager.setupFSM()

	serializedState := &fsm.SerializedState{}
	serializedState.StateName = "preproc"
	serializedState.StateData = simulationStateManager.FSM.Serialize(testData)
	serializedState.StateVersion = 1

	markerRecordedEvent := sugar.EventFromPayload(5, &swf.MarkerRecordedEventAttributes{
		MarkerName: sugar.S(fsm.StateMarker),
		Details:    sugar.S(simulationStateManager.FSM.Serialize(serializedState)),
	})

	events := []*swf.HistoryEvent{
		&swf.HistoryEvent{EventType: sugar.S("DecisionTaskStarted"), EventId: sugar.I(9)},
		&swf.HistoryEvent{EventType: sugar.S("DecisionTaskScheduled"), EventId: sugar.I(8)},
		sugar.EventFromPayload(7, &swf.ActivityTaskFailedEventAttributes{
			ScheduledEventId: sugar.I(6),
		}),
		sugar.EventFromPayload(6, &swf.ActivityTaskScheduledEventAttributes{
			ActivityId:   sugar.S(testActivityInfo.ActivityId),
			ActivityType: testActivityInfo.ActivityType,
		}),
		markerRecordedEvent,
	}
	first := testDecisionTask(5, events)

	// act
	_, decisions, _, err := simulationStateManager.Tick(first)

	// assert
	assert.Nil(t, err, "Should be no errors")
	assert.NotNil(t, decisions, "Should have returned some decisions")
	assert.True(t, Find(decisions, workflowCancelledPredicate), "Should have failed the workflow because preproc failed")
}
示例#5
0
func TestFSMWhenStartingNewWorkflowExpectsPreprocScheduled(t *testing.T) {
	// arrange
	// {"CustomerId": 1, "SimulationResultId": 172, "S3SimulationFolder": "Customer_1/simulation172_2016-01-22"}

	simulationStateManager := &simulationStateManager{}
	simulationStateManager.FSM = simulationStateManager.setupFSM()
	events := []*swf.HistoryEvent{
		&swf.HistoryEvent{EventType: sugar.S("DecisionTaskStarted"), EventId: sugar.I(3)},
		&swf.HistoryEvent{EventType: sugar.S("DecisionTaskScheduled"), EventId: sugar.I(2)},
		sugar.EventFromPayload(1, &swf.WorkflowExecutionStartedEventAttributes{
			Input: fsm.StartFSMWorkflowInput(simulationStateManager.FSM, testData),
		}),
	}
	firstDecisionTask := testDecisionTask(0, events)

	// act
	_, decisions, _, err := simulationStateManager.Tick(firstDecisionTask)

	// assert
	assert.Nil(t, err, "Should be no errors")
	assert.NotNil(t, decisions, "Should have returned some decisions")
	assert.True(t, Find(decisions, scheduleActivityPredicateFunc("preproc")), "Should have scheduled preproc")
}