Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c555958d6 |
No files matched your search
@@ -145,19 +145,9 @@ type testServer struct {
|
||||
handlers *handlers.Handlers
|
||||
}
|
||||
|
||||
const (
|
||||
// maxMessageSize is MAX_MESSAGE_SIZE on every test server, the
|
||||
// setting's default.
|
||||
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
|
||||
)
|
||||
// maxMessageSize is MAX_MESSAGE_SIZE on every test server, the
|
||||
// setting's default.
|
||||
const maxMessageSize = 4096
|
||||
|
||||
func newTestServer(
|
||||
t *testing.T,
|
||||
@@ -198,7 +188,7 @@ func newTestServerWith(
|
||||
logger.New,
|
||||
// Built here rather than by config.New, which writes
|
||||
// the global viper instance, so servers start in
|
||||
// parallel.
|
||||
// parallel. Settings left out take their defaults.
|
||||
func() *config.Config {
|
||||
return &config.Config{
|
||||
DBURL: dbURL,
|
||||
@@ -211,8 +201,6 @@ func newTestServerWith(
|
||||
MessageMaxAge: thirtyDays,
|
||||
QueueMaxAge: thirtyDays,
|
||||
SessionIdleTimeout: thirtyDays,
|
||||
LoginRateLimit: loginRateLimit,
|
||||
LoginRateBurst: loginRateBurst,
|
||||
TrustedProxies: trusted,
|
||||
}
|
||||
},
|
||||
@@ -3041,18 +3029,18 @@ func TestGetMessagesRemovesWaitChannel(t *testing.T) {
|
||||
longTimeout = 10
|
||||
|
||||
// shortTimeout, in seconds, is the timeout of the
|
||||
// request that waits it out.
|
||||
// requests that wait it out.
|
||||
shortTimeout = 1
|
||||
)
|
||||
|
||||
// queued is whether a message is queued before the request,
|
||||
// whose timeout is in seconds. failingRead and notified are
|
||||
// as for getMessagesFailingRead. wantReads is how many times
|
||||
// the handler reads the queue: once if it answers at once,
|
||||
// whose timeout is in seconds. failingRead is as for
|
||||
// getMessagesFailingRead. wantReads is how many times the
|
||||
// handler reads the queue: once if it answers at once,
|
||||
// twice if it waits first.
|
||||
tests := []struct {
|
||||
name string
|
||||
queued, notified bool
|
||||
queued bool
|
||||
timeout, failingRead int
|
||||
wantReads, wantStatus int
|
||||
}{
|
||||
@@ -3073,9 +3061,9 @@ func TestGetMessagesRemovesWaitChannel(t *testing.T) {
|
||||
wantReads: 1, wantStatus: http.StatusInternalServerError,
|
||||
},
|
||||
{
|
||||
name: "read after the wait failed", notified: true,
|
||||
timeout: handlers.MaxLongPollTimeout, failingRead: 2,
|
||||
wantReads: 2, wantStatus: http.StatusInternalServerError,
|
||||
name: "read after the wait failed", timeout: shortTimeout,
|
||||
failingRead: 2, wantReads: 2,
|
||||
wantStatus: http.StatusInternalServerError,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3107,7 +3095,7 @@ func TestGetMessagesRemovesWaitChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
status, reads := tserver.getMessagesFailingRead(
|
||||
token, sessionID, lastID, tc.timeout, tc.failingRead, tc.notified,
|
||||
token, lastID, tc.timeout, tc.failingRead,
|
||||
)
|
||||
if 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
|
||||
// client token of the session sessionID, with timeout and
|
||||
// after afterID. The handler's read of the queue numbered
|
||||
// failingRead, counting from 1, fails; with 0, none does.
|
||||
// With notified, it notifies the broker once the request
|
||||
// waits. It returns the response status and how many times
|
||||
// the handler read the queue.
|
||||
// client token with timeout and after afterID. The handler's
|
||||
// read of the queue numbered failingRead, counting from 1,
|
||||
// fails; with 0, none does. It returns the response status
|
||||
// and how many times the handler read the queue.
|
||||
func (tserver *testServer) getMessagesFailingRead(
|
||||
token string,
|
||||
sessionID, afterID int64,
|
||||
afterID int64,
|
||||
timeout, failingRead int,
|
||||
notified bool,
|
||||
) (int, int) {
|
||||
tserver.t.Helper()
|
||||
|
||||
@@ -3156,45 +3141,20 @@ func (tserver *testServer) getMessagesFailingRead(
|
||||
)
|
||||
})
|
||||
|
||||
var (
|
||||
status int
|
||||
err error
|
||||
resp, err := doRequestAuth(
|
||||
tserver.t, http.MethodGet,
|
||||
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 {
|
||||
tserver.t.Fatalf("get messages: %v", err)
|
||||
}
|
||||
|
||||
return status, reads
|
||||
_ = resp.Body.Close()
|
||||
|
||||
return resp.StatusCode, reads
|
||||
}
|
||||
|
||||
// TestLongPollRemovesWaitChannelWhenClientGivesUp checks that
|
||||
|
||||
@@ -6,10 +6,6 @@ import (
|
||||
"sneak.berlin/go/neoirc/internal/db"
|
||||
)
|
||||
|
||||
// MaxLongPollTimeout is the longest HandleGetMessages waits, in
|
||||
// seconds.
|
||||
const MaxLongPollTimeout = maxLongPollTimeout
|
||||
|
||||
// SetPollMessages makes HandleGetMessages read the client
|
||||
// output queue with poll in place of Database.PollMessages.
|
||||
func (hdlr *Handlers) SetPollMessages(
|
||||
|
||||
Reference in new issue
Block a user