59 lines
2.5 KiB
Go
59 lines
2.5 KiB
Go
package upwatch
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// R-1292: qBittorrent's 50 % rule owns the NORMAL slot only. With the household's alternative speed on, the rule used
|
|
// to read and write the CURRENT mode's slot (`transfer/uploadLimit`, measured on 5.2.4): it set the alternative limit,
|
|
// and the next switch read as „the household changed it" — the rule stopped for good. The consequences asserted, on the
|
|
// R-1261 fake that behaves like 5.2.4 (fakeQBPrefs): the normal limit is set, the alternative is untouched, and a later
|
|
// switch either way still reads as the box's own limit.
|
|
// RED-PROOF: ApplyQBLimit through UploadLimit/SetUploadLimit (the current mode's slot) → case 1 reads the household's
|
|
// alternative 500 KiB/s as „the household's" and sets nothing; case 2 writes the alternative slot, the normal stays 0.
|
|
|
|
func r1292Apply(t *testing.T, q *QBittorrent, st QBLimitState) (QBLimitState, string) {
|
|
t.Helper()
|
|
ns, act, err := ApplyQBLimit(context.Background(), q, st, 100, true, 0.5, time.Date(2026, 10, 26, 3, 0, 0, 0, time.UTC))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return ns, act
|
|
}
|
|
|
|
func TestR1292_TheRuleSetsTheNormalSlotWhileTheAlternativeIsOn(t *testing.T) {
|
|
target := QBLimitTarget(100, 0.5)
|
|
for _, c := range []struct {
|
|
name string
|
|
alt int64
|
|
}{{"the household's alternative speed 500 KiB/s", 512000}, {"no alternative limit set", 0}} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
f := &fakeQBPrefs{up: 0, alt: c.alt, altMode: true}
|
|
srv := f.server(t, "pw-1292")
|
|
defer srv.Close()
|
|
q := &QBittorrent{Box: envBox{"qbittorrent/QBT_ADMIN_PASSWORD": "pw-1292"}, URL: srv.URL}
|
|
|
|
st, act := r1292Apply(t, q, QBLimitState{})
|
|
if act != "set" || f.up < target-1024 || f.up > target || st.BoxSetBytes != f.up {
|
|
t.Fatalf("alternative mode on: the rule must set the NORMAL limit to ~%d (as stored): act %q, normal %d, recorded %d",
|
|
target, act, f.up, st.BoxSetBytes)
|
|
}
|
|
if f.alt != c.alt {
|
|
t.Fatalf("the alternative limit is the household's: %d → %d", c.alt, f.alt)
|
|
}
|
|
|
|
f.altMode = false // the household switches back to normal speed
|
|
st, act = r1292Apply(t, q, st)
|
|
if act != "kept" || st.Household {
|
|
t.Fatalf("a switch to normal must still read as the box's own limit: act %q, household %v", act, st.Household)
|
|
}
|
|
f.altMode = true // and back to the alternative
|
|
if _, act = r1292Apply(t, q, st); act != "kept" {
|
|
t.Fatalf("a switch back to the alternative must still read as the box's own limit: act %q", act)
|
|
}
|
|
})
|
|
}
|
|
}
|