fix: keep Redis timeouts below a second exact
A checker's long poll ends with BLPOP waiting the rest of it, often below a second, which go-redis rounded up to one second with a warning in the log; the poll then ran up to a second too long. Such waits now pass BLPOP a fraction of a second, which Redis takes since 6.0. A session's sliding expiry, which can be below a second near its absolute end, uses PEXPIRE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
db36d918fe
commit
66537f4e65
3 files changed
+28
-3
No files matched your search
@@ -188,11 +188,26 @@ func TestTakeWaits(t *testing.T) {
|
||||
if err != nil || len(got) != 0 {
|
||||
t.Fatalf("Take() on empty queue = %v, %v", got, err)
|
||||
}
|
||||
if waited := time.Since(start); waited < 250*time.Millisecond {
|
||||
// Not rounded up to the second that BLPOP counts in.
|
||||
if waited := time.Since(start); waited < 250*time.Millisecond || waited > 800*time.Millisecond {
|
||||
t.Errorf("Take() returned after %v, want it to wait about 300ms", waited)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTakeGetsAJobDuringAShortWait(t *testing.T) {
|
||||
s, _ := newTest(t)
|
||||
ctx := context.Background()
|
||||
in, monitor := uuid.New(), uuid.New()
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
s.rdb.RPush(ctx, jobsPrefix+in.String(), monitor.String()+"|1800000000000")
|
||||
}()
|
||||
got, err := s.Take(ctx, in, 10, 600*time.Millisecond)
|
||||
if err != nil || len(got) != 1 || got[0].MonitorID != monitor {
|
||||
t.Fatalf("Take() = %v, %v; want the job pushed while waiting", got, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTakeReturnsWhenCancelled(t *testing.T) {
|
||||
s, _ := newTest(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
Reference in new issue
Block a user