mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-04-25 19:58:34 -05:00
ffbeafc204
* re-add new testing harness * add healthcheck port and pick random grpc port to listen on * feat: parallel load tests and faster tests * make parallelism = 5 * fix: lint * add linter to pre * fix: add back rampup fixes * reduce matrix on PR, add matrix to pre-release step * make load tests less likely to block * make limit strategy group round robin * uncomment lines
92 lines
2.0 KiB
Go
92 lines
2.0 KiB
Go
//go:build !e2e && !load && !rampup && !integration
|
|
|
|
package dagutils_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hatchet-dev/hatchet/internal/dagutils"
|
|
"github.com/hatchet-dev/hatchet/pkg/repository"
|
|
)
|
|
|
|
func TestOrderWorkflowSteps(t *testing.T) {
|
|
t.Run("valid ordering", func(t *testing.T) {
|
|
steps := []repository.CreateWorkflowStepOpts{
|
|
{
|
|
ReadableId: "step1",
|
|
Action: "action1",
|
|
Parents: []string{},
|
|
},
|
|
{
|
|
ReadableId: "step2",
|
|
Action: "action2",
|
|
Parents: []string{"step1"},
|
|
},
|
|
{
|
|
ReadableId: "step3",
|
|
Action: "action3",
|
|
Parents: []string{"step2"},
|
|
},
|
|
}
|
|
|
|
ordered, err := dagutils.OrderWorkflowSteps(steps)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
// Validate that each step appears after its parents.
|
|
orderIndex := make(map[string]int)
|
|
for i, step := range ordered {
|
|
orderIndex[step.ReadableId] = i
|
|
}
|
|
|
|
for _, step := range steps {
|
|
for _, parent := range step.Parents {
|
|
if orderIndex[parent] > orderIndex[step.ReadableId] {
|
|
t.Errorf("step %q appears before its parent %q", step.ReadableId, parent)
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("unknown parent", func(t *testing.T) {
|
|
steps := []repository.CreateWorkflowStepOpts{
|
|
{
|
|
ReadableId: "step1",
|
|
Action: "action1",
|
|
Parents: []string{"nonexistent"},
|
|
},
|
|
}
|
|
|
|
_, err := dagutils.OrderWorkflowSteps(steps)
|
|
if err == nil {
|
|
t.Fatal("expected error for unknown parent, got nil")
|
|
}
|
|
})
|
|
|
|
t.Run("cycle detection", func(t *testing.T) {
|
|
steps := []repository.CreateWorkflowStepOpts{
|
|
{
|
|
ReadableId: "step1",
|
|
Action: "action1",
|
|
Parents: []string{"step3"},
|
|
},
|
|
{
|
|
ReadableId: "step2",
|
|
Action: "action2",
|
|
Parents: []string{"step1"},
|
|
},
|
|
{
|
|
ReadableId: "step3",
|
|
Action: "action3",
|
|
Parents: []string{"step2"},
|
|
},
|
|
}
|
|
|
|
_, err := dagutils.OrderWorkflowSteps(steps)
|
|
if err == nil {
|
|
t.Fatal("expected error for cycle detection, got nil")
|
|
}
|
|
})
|
|
}
|