f580d88a14
gates / gates (push) Successful in 45s
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
57 lines
2.2 KiB
Go
57 lines
2.2 KiB
Go
package settings
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// The media drive events (v0.313.0): a drive change makes the restart pending until the apps restart; a safe removal
|
|
// keeps the drive registered and its paused torrents until the media apps restart after its return (R-1044).
|
|
func TestMediaEvents_PendingUntilRestarted(t *testing.T) {
|
|
s := newTestSettings(t, []StoragePath{{Path: "/mnt/felhom-drives/media_b", Label: "Media B"}})
|
|
if err := s.MarkMediaChanged("/mnt/felhom-drives/media_b", "added"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !s.GetStoragePaths()[0].MediaRestartPending() {
|
|
t.Fatal("a drive just added must make the media restart pending")
|
|
}
|
|
time.Sleep(2 * time.Millisecond)
|
|
if err := s.MarkMediaRestarted(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s.GetStoragePaths()[0].MediaRestartPending() {
|
|
t.Fatal("after the restart nothing is pending")
|
|
}
|
|
time.Sleep(2 * time.Millisecond)
|
|
_ = s.MarkMediaChanged("/mnt/felhom-drives/media_b", "returned")
|
|
if !s.GetStoragePaths()[0].MediaRestartPending() {
|
|
t.Fatal("a later change makes it pending again — the timestamps must compare correctly as text")
|
|
}
|
|
}
|
|
|
|
// COMPANION RED-PROOF (2026-10-15): make ClearEjected also clear EjectPaused → this test fails (nothing to resume after
|
|
// the restart: the household's torrents stay stopped). Restored.
|
|
func TestMediaEvents_SafeRemovalKeepsDriveAndTorrents(t *testing.T) {
|
|
s := newTestSettings(t, []StoragePath{{Path: "/mnt/felhom-drives/media_c", Label: "Media C"}})
|
|
if err := s.SetEjected("/mnt/felhom-drives/media_c", "uuid:abc", []string{"qbit:h1", "trans:h2"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sp := s.GetStoragePaths()
|
|
if len(sp) != 1 || !sp[0].Disconnected || sp[0].EjectedAt == "" {
|
|
t.Fatalf("a safe removal must keep the drive registered and mark it removed: %+v", sp)
|
|
}
|
|
if got := s.TakeResumable(); len(got) != 0 {
|
|
t.Fatalf("while the drive is away nothing may resume: %v", got)
|
|
}
|
|
if err := s.ClearEjected("/mnt/felhom-drives/media_c"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := s.TakeResumable()
|
|
if len(got) != 2 {
|
|
t.Fatalf("after the return the two paused torrents must be handed to the restart: %v", got)
|
|
}
|
|
if again := s.TakeResumable(); len(again) != 0 {
|
|
t.Fatalf("taken once, never twice: %v", again)
|
|
}
|
|
}
|