The slowest test packages spent their time waiting rather than testing. db.Params gains an optional PasswordCost (zero means bcrypt.DefaultCost), and the db, ircserver and handlers tests hash at bcrypt.MinCost. A test IRC server's relay checks its queue on broker notification instead of polling. The service and handlers tests build config.Config directly and run in parallel; config exports DefaultTrustedProxies and ParseTrustedProxies for them. Fixed sleeps give way to waits for the event. Production defaults are unchanged. What still takes time is CPU work under -race or a timeout a test is about. Model: opus-5-5
This commit was merged in pull request #267.
This commit is contained in:
1 parent
847f5c6fec
commit
ed5125606a
15 files changed
+558
-261
No files matched your search
@@ -14,16 +14,16 @@ import (
|
||||
)
|
||||
|
||||
// NewTestServer creates a Server suitable for testing, whose
|
||||
// connections use interval and deadline in place of
|
||||
// pingInterval and pongDeadline, and resolve in place of
|
||||
// resolveHost.
|
||||
// connections use interval, deadline and poll in place of
|
||||
// pingInterval, pongDeadline and pollInterval, and resolve in
|
||||
// place of resolveHost.
|
||||
// The caller must call Stop() when finished.
|
||||
func NewTestServer(
|
||||
log *slog.Logger,
|
||||
cfg *config.Config,
|
||||
database *db.Database,
|
||||
brk *broker.Broker,
|
||||
interval, deadline time.Duration,
|
||||
interval, deadline, poll time.Duration,
|
||||
resolve func(ctx context.Context, addr string) string,
|
||||
) *Server {
|
||||
globs := &globals.Globals{
|
||||
@@ -46,10 +46,18 @@ func NewTestServer(
|
||||
|
||||
pingInterval: interval,
|
||||
pongDeadline: deadline,
|
||||
pollInterval: poll,
|
||||
stopTimeout: stopTimeout,
|
||||
resolveHost: resolve,
|
||||
}
|
||||
}
|
||||
|
||||
// SetStopTimeout makes Stop wait at most timeout for the
|
||||
// connections' cleanup.
|
||||
func (s *Server) SetStopTimeout(timeout time.Duration) {
|
||||
s.stopTimeout = timeout
|
||||
}
|
||||
|
||||
// ResolveHost is the reverse DNS lookup that a server made by
|
||||
// New does for each client.
|
||||
func ResolveHost(ctx context.Context, addr string) string {
|
||||
@@ -99,10 +107,6 @@ const PingInterval = pingInterval
|
||||
// for a line before it closes the connection.
|
||||
const PongDeadline = pongDeadline
|
||||
|
||||
// StopTimeout is the longest Stop waits for the connections'
|
||||
// cleanup.
|
||||
const StopTimeout = stopTimeout
|
||||
|
||||
// NewTestConn returns a Conn for nick on tcpConn, without a
|
||||
// server, database or service behind it.
|
||||
func NewTestConn(
|
||||
@@ -111,7 +115,7 @@ func NewTestConn(
|
||||
tcpConn net.Conn,
|
||||
nick string,
|
||||
) *Conn {
|
||||
conn := newConn(tcpConn, log, nil, nil, cfg, nil)
|
||||
conn := newConn(tcpConn, log, nil, nil, cfg, nil, pollInterval)
|
||||
conn.nick = nick
|
||||
|
||||
return conn
|
||||
|
||||
Reference in new issue
Block a user