- Tests hash passwords at bcrypt.MinCost through db.PasswordCost. - 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: service had run serially, and handlers started its servers one at a time. - 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
This commit is contained in:
1 parent
bc8aa6bb96
commit
c492e5969e
11 files changed
+356
-198
No files matched your search
@@ -18,6 +18,7 @@ import (
|
||||
"time"
|
||||
|
||||
"go.uber.org/fx/fxtest"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"sneak.berlin/go/neoirc/internal/broker"
|
||||
"sneak.berlin/go/neoirc/internal/config"
|
||||
"sneak.berlin/go/neoirc/internal/db"
|
||||
@@ -32,6 +33,19 @@ import (
|
||||
|
||||
const testTimeout = 5 * time.Second
|
||||
|
||||
// testPollInterval is how often the relay of a test server
|
||||
// checks the client output queue without a broker
|
||||
// notification. It is so long that the relay delivers only on
|
||||
// notification, and a test fails when one is missing.
|
||||
const testPollInterval = time.Hour
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
// A password hashed at full cost takes seconds under -race.
|
||||
db.PasswordCost = bcrypt.MinCost
|
||||
|
||||
m.Run()
|
||||
}
|
||||
|
||||
// testEnv holds the shared test infrastructure.
|
||||
type testEnv struct {
|
||||
dbURL string
|
||||
@@ -91,16 +105,19 @@ func newTestEnvWithPingTimes(
|
||||
t.Helper()
|
||||
|
||||
return newTestEnvWithResolver(
|
||||
t, cfg, interval, deadline, ircserver.ResolveHost,
|
||||
t, cfg, interval, deadline, testPollInterval,
|
||||
ircserver.ResolveHost,
|
||||
)
|
||||
}
|
||||
|
||||
// newTestEnvWithResolver is newTestEnvWithPingTimes, except
|
||||
// that the server looks up a client's hostname with resolve.
|
||||
// that the relay checks the client output queue every poll
|
||||
// without a broker notification, and the server looks up a
|
||||
// client's hostname with resolve.
|
||||
func newTestEnvWithResolver(
|
||||
t *testing.T,
|
||||
cfg *config.Config,
|
||||
interval, deadline time.Duration,
|
||||
interval, deadline, poll time.Duration,
|
||||
resolve func(ctx context.Context, addr string) string,
|
||||
) *testEnv {
|
||||
t.Helper()
|
||||
@@ -134,7 +151,7 @@ func newTestEnvWithResolver(
|
||||
))
|
||||
|
||||
srv := ircserver.NewTestServer(
|
||||
log, cfg, database, brk, interval, deadline, resolve,
|
||||
log, cfg, database, brk, interval, deadline, poll, resolve,
|
||||
)
|
||||
|
||||
// Port 0 makes the system pick a free port. dial reads it
|
||||
@@ -430,7 +447,8 @@ func TestRegistrationWhileAnotherLookupIsPending(t *testing.T) {
|
||||
|
||||
env := newTestEnvWithResolver(
|
||||
t, &config.Config{ServerName: testServerName},
|
||||
ircserver.PingInterval, ircserver.PongDeadline, resolve,
|
||||
ircserver.PingInterval, ircserver.PongDeadline,
|
||||
testPollInterval, resolve,
|
||||
)
|
||||
|
||||
env.dial(t)
|
||||
@@ -1039,12 +1057,16 @@ func TestStopEndsSessions(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestStopReturnsWhileCleanupIsStuck checks that Stop stops
|
||||
// waiting for a connection's cleanup after StopTimeout, so a
|
||||
// cleanup that cannot finish does not hold up stopping.
|
||||
// waiting for a connection's cleanup after its stop timeout,
|
||||
// so a cleanup that cannot finish does not hold up stopping.
|
||||
func TestStopReturnsWhileCleanupIsStuck(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const stopTimeout = 100 * time.Millisecond
|
||||
|
||||
env := newTestEnv(t)
|
||||
env.srv.SetStopTimeout(stopTimeout)
|
||||
|
||||
client := env.dial(t)
|
||||
|
||||
client.register("stuck")
|
||||
@@ -1070,7 +1092,7 @@ func TestStopReturnsWhileCleanupIsStuck(t *testing.T) {
|
||||
|
||||
select {
|
||||
case <-stopped:
|
||||
case <-time.After(ircserver.StopTimeout + testTimeout):
|
||||
case <-time.After(stopTimeout + testTimeout):
|
||||
t.Error("Stop did not return while a cleanup was stuck")
|
||||
}
|
||||
|
||||
@@ -1122,9 +1144,6 @@ func TestDirectMessage(t *testing.T) {
|
||||
receiver := env.dial(t)
|
||||
receiver.register("dmreceiver")
|
||||
|
||||
// Give relay goroutines time to start.
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
sender.send("PRIVMSG dmreceiver :hello privately")
|
||||
|
||||
lines := receiver.readUntil(func(line string) bool {
|
||||
|
||||
Reference in new issue
Block a user