422 Unprocessable Entity means a well-formed request with invalid
semantics, which does not fit a cancelled request. The request
context is also cancelled on server shutdown, where 503 Service
Unavailable is the conventional response.
Signed-off-by: Solomon Jacobs <solomonjacobs@protonmail.com>
Use testing/synctest for deterministic scheduling.
Move all require.* assertions into the test goroutine, since
require.FailNow must not be called from other goroutines.
Use t.Context() and http.MethodPost, and deduplicate the handler
goroutine into a serveReload helper.
Signed-off-by: Solomon Jacobs <solomonjacobs@protonmail.com>
Fix three bugs in the reload handler identified in #5103:
1. Use a buffered error channel (size 1) so the reloader goroutine
never blocks if the HTTP client disconnects before reading the
result.
2. Remove the incorrect `defer close(errc)` — the handler is the
receiver, not the sender; closing from the receiver side could
panic the sender.
3. Wrap both the enqueue (send to reloadCh) and the reply (receive
from errc) in select statements that also listen on
req.Context().Done(), so a client disconnect unblocks the handler
at either stage.
Fixes#5103
Signed-off-by: June Kim <kimjune01@gmail.com>
Signed-off-by: Solomon Jacobs <solomonjacobs@protonmail.com>
In the future, we want to remove the ui build artifacts from the
repository. This will break the usages of
```sh
go get github.com/prometheus/alertmanager/ui
```
That is exactly as expected, since the ui can't function correctly
without the ui artefacts.
This change attempts to make the transition a bit less painful.
Signed-off-by: Solomon Jacobs <solomonjacobs@protonmail.com>