Drive the archive reopen debounce test from a clock (closes #190)
check / check (push) Waiting to run
check / check (push) Waiting to run
The archive writer's reopen debounce test made two writes that had to land inside the real 2-second window, then slept 2.1 seconds to cross it, so a slow host could turn correct code red. The archive writer now reads the time for its reopen debounce from a clock field, time.Now in production, and the test moves that clock instead of sleeping: two writes at one instant open the file once, and a write one debounce later closes and reopens it once. Removing the debounce check fails the test. This was the last test whose result depended on real elapsed time. Model: opus-5-5
This commit was merged in pull request #438.
This commit is contained in:
@@ -194,6 +194,10 @@ type archiveWriter struct {
|
||||
lastReopen time.Time
|
||||
reopens int
|
||||
|
||||
// now is the clock the reopen debounce is measured on. It is
|
||||
// time.Now outside tests.
|
||||
now func() time.Time
|
||||
|
||||
// evicted marks a writer that has been removed from the
|
||||
// registry. Its handle is closed and it must never open the
|
||||
// file again: nothing holds it any more, so a reopen would
|
||||
@@ -228,6 +232,7 @@ func newArchiveWriter(
|
||||
path: path,
|
||||
log: log,
|
||||
debounce: archiveReopenDebounce,
|
||||
now: time.Now,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +268,7 @@ func (w *archiveWriter) write(
|
||||
)
|
||||
}
|
||||
|
||||
if time.Since(w.lastReopen) >= w.debounce {
|
||||
if w.now().Sub(w.lastReopen) >= w.debounce {
|
||||
return w.reopen(expiry)
|
||||
}
|
||||
|
||||
@@ -323,7 +328,7 @@ func (w *archiveWriter) openMode(
|
||||
}
|
||||
|
||||
w.db = gdb
|
||||
w.lastReopen = time.Now()
|
||||
w.lastReopen = w.now()
|
||||
w.reopens++
|
||||
|
||||
if expiry > 0 {
|
||||
|
||||
Reference in New Issue
Block a user