Some checks failed
check / check (push) Failing after 16s
db: TestSetSessionUserModesIsAtomic installs a trigger that rejects the is_oper UPDATE after the is_wallops UPDATE has run, proving the '+w-o' partial-failure the old independent-UPDATE loop exhibited is gone. ircserver: TestDisconnectDoesNotBlockOnUnresponsiveVictim drives Disconnect against a net.Pipe victim that never reads and requires the call to return promptly; verified to fail against the synchronous implementation. Its counterpart asserts the notification is still delivered and the socket still closed.
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package ircserver
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"net"
|
|
"time"
|
|
|
|
"sneak.berlin/go/neoirc/internal/broker"
|
|
"sneak.berlin/go/neoirc/internal/config"
|
|
"sneak.berlin/go/neoirc/internal/db"
|
|
"sneak.berlin/go/neoirc/internal/globals"
|
|
"sneak.berlin/go/neoirc/internal/service"
|
|
)
|
|
|
|
// NewTestServer creates a Server suitable for testing.
|
|
// The caller must call Stop() when finished.
|
|
func NewTestServer(
|
|
log *slog.Logger,
|
|
cfg *config.Config,
|
|
database *db.Database,
|
|
brk *broker.Broker,
|
|
) *Server {
|
|
globs := &globals.Globals{
|
|
Appname: "neoirc",
|
|
Version: "test",
|
|
StartTime: time.Now(),
|
|
}
|
|
|
|
svc := service.NewTestService(
|
|
database, brk, cfg, globs, log,
|
|
)
|
|
|
|
return &Server{ //nolint:exhaustruct
|
|
log: log,
|
|
cfg: cfg,
|
|
database: database,
|
|
brk: brk,
|
|
svc: svc,
|
|
conns: make(map[*Conn]struct{}),
|
|
}
|
|
}
|
|
|
|
// Start exposes the unexported start method for tests.
|
|
func (s *Server) Start(addr string) error {
|
|
return s.start(context.Background(), addr)
|
|
}
|
|
|
|
// Stop exposes the unexported stop method for tests.
|
|
func (s *Server) Stop() {
|
|
s.stop()
|
|
}
|
|
|
|
// Listener returns the server's net.Listener for tests.
|
|
func (s *Server) Listener() net.Listener {
|
|
return s.listener
|
|
}
|
|
|
|
// NewTestConn wraps an already-established net.Conn in a
|
|
// Conn so tests can drive connection-level behaviour such
|
|
// as Disconnect without standing up a whole server.
|
|
func NewTestConn(
|
|
log *slog.Logger,
|
|
cfg *config.Config,
|
|
tcpConn net.Conn,
|
|
nick string,
|
|
) *Conn {
|
|
conn := newConn(
|
|
context.Background(), tcpConn, log,
|
|
nil, nil, cfg, nil,
|
|
)
|
|
conn.nick = nick
|
|
|
|
return conn
|
|
}
|