package rollout import ( "fmt" "strings" "testing" "github.com/carlosframework/platform/internal/activator" "github.com/carlosframework/platform/internal/rolloutwords" ) // Astra plan 6 R1 #8: the swapping event is emitted for every attempt, a // hold-mode swap and a socketless worker's stop-then-start replacement as // much as an overlap swap, so its words must not say the new build starts // beside the running one. Driven through the real emit sites (scheduler // execute, executeWorker). func TestTheSwappingEventIsModeNeutral(t *testing.T) { for name, h := range map[string]*harness{ "hold swap": func() *harness { h := newHarness(t, "a"); h.swap = "hold"; return h }(), "worker replacement": workerHarness(t, "a"), } { h.stage("v2") h.install("v2", "a") h.pass() want := "a: " + fmt.Sprintf(rolloutwords.EventSwapping, "v2", rolloutwords.Cause("release")) waitFor(t, name+": the swapping event", func() bool { return h.events.has(want) }) waitFor(t, name+": the attempt", func() bool { calls, _, _ := h.act.snapshot() return len(calls)+len(h.act.replacements()) == 1 }) calls, _, _ := h.act.snapshot() switch { case name == "hold swap" && (len(calls) != 1 || calls[0].a.Mode != activator.ModeHold): t.Fatalf("%s: swaps %+v, want one in hold mode", name, calls) case name == "worker replacement" && (len(calls) != 0 || len(h.act.replacements()) != 1): t.Fatalf("%s: %d swaps, %d replacements, want one replacement", name, len(calls), len(h.act.replacements())) } h.events.mu.Lock() for _, l := range h.events.lines { if strings.Contains(l, "beside") { t.Errorf("%s: %q says the new build runs beside the old one", name, l) } } h.events.mu.Unlock() } }