1 Commits
Author SHA1 Message Date
sneak 6c555958d6 Stop the slow test packages waiting (closes #263)
check / check (push) Failing after 3s
- Tests hash passwords at bcrypt.MinCost, set through the
  PasswordCost field of db.Params. TestPasswordCost checks the
  cost with and without it.
- Test IRC servers check the queue only on broker notification;
  one test keeps the 100 ms fallback poll.
- The stop-timeout test shortens the timeout through a test-only
  setter.
- service and handlers tests build config.Config directly instead
  of through config.New, so they run in parallel. config exports
  DefaultTrustedProxies and ParseTrustedProxies for the handlers
  test config.
- Repeated race trials run as parallel subtests.
- Fixed sleeps become waits on the broker.
- A new test covers the relay's failed queue read, which only the
  100 ms poll had reached.

Model: opus-5-5
2026-11-10 22:12:13 +00:00
2 changed files with 27 additions and 71 deletions

No files matched your search

+27 -67
View File
@@ -145,19 +145,9 @@ type testServer struct {
handlers *handlers.Handlers handlers *handlers.Handlers
} }
const ( // maxMessageSize is MAX_MESSAGE_SIZE on every test server, the
// maxMessageSize is MAX_MESSAGE_SIZE on every test server, the // setting's default.
// setting's default. const maxMessageSize = 4096
maxMessageSize = 4096
// loginRateLimit is LOGIN_RATE_LIMIT on every test server, the
// setting's default.
loginRateLimit = 1
// loginRateBurst is LOGIN_RATE_BURST on every test server, the
// setting's default.
loginRateBurst = 5
)
func newTestServer( func newTestServer(
t *testing.T, t *testing.T,
@@ -198,7 +188,7 @@ func newTestServerWith(
logger.New, logger.New,
// Built here rather than by config.New, which writes // Built here rather than by config.New, which writes
// the global viper instance, so servers start in // the global viper instance, so servers start in
// parallel. // parallel. Settings left out take their defaults.
func() *config.Config { func() *config.Config {
return &config.Config{ return &config.Config{
DBURL: dbURL, DBURL: dbURL,
@@ -211,8 +201,6 @@ func newTestServerWith(
MessageMaxAge: thirtyDays, MessageMaxAge: thirtyDays,
QueueMaxAge: thirtyDays, QueueMaxAge: thirtyDays,
SessionIdleTimeout: thirtyDays, SessionIdleTimeout: thirtyDays,
LoginRateLimit: loginRateLimit,
LoginRateBurst: loginRateBurst,
TrustedProxies: trusted, TrustedProxies: trusted,
} }
}, },
@@ -3041,18 +3029,18 @@ func TestGetMessagesRemovesWaitChannel(t *testing.T) {
longTimeout = 10 longTimeout = 10
// shortTimeout, in seconds, is the timeout of the // shortTimeout, in seconds, is the timeout of the
// request that waits it out. // requests that wait it out.
shortTimeout = 1 shortTimeout = 1
) )
// queued is whether a message is queued before the request, // queued is whether a message is queued before the request,
// whose timeout is in seconds. failingRead and notified are // whose timeout is in seconds. failingRead is as for
// as for getMessagesFailingRead. wantReads is how many times // getMessagesFailingRead. wantReads is how many times the
// the handler reads the queue: once if it answers at once, // handler reads the queue: once if it answers at once,
// twice if it waits first. // twice if it waits first.
tests := []struct { tests := []struct {
name string name string
queued, notified bool queued bool
timeout, failingRead int timeout, failingRead int
wantReads, wantStatus int wantReads, wantStatus int
}{ }{
@@ -3073,9 +3061,9 @@ func TestGetMessagesRemovesWaitChannel(t *testing.T) {
wantReads: 1, wantStatus: http.StatusInternalServerError, wantReads: 1, wantStatus: http.StatusInternalServerError,
}, },
{ {
name: "read after the wait failed", notified: true, name: "read after the wait failed", timeout: shortTimeout,
timeout: handlers.MaxLongPollTimeout, failingRead: 2, failingRead: 2, wantReads: 2,
wantReads: 2, wantStatus: http.StatusInternalServerError, wantStatus: http.StatusInternalServerError,
}, },
} }
@@ -3107,7 +3095,7 @@ func TestGetMessagesRemovesWaitChannel(t *testing.T) {
} }
status, reads := tserver.getMessagesFailingRead( status, reads := tserver.getMessagesFailingRead(
token, sessionID, lastID, tc.timeout, tc.failingRead, tc.notified, token, lastID, tc.timeout, tc.failingRead,
) )
if status != tc.wantStatus { if status != tc.wantStatus {
t.Errorf("status %d, want %d", status, tc.wantStatus) t.Errorf("status %d, want %d", status, tc.wantStatus)
@@ -3124,17 +3112,14 @@ func TestGetMessagesRemovesWaitChannel(t *testing.T) {
} }
// getMessagesFailingRead sends GET /api/v1/messages for the // getMessagesFailingRead sends GET /api/v1/messages for the
// client token of the session sessionID, with timeout and // client token with timeout and after afterID. The handler's
// after afterID. The handler's read of the queue numbered // read of the queue numbered failingRead, counting from 1,
// failingRead, counting from 1, fails; with 0, none does. // fails; with 0, none does. It returns the response status
// With notified, it notifies the broker once the request // and how many times the handler read the queue.
// waits. It returns the response status and how many times
// the handler read the queue.
func (tserver *testServer) getMessagesFailingRead( func (tserver *testServer) getMessagesFailingRead(
token string, token string,
sessionID, afterID int64, afterID int64,
timeout, failingRead int, timeout, failingRead int,
notified bool,
) (int, int) { ) (int, int) {
tserver.t.Helper() tserver.t.Helper()
@@ -3156,45 +3141,20 @@ func (tserver *testServer) getMessagesFailingRead(
) )
}) })
var ( resp, err := doRequestAuth(
status int tserver.t, http.MethodGet,
err error tserver.url(fmt.Sprintf(
"%s?timeout=%d&after=%d", apiMessages, timeout, afterID,
)),
token, nil,
) )
answered := make(chan struct{})
go func() {
defer close(answered)
var resp *http.Response
resp, err = doRequestAuth(
tserver.t, http.MethodGet,
tserver.url(fmt.Sprintf(
"%s?timeout=%d&after=%d", apiMessages, timeout, afterID,
)),
token, nil,
)
if err != nil {
return
}
status = resp.StatusCode
_ = resp.Body.Close()
}()
if notified {
tserver.waitForLongPoll(sessionID)
tserver.broker.Notify(sessionID)
}
<-answered
if err != nil { if err != nil {
tserver.t.Fatalf("get messages: %v", err) tserver.t.Fatalf("get messages: %v", err)
} }
return status, reads _ = resp.Body.Close()
return resp.StatusCode, reads
} }
// TestLongPollRemovesWaitChannelWhenClientGivesUp checks that // TestLongPollRemovesWaitChannelWhenClientGivesUp checks that
-4
View File
@@ -6,10 +6,6 @@ import (
"sneak.berlin/go/neoirc/internal/db" "sneak.berlin/go/neoirc/internal/db"
) )
// MaxLongPollTimeout is the longest HandleGetMessages waits, in
// seconds.
const MaxLongPollTimeout = maxLongPollTimeout
// SetPollMessages makes HandleGetMessages read the client // SetPollMessages makes HandleGetMessages read the client
// output queue with poll in place of Database.PollMessages. // output queue with poll in place of Database.PollMessages.
func (hdlr *Handlers) SetPollMessages( func (hdlr *Handlers) SetPollMessages(