check / check (push) Waiting to run
Stopping the server returned before the IRC listener's connections had run their cleanup, and the database closed under them, so their sessions, clients and channel memberships stayed and their nicks stayed taken after a restart. The IRC listener's stop now waits up to five seconds for every connection's cleanup, which now runs on a context that stopping does not cancel. The HTTP server's stop hook now runs Shutdown itself and waits for it; httpServer is set before serving starts, and the server's own signal watcher, which raced fx's stop hooks, is gone. Model: opus-5-5
45 lines
972 B
Go
45 lines
972 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"sneak.berlin/go/neoirc/internal/config"
|
|
)
|
|
|
|
// NewTestSPAServer creates a Server whose router serves only
|
|
// the embedded web client.
|
|
func NewTestSPAServer() *Server {
|
|
srv := &Server{router: chi.NewRouter()}
|
|
srv.setupSPA()
|
|
|
|
return srv
|
|
}
|
|
|
|
// NewTestHTTPServer creates a Server whose router serves
|
|
// handler at / and whose HTTP server listens on port once
|
|
// Start is called.
|
|
func NewTestHTTPServer(port int, handler http.HandlerFunc) *Server {
|
|
router := chi.NewRouter()
|
|
router.Get("/", handler)
|
|
|
|
return &Server{
|
|
log: slog.New(slog.DiscardHandler),
|
|
router: router,
|
|
params: Params{Config: &config.Config{Port: port}},
|
|
}
|
|
}
|
|
|
|
// Start starts the HTTP server, as the start hook does once
|
|
// the router is built.
|
|
func (srv *Server) Start() {
|
|
srv.startHTTP()
|
|
}
|
|
|
|
// Stop does what the stop hook does.
|
|
func (srv *Server) Stop(ctx context.Context) {
|
|
srv.cleanShutdown(ctx)
|
|
}
|