carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package rollout
2
3import (
4 "fmt"
5 "strings"
6 "testing"
7
8 "github.com/carlosframework/platform/internal/activator"
9 "github.com/carlosframework/platform/internal/rolloutwords"
10)
11
12// Astra plan 6 R1 #8: the swapping event is emitted for every attempt, a
13// hold-mode swap and a socketless worker's stop-then-start replacement as
14// much as an overlap swap, so its words must not say the new build starts
15// beside the running one. Driven through the real emit sites (scheduler
16// execute, executeWorker).
17func TestTheSwappingEventIsModeNeutral(t *testing.T) {
18 for name, h := range map[string]*harness{
19 "hold swap": func() *harness { h := newHarness(t, "a"); h.swap = "hold"; return h }(),
20 "worker replacement": workerHarness(t, "a"),
21 } {
22 h.stage("v2")
23 h.install("v2", "a")
24 h.pass()
25 want := "a: " + fmt.Sprintf(rolloutwords.EventSwapping, "v2", rolloutwords.Cause("release"))
26 waitFor(t, name+": the swapping event", func() bool { return h.events.has(want) })
27 waitFor(t, name+": the attempt", func() bool {
28 calls, _, _ := h.act.snapshot()
29 return len(calls)+len(h.act.replacements()) == 1
30 })
31 calls, _, _ := h.act.snapshot()
32 switch {
33 case name == "hold swap" && (len(calls) != 1 || calls[0].a.Mode != activator.ModeHold):
34 t.Fatalf("%s: swaps %+v, want one in hold mode", name, calls)
35 case name == "worker replacement" && (len(calls) != 0 || len(h.act.replacements()) != 1):
36 t.Fatalf("%s: %d swaps, %d replacements, want one replacement", name, len(calls), len(h.act.replacements()))
37 }
38 h.events.mu.Lock()
39 for _, l := range h.events.lines {
40 if strings.Contains(l, "beside") {
41 t.Errorf("%s: %q says the new build runs beside the old one", name, l)
42 }
43 }
44 h.events.mu.Unlock()
45 }
46}
47