35 lines
1.3 KiB
Go
35 lines
1.3 KiB
Go
package mysql
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestPairPhaseLatenciesSortsEventsAndUsesFirstValidTarget(t *testing.T) {
|
|
base := time.Date(2026, 9, 19, 0, 0, 0, 0, time.UTC)
|
|
got := pairPhaseLatencies(map[string][]phaseEvent{
|
|
"task-a": {
|
|
{kind: "task", id: "terminal", typeName: "task.succeeded", at: base.Add(4 * time.Second)},
|
|
{kind: "task", id: "start", typeName: "task.started", at: base.Add(2 * time.Second)},
|
|
{kind: "task", id: "accepted", typeName: "task.accepted", at: base},
|
|
{kind: "task", id: "later-terminal", typeName: "task.failed", at: base.Add(5 * time.Second)},
|
|
},
|
|
}, "task.accepted", "task.succeeded", "task.failed")
|
|
if got.average != 4 || got.maximum != 4 {
|
|
t.Fatalf("phase latency=%+v, want first valid terminal at four seconds", got)
|
|
}
|
|
}
|
|
|
|
func TestPairPhaseLatenciesRejectsTargetBeforeStart(t *testing.T) {
|
|
base := time.Date(2026, 9, 19, 0, 0, 0, 0, time.UTC)
|
|
got := pairPhaseLatencies(map[string][]phaseEvent{
|
|
"workflow-a": {
|
|
{kind: "workflow", id: "stop", typeName: "workflow.stopped", at: base},
|
|
{kind: "workflow", id: "start", typeName: "workflow.started", at: base.Add(time.Second)},
|
|
},
|
|
}, "workflow.started", "workflow.stopped")
|
|
if got.average != 0 || got.maximum != 0 {
|
|
t.Fatalf("invalid phase pair produced latency=%+v", got)
|
|
}
|
|
}
|