Two edges of v0.1.3687's gateway.json:
1. The first update from a magpie older than the record found no gateway.json,
asked 3425, said "isn't running" and left a service on MAGPIE_ADDR=0.0.0.0:10100
on the old version. With no record, no MAGPIE_ADDR and no answer at the usual
address, `magpie update` now tries the installed service's MAGPIE_ADDR (read
from its unit or launch agent, daemon.Addr), the port in Settings and 3425,
and takes the first that answers as magpie. --addr and MAGPIE_ADDR stay the
user's word.
2. A restart asked by `magpie update` waited on "N requests" with no end (Windows
hands nothing over, long streams never finish). The app and magpie serve now
wait at most 10 minutes for that ask, then restart; the output says so
("or in 10 min at the latest, which cuts what is still running"). `magpie
update --force` restarts at once (gateway.SetForceRestarter), and says if the
running magpie is too old to know --force. The app's own look at the disk
(followReplaced) and autonomous serve follow still never cut a request.
Run (mote refused SSH; win-run on xiaomi-gpu): go vet cli/gui/gateway/daemon
(windows), linux nogui vet; go test -run TestUpdate|TestServeFollow|
TestTerminalUpdate|TestRestart over cli, gui, gateway, daemon: ok except
TestUpdateThatWontStart, red on origin/main on the same box too (#6059).
Broken by hand: drain bound off, record fallback off, serve bound off: the new
tests TestTerminalUpdateWaitIsBoundedAndCanBeForced, TestUpdateFindsAMagpieThatWroteNoRecord,
TestServeFollowDrainIsBounded go red.
Not tried: a real systemd service upgrade; darwin cross vet (cgo) and the full
suite (started after the tag if mote is back).
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
)
|
|
|
|
// magpie update tells the magpie running what it put in, and says what
|
|
// came of it: a restart, a wait, magpie serve, an older magpie (404), or
|
|
// none running.
|
|
func TestUpdateAsksTheRunningMagpieToRestart(t *testing.T) {
|
|
var reply gateway.RestartReply
|
|
var asked string
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != "POST" || r.URL.Path != gateway.RestartPath {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
b, _ := io.ReadAll(r.Body)
|
|
asked = string(b)
|
|
json.NewEncoder(w).Encode(reply)
|
|
}))
|
|
defer ts.Close()
|
|
for _, c := range []struct {
|
|
reply gateway.RestartReply
|
|
want string
|
|
}{
|
|
{gateway.RestartReply{State: "restarting", Version: "v0.1.1", Handover: true}, "restarts into v0.1.2 now, handing its gateway over"},
|
|
{gateway.RestartReply{State: "waiting", Version: "v0.1.1", Busy: &gateway.Busy{Requests: 2}}, "once the 2 request(s)"},
|
|
{gateway.RestartReply{State: "unsupported", Version: "v0.1.1"}, "magpie serve"},
|
|
{gateway.RestartReply{State: "current", Version: "v0.1.1"}, "another copy"},
|
|
} {
|
|
reply = c.reply
|
|
if got := restartRunning(ts.URL, "v0.1.2"); !strings.Contains(got, c.want) {
|
|
t.Errorf("%s: %q", c.reply.State, got)
|
|
}
|
|
if asked != `{"version":"v0.1.2","force":false}` {
|
|
t.Errorf("asked %q", asked)
|
|
}
|
|
}
|
|
old := httptest.NewServer(http.NotFoundHandler())
|
|
defer old.Close()
|
|
if got := restartRunning(old.URL, "v0.1.2"); !strings.Contains(got, "quit and reopen") {
|
|
t.Errorf("an older magpie: %q", got)
|
|
}
|
|
old.Close()
|
|
if got := restartRunning(old.URL, "v0.1.2"); !strings.Contains(got, "isn't running") {
|
|
t.Errorf("none running: %q", got)
|
|
}
|
|
}
|