mirror of
https://github.com/tiennm99/telegram-exporter.git
synced 2026-10-15 12:14:59 +00:00
Verification matched on name and non-zero size, so an upload that died partway was counted archived permanently. Comparing against the size Telegram reports found six such objects in the live archive, one of them 221 MiB standing in for a 2006 MiB video. They are folded into the outstanding set; rclone overwrites a size mismatch, so another pass repairs them. A zero Report claimed the archive was complete — nothing expected, nothing missing — which is the value both commands hold before their Telegram callback populates it, so any early return printed COMPLETE and exited 0 on an untouched chat. A Report now knows whether it ran. A name that can never be written kept the run outstanding forever while the download set deliberately excluded it, so a driver looping on "incomplete" walked the whole history and re-indexed the whole remote every pass for work that could not be done. Such a run now reports STALLED and exits 4. A destination that stopped accepting uploads was reported and then discarded, exiting 1. The same driver would retry against a full or unreachable remote indefinitely, downloading gigabytes each pass to upload none. It exits 3. Free space is re-checked during the run, not only before it. An archive this size runs for hours, and the remote can fill in the middle; discovering it through five failed multi-gigabyte uploads wastes the download for all of them. Also: parseSize silently wrapped to a negative or zero on a large input, which reads downstream as "no cap"; list printed attacker-chosen filenames raw, so a tab shifted the columns and an escape sequence reached the terminal; a missing backend blamed credentials rather than the build; humanBytes indexed past its unit table above 1 PiB; a second Init reported success against a config that never loaded; and sync did not surface the basename collisions verify warned about, though sync is the command that acts on the verdict. The env-override test could not observe what it claimed: rclone reads RCLONE_* at package init, so t.Setenv came too late and the assertion held with the guard removed. It runs in a subprocess now, as does the new one covering the index against inherited filters.
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestSpaceGuard(t *testing.T) {
|
|
const floor = 10 << 30
|
|
|
|
t.Run("unset guard never complains", func(t *testing.T) {
|
|
if err := newSpaceGuard(nil, floor).check(t.Context()); err != nil {
|
|
t.Errorf("check = %v, want nil when no reporter is configured", err)
|
|
}
|
|
})
|
|
|
|
t.Run("a backend without a quota counts as unlimited", func(t *testing.T) {
|
|
g := newSpaceGuard(func(context.Context) (int64, bool) { return 0, false }, floor)
|
|
g.lastCheck = time.Now().Add(-2 * spaceCheckInterval)
|
|
if err := g.check(t.Context()); err != nil {
|
|
t.Errorf("check = %v, want nil when the backend cannot report", err)
|
|
}
|
|
})
|
|
|
|
t.Run("plenty of room is fine", func(t *testing.T) {
|
|
g := newSpaceGuard(func(context.Context) (int64, bool) { return 100 << 30, true }, floor)
|
|
g.lastCheck = time.Now().Add(-2 * spaceCheckInterval)
|
|
if err := g.check(t.Context()); err != nil {
|
|
t.Errorf("check = %v, want nil with 100 GiB free", err)
|
|
}
|
|
})
|
|
|
|
t.Run("below the floor stops the run", func(t *testing.T) {
|
|
var calls int
|
|
g := newSpaceGuard(func(context.Context) (int64, bool) {
|
|
calls++
|
|
return 1 << 30, true
|
|
}, floor)
|
|
g.lastCheck = time.Now().Add(-2 * spaceCheckInterval)
|
|
|
|
err := g.check(t.Context())
|
|
if !errors.Is(err, ErrDestinationFailing) {
|
|
t.Fatalf("check = %v, want ErrDestinationFailing", err)
|
|
}
|
|
// Sticky, and without another round trip: the run is ending either way,
|
|
// and every upload worker calls this.
|
|
for range 5 {
|
|
if !errors.Is(g.check(t.Context()), ErrDestinationFailing) {
|
|
t.Fatal("the verdict did not stick")
|
|
}
|
|
}
|
|
if calls != 1 {
|
|
t.Errorf("free space was read %d times, want 1", calls)
|
|
}
|
|
})
|
|
|
|
t.Run("checks are throttled", func(t *testing.T) {
|
|
var calls int
|
|
g := newSpaceGuard(func(context.Context) (int64, bool) {
|
|
calls++
|
|
return 100 << 30, true
|
|
}, floor)
|
|
// Freshly built, so the interval has not elapsed. About is a network
|
|
// round trip and every worker calls this per file.
|
|
for range 20 {
|
|
if err := g.check(t.Context()); err != nil {
|
|
t.Fatalf("check = %v", err)
|
|
}
|
|
}
|
|
if calls != 0 {
|
|
t.Errorf("free space was read %d times inside the interval, want 0", calls)
|
|
}
|
|
})
|
|
}
|