Let ircserver and db tests pass under heavy host load (closes #265)
check / check (push) Failing after 3s
check / check (push) Failing after 3s
testTimeout, the limit on every read and wait in the ircserver tests, goes from 5 to 30 seconds. A passing test never reaches it. TestQuietClientNotAnsweringPingIsClosed uses a 3 second ping interval, and measures its upper bound from the end of registration. That leaves 2.7 seconds for scheduling delay before the close a two-interval read deadline would make. The lower bound, from the client's last line, is unchanged. The cancelled-query tests in internal/db run the endless query for 2 seconds instead of 100 ms. A context that ends before the statement starts interrupts nothing, so the pool kept its connection. Model: opus-5-5
This commit is contained in:
1 parent
72d8f2c12b
commit
ebea2abe28
2 files changed
+39
-11
No files matched your search
@@ -30,7 +30,10 @@ import (
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
const testTimeout = 5 * time.Second
|
||||
// testTimeout is how long a test waits for something before it
|
||||
// fails. A passing test never waits this long, so it is generous
|
||||
// enough for a heavily loaded host.
|
||||
const testTimeout = 30 * time.Second
|
||||
|
||||
// testEnv holds the shared test infrastructure.
|
||||
type testEnv struct {
|
||||
@@ -553,27 +556,48 @@ func TestQuietClientAnsweringPingStaysConnected(t *testing.T) {
|
||||
func TestQuietClientNotAnsweringPingIsClosed(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// latest leaves room for a loaded host, but is sooner than
|
||||
// a read deadline of two ping intervals would close it.
|
||||
// A read deadline of two ping intervals would close the
|
||||
// connection at latest. The ping interval is longer than
|
||||
// testPingInterval, so that the time between the expected
|
||||
// close and latest leaves room for a loaded host.
|
||||
const (
|
||||
earliest = testPingInterval + testPongDeadline
|
||||
latest = 2 * testPingInterval
|
||||
interval = 3 * time.Second
|
||||
earliest = interval + testPongDeadline
|
||||
latest = 2 * interval
|
||||
)
|
||||
|
||||
env := newTestEnvWithShortPings(t)
|
||||
env := newTestEnvWithPingTimes(
|
||||
t,
|
||||
&config.Config{ServerName: testServerName},
|
||||
interval, testPongDeadline,
|
||||
)
|
||||
client := env.dial(t)
|
||||
|
||||
lastSent := time.Now()
|
||||
|
||||
client.register("silent")
|
||||
client.readServerPing(lastSent)
|
||||
|
||||
// The server starts both waits once it has handled the
|
||||
// registration, so the time registration took does not
|
||||
// count against latest.
|
||||
registered := time.Now()
|
||||
|
||||
client.readUntil(isServerPing)
|
||||
client.readUntilClosed()
|
||||
|
||||
waited := time.Since(lastSent)
|
||||
if waited < earliest || waited >= latest {
|
||||
if waited < earliest {
|
||||
t.Errorf(
|
||||
"closed %v after the client's last line, want %v to %v",
|
||||
waited, earliest, latest,
|
||||
"closed %v after the client's last line, want at least %v",
|
||||
waited, earliest,
|
||||
)
|
||||
}
|
||||
|
||||
sinceRegistered := time.Since(registered)
|
||||
if sinceRegistered >= latest {
|
||||
t.Errorf(
|
||||
"closed %v after registration, want less than %v",
|
||||
sinceRegistered, latest,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user