Ejemplo n.º 1
0
func TestOnSignalReceived(t *testing.T) {
	signal := "the-signal"
	ctx := deciderTestContext()
	decider := Transition("some-state")
	composedDecider := OnSignalReceived(signal, decider)

	for _, e := range s.SWFHistoryEventTypes() {
		switch e {
		case swf.EventTypeWorkflowExecutionSignaled:
			event := &swf.HistoryEvent{
				EventType: s.S(e),
				EventId:   s.L(129),
				WorkflowExecutionSignaledEventAttributes: &swf.WorkflowExecutionSignaledEventAttributes{
					SignalName: s.S("the-signal"),
				},
			}
			data := &TestingType{Field: "yes"}
			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(e),
			}
			outcome := composedDecider(ctx, event, nil)
			if !reflect.DeepEqual(outcome, ctx.Pass()) {
				t.Fatal("Outcome does not equal Pass", outcome)
			}
		}
	}
}
Ejemplo n.º 2
0
func TestOnData(t *testing.T) {
	decider := Transition("some-state")
	typed := Typed(new(TestingType))
	data := &TestingType{Field: "yes"}
	ctx := deciderTestContext()

	predicate := typed.PredicateFunc(func(data *TestingType) bool {
		return data.Field == "yes"
	})

	composedDecider := OnData(predicate, decider)

	event := &swf.HistoryEvent{
		EventId:        s.L(129),
		EventTimestamp: aws.Time(time.Now()),
		EventType:      s.S(swf.EventTypeWorkflowExecutionStarted),
	}

	outcome := composedDecider(ctx, event, data)
	expected := decider(ctx, event, data)

	if !reflect.DeepEqual(outcome, expected) {
		t.Fatal("Outcomes not equal", outcome, expected)
	}

	data.Field = "nope"
	outcome = composedDecider(ctx, event, data)

	if reflect.DeepEqual(outcome, expected) {
		t.Fatal("Outcomes should not be equal", outcome, expected)
	}
}
Ejemplo n.º 3
0
func testDecisionTask(prevStarted int, events []*swf.HistoryEvent) *swf.PollForDecisionTaskOutput {
	d := &swf.PollForDecisionTaskOutput{
		Events:                 events,
		PreviousStartedEventId: sugar.I(prevStarted),
		StartedEventId:         sugar.I(prevStarted + len(events)),
		WorkflowExecution:      testWorkflowExecution,
		WorkflowType:           testWorkflowType,
	}
	for i, e := range d.Events {
		if e.EventId == nil {
			e.EventId = sugar.L(*d.StartedEventId - int64(i))
		}
		e.EventTimestamp = aws.Time(time.Unix(0, 0))
		d.Events[i] = e
	}
	return d
}
Ejemplo n.º 4
0
func TestOnActivityFailedTimedOutCanceled(t *testing.T) {
	activity := "test-activity"
	decider := Transition("some-state")
	composedDecider := OnActivityFailedTimedOutCanceled(activity, decider)

	ctx := testContextWithActivity(123, &swf.ActivityTaskScheduledEventAttributes{
		ActivityId: s.S("the-id"),
		ActivityType: &swf.ActivityType{
			Name:    s.S(activity),
			Version: s.S("1"),
		},
	},
	)

	for _, e := range s.SWFHistoryEventTypes() {
		switch e {
		case swf.EventTypeActivityTaskFailed, swf.EventTypeActivityTaskTimedOut, swf.EventTypeActivityTaskCanceled:
			event := &swf.HistoryEvent{
				EventType: s.S(e),
				EventId:   s.L(129),
				ActivityTaskCanceledEventAttributes: &swf.ActivityTaskCanceledEventAttributes{ScheduledEventId: s.L(123)},
				ActivityTaskFailedEventAttributes:   &swf.ActivityTaskFailedEventAttributes{ScheduledEventId: s.L(123)},
				ActivityTaskTimedOutEventAttributes: &swf.ActivityTaskTimedOutEventAttributes{ScheduledEventId: s.L(123)},
			}
			data := &TestingType{Field: "yes"}
			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(e),
			}
			outcome := composedDecider(ctx(), event, nil)
			if !reflect.DeepEqual(outcome, ctx().Pass()) {
				t.Fatal("Outcome does not equal Pass", outcome)
			}
		}
	}
}