| index 5c25ee7f..05db4bf9 100644 |
| --- a/internal/release/upgrade_test.go |
| +++ b/internal/release/upgrade_test.go |
| @@ -24,6 +24,8 @@ type upgradeRig struct { |
| root, home, runner string |
| script, log string |
| serviceEnv, unit string |
| + // env is added to every run's environment. |
| + env []string |
| } |
| |
| func newUpgradeRig(t *testing.T) *upgradeRig { |
| @@ -70,7 +72,7 @@ func newUpgradeRig(t *testing.T) *upgradeRig { |
| r.write(filepath.Join(bin, "carlos"), "#!/bin/sh\n"+log+`case "$1 $2" in |
| "db "*) [ -e `+filepath.Join(root, "replicabroken")+` ] && { echo "the copy failed its integrity check" >&2; exit 1; } |
| case "$2 $*" in pull*) for a; do case $prev in --out) python3 -c "import sqlite3,sys; c=sqlite3.connect(sys.argv[1]); [c.execute('create table '+t+'(x)') for t in ('teams','chat_tasks','chat_steps','chat_turns','runners')]; c.commit()" "$a" ;; esac; prev=$a; done ;; |
| - *integrity_check*) printf 'integrity_check\nok\n' ;; *) printf 'x\n%s\n' "$(cat `+filepath.Join(root, "inflight")+`)" ;; esac ;; |
| + *integrity_check*) printf 'integrity_check\nok\n' ;; *step_timeout*) printf 'x\n%s\n' "$(cat `+filepath.Join(root, "unfinished")+` 2>/dev/null || echo 0)" ;; *) printf 'x\n%s\n' "$(cat `+filepath.Join(root, "inflight")+`)" ;; esac ;; |
| deploy*) for a; do case $prev in --version) echo "$a" > `+filepath.Join(root, "served")+` ;; esac; prev=$a; done ;; |
| promote*) shift; for a; do last2=$last; last=$a; done; echo "$last2" > `+filepath.Join(root, "served")+` ;; |
| esac |
| @@ -99,6 +101,7 @@ func (r *upgradeRig) read(path string) string { |
| func (r *upgradeRig) run(args ...string) (string, error) { |
| cmd := exec.Command("bash", append([]string{r.script}, args...)...) |
| cmd.Env = []string{"HOME=" + r.home, "PATH=" + filepath.Join(r.root, "bin") + ":/usr/bin:/bin", "UPGRADE_YES=1", "UPGRADE_TRIES=3", "UPGRADE_WAIT=0", "UPGRADE_PROC=" + filepath.Join(r.root, "proc"), "LANG=C.UTF-8"} |
| + cmd.Env = append(cmd.Env, r.env...) |
| out, err := cmd.CombinedOutput() |
| return string(out), err |
| } |
| @@ -418,3 +421,33 @@ func TestUpgradeResumesAfterTheRestart(t *testing.T) { |
| t.Fatalf("rollback retry stopped the previous runner again: %v\n%s\n%s", err, out, r.read(r.log)) |
| } |
| } |
| + |
| +// An older release takes the work of an Engineering step that ran out of |
| +// time (done, step_timeout) for finished work: a rollback refuses while |
| +// an open task holds such work, before it changes anything, unless the |
| +// operator says to go on (UPGRADE_ALLOW_UNFINISHED=1). |
| +func TestUpgradeRollbackRefusesWithUnfinishedWork(t *testing.T) { |
| + r := newUpgradeRig(t) |
| + if out, err := r.run(upgradeTo, "--execute"); err != nil { |
| + t.Fatalf("upgrade: %v\n%s", err, out) |
| + } |
| + exe := filepath.Join(r.root, "proc", "4242", "exe") |
| + r.must(os.Remove(exe)) |
| + r.must(os.Symlink(filepath.Join(r.runner, "releases", upgradeFrom, "equipo-runner"), exe)) |
| + r.write(filepath.Join(r.root, "unfinished"), "2", 0600) |
| + before := r.read(r.log) |
| + out, err := r.run("rollback", "--execute") |
| + if err == nil || !strings.Contains(out, "refused: 2 open task(s) hold unfinished work") || strings.Contains(r.state(), "rolled_back=1") { |
| + t.Fatalf("rollback with unfinished work: %v\n%s", err, out) |
| + } |
| + if changed := strings.TrimPrefix(r.read(r.log), before); strings.Contains(changed, "systemctl") || strings.Contains(changed, "promote") { |
| + t.Fatalf("changed something before refusing:\n%s", changed) |
| + } |
| + if plan, err := r.run("rollback"); err != nil || !strings.Contains(plan, "unfinished work") { |
| + t.Fatalf("the plan does not name the check: %v\n%s", err, plan) |
| + } |
| + r.env = []string{"UPGRADE_ALLOW_UNFINISHED=1"} |
| + if out, err := r.run("rollback", "--execute"); err != nil || !strings.Contains(r.state(), "rolled_back=1") { |
| + t.Fatalf("rollback told to go on: %v\n%s", err, out) |
| + } |
| +} |