adding scheduler slots
This commit is contained in:
+28
-1
@@ -18,6 +18,7 @@ type fakeTransmission struct {
|
||||
mu sync.Mutex
|
||||
torrents map[string]schedulerTorrent
|
||||
failStart bool
|
||||
actions []string
|
||||
}
|
||||
|
||||
func newFakeTransmission(t *testing.T, torrents ...schedulerTorrent) (*Client, *fakeTransmission) {
|
||||
@@ -57,6 +58,7 @@ func newFakeTransmission(t *testing.T, torrents ...schedulerTorrent) (*Client, *
|
||||
response["result"] = "start failed"
|
||||
} else {
|
||||
for _, hash := range request.Arguments.IDs {
|
||||
fake.actions = append(fake.actions, request.Method+":"+hash)
|
||||
torrent := fake.torrents[hash]
|
||||
torrent.Status = 6
|
||||
fake.torrents[hash] = torrent
|
||||
@@ -64,6 +66,7 @@ func newFakeTransmission(t *testing.T, torrents ...schedulerTorrent) (*Client, *
|
||||
}
|
||||
case "torrent-stop":
|
||||
for _, hash := range request.Arguments.IDs {
|
||||
fake.actions = append(fake.actions, request.Method+":"+hash)
|
||||
torrent := fake.torrents[hash]
|
||||
torrent.Status = 0
|
||||
fake.torrents[hash] = torrent
|
||||
@@ -192,7 +195,9 @@ func TestSchedulerMultipleSlotsAndManualActions(t *testing.T) {
|
||||
a := schedulerTorrent{Hash: strings.Repeat("a", 40), Name: "A", PercentDone: 1}
|
||||
b := schedulerTorrent{Hash: strings.Repeat("b", 40), Name: "B", PercentDone: 1}
|
||||
c := schedulerTorrent{Hash: strings.Repeat("c", 40), Name: "C", PercentDone: 1}
|
||||
client, fake := newFakeTransmission(t, a, b, c)
|
||||
unmanagedDownload := schedulerTorrent{Hash: strings.Repeat("d", 40), Name: "Unmanaged download", PercentDone: .5, Status: 4}
|
||||
unmanagedSeed := schedulerTorrent{Hash: strings.Repeat("e", 40), Name: "Unmanaged seed", PercentDone: 1, Status: 6}
|
||||
client, fake := newFakeTransmission(t, a, b, c, unmanagedDownload, unmanagedSeed)
|
||||
scheduler := testScheduler(t, client)
|
||||
addOptIn(t, scheduler, a, b, c)
|
||||
if _, err := scheduler.db.Exec("UPDATE scheduler_settings SET max_active=2 WHERE id=1"); err != nil {
|
||||
@@ -229,6 +234,28 @@ func TestSchedulerMultipleSlotsAndManualActions(t *testing.T) {
|
||||
if got := activeHashes(t, scheduler); len(got) != 2 || got[0] != b.Hash || got[1] != c.Hash {
|
||||
t.Fatalf("expected one rotation with no same-tick reuse: %v", got)
|
||||
}
|
||||
if _, err := scheduler.db.Exec("UPDATE scheduler_settings SET max_active=1 WHERE id=1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := scheduler.Tick(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := activeHashes(t, scheduler); len(got) != 1 {
|
||||
t.Fatalf("expected one opted-in active slot after reducing the limit: %v", got)
|
||||
}
|
||||
fake.mu.Lock()
|
||||
downloadStatus := fake.torrents[unmanagedDownload.Hash].Status
|
||||
seedStatus := fake.torrents[unmanagedSeed.Hash].Status
|
||||
actions := append([]string(nil), fake.actions...)
|
||||
fake.mu.Unlock()
|
||||
if downloadStatus != 4 || seedStatus != 6 {
|
||||
t.Fatalf("unopted torrents changed status: download=%d seed=%d", downloadStatus, seedStatus)
|
||||
}
|
||||
for _, action := range actions {
|
||||
if strings.Contains(action, unmanagedDownload.Hash) || strings.Contains(action, unmanagedSeed.Hash) {
|
||||
t.Fatalf("scheduler sent an action for an unopted torrent: %s", action)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSchedulerFailureDoesNotRecordActivation(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user