Restore test

This commit is contained in:
Justin Hawkins 2023-03-09 23:24:03 +10:30
parent 3d72b8b16a
commit f2c05d0144
2 changed files with 112 additions and 62 deletions

View File

@ -57,6 +57,7 @@ type ConfigService struct {
func (cs *ConfigService) LoadTestConfig() { func (cs *ConfigService) LoadTestConfig() {
cs.LoadDefaultConfig() cs.LoadDefaultConfig()
cs.Config.Server.DownloadPath = "/tmp"
cs.Config.DownloadProfiles = []DownloadProfile{{Name: "test profile", Command: "sleep", Args: []string{"5"}}} cs.Config.DownloadProfiles = []DownloadProfile{{Name: "test profile", Command: "sleep", Args: []string{"5"}}}
} }

View File

@ -2,7 +2,11 @@ package download
import ( import (
"strings" "strings"
"sync"
"testing" "testing"
"time"
"github.com/tardisx/gropple/config"
) )
func TestUpdateMetadata(t *testing.T) { func TestUpdateMetadata(t *testing.T) {
@ -76,79 +80,124 @@ func TestUpdateMetadata(t *testing.T) {
// [download] 100% of 4.64MiB in 00:00 // [download] 100% of 4.64MiB in 00:00
// [ffmpeg] Merging formats into "Halo Infinite Flight 4K Gameplay-wi7Agv1M6PY.mp4" // [ffmpeg] Merging formats into "Halo Infinite Flight 4K Gameplay-wi7Agv1M6PY.mp4"
// func TestQueue(t *testing.T) { func TestQueue(t *testing.T) {
// cs := config.ConfigService{} cs := config.ConfigService{}
// cs.LoadTestConfig() cs.LoadTestConfig()
// conf := cs.Config conf := cs.Config
// new1 := Download{Id: 1, Url: "http://sub.example.org/foo1", State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf} new1 := Download{Id: 1, Url: "http://sub.example.org/foo1", State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf}
// new2 := Download{Id: 2, Url: "http://sub.example.org/foo2", State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf} new2 := Download{Id: 2, Url: "http://sub.example.org/foo2", State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf}
// new3 := Download{Id: 3, Url: "http://sub.example.org/foo3", State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf} new3 := Download{Id: 3, Url: "http://sub.example.org/foo3", State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf}
// new4 := Download{Id: 4, Url: "http://example.org/", State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf} new4 := Download{Id: 4, Url: "http://example.org/", State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf}
// dls := Downloads{&new1, &new2, &new3, &new4} q := Manager{
// dls.StartQueued(1) Downloads: []*Download{},
// time.Sleep(time.Millisecond * 100) MaxPerDomain: 2,
// if dls[0].State == "queued" { Lock: sync.Mutex{},
// t.Error("#1 was not started") }
// }
// if dls[1].State != "queued" {
// t.Error("#2 is not queued")
// }
// if dls[3].State == "queued" {
// t.Error("#4 is not started")
// }
// // this should start no more, as one is still going q.AddDownload(&new1)
// dls.StartQueued(1) q.AddDownload(&new2)
// time.Sleep(time.Millisecond * 100) q.AddDownload(&new3)
// if dls[1].State != "queued" { q.AddDownload(&new4)
// t.Error("#2 was started when it should not be")
// }
// dls.StartQueued(2) q.startQueued(1)
// time.Sleep(time.Millisecond * 100)
// if dls[1].State == "queued" {
// t.Error("#2 was not started but it should be")
// } // two should start, one from each of the two domains
time.Sleep(time.Millisecond * 100)
if q.Downloads[0].State != "downloading" {
t.Errorf("#1 was not downloading - %s instead ", q.Downloads[0].State)
}
if q.Downloads[1].State != "queued" {
t.Errorf("#2 is not queued - %s instead", q.Downloads[1].State)
}
if q.Downloads[2].State != "queued" {
t.Errorf("#3 is not queued - %s instead", q.Downloads[2].State)
}
if q.Downloads[3].State != "downloading" {
t.Errorf("#4 is not downloading - %s instead", q.Downloads[3].State)
}
// dls.StartQueued(2) // this should start no more, as one is still going
// time.Sleep(time.Millisecond * 100) q.startQueued(1)
// if dls[3].State == "queued" { time.Sleep(time.Millisecond * 100)
// t.Error("#4 was not started but it should be") if q.Downloads[0].State != "downloading" {
// } t.Errorf("#1 was not downloading - %s instead ", q.Downloads[0].State)
}
if q.Downloads[1].State != "queued" {
t.Errorf("#2 is not queued - %s instead", q.Downloads[1].State)
}
if q.Downloads[2].State != "queued" {
t.Errorf("#3 is not queued - %s instead", q.Downloads[2].State)
}
if q.Downloads[3].State != "downloading" {
t.Errorf("#4 is not downloading - %s instead", q.Downloads[3].State)
}
// // reset them all // wait until the two finish, check
// dls[0].State = "queued" time.Sleep(time.Second * 5.0)
// dls[1].State = "queued" if q.Downloads[0].State != "complete" {
// dls[2].State = "queued" t.Errorf("#1 was not complete - %s instead ", q.Downloads[0].State)
// dls[3].State = "queued" }
if q.Downloads[1].State != "queued" {
t.Errorf("#2 is not queued - %s instead", q.Downloads[1].State)
}
if q.Downloads[2].State != "queued" {
t.Errorf("#3 is not queued - %s instead", q.Downloads[2].State)
}
if q.Downloads[3].State != "complete" {
t.Errorf("#4 is not complete - %s instead", q.Downloads[3].State)
}
// dls.StartQueued(0) // this should start one more, as one is still going
// time.Sleep(time.Millisecond * 100) q.startQueued(1)
time.Sleep(time.Millisecond * 100)
if q.Downloads[0].State != "complete" {
t.Errorf("#1 was not complete - %s instead ", q.Downloads[0].State)
}
if q.Downloads[1].State != "downloading" {
t.Errorf("#2 is not downloading - %s instead", q.Downloads[1].State)
}
if q.Downloads[2].State != "queued" {
t.Errorf("#3 is not queued - %s instead", q.Downloads[2].State)
}
if q.Downloads[3].State != "complete" {
t.Errorf("#4 is not complete - %s instead", q.Downloads[3].State)
}
// // they should all be going // this should start no more, as one is still going
// if dls[0].State == "queued" || dls[1].State == "queued" || dls[2].State == "queued" || dls[3].State == "queued" { q.startQueued(1)
// t.Error("none should be queued") time.Sleep(time.Millisecond * 100)
// } if q.Downloads[0].State != "complete" {
t.Errorf("#1 was not complete - %s instead ", q.Downloads[0].State)
}
if q.Downloads[1].State != "downloading" {
t.Errorf("#2 is not downloading - %s instead", q.Downloads[1].State)
}
if q.Downloads[2].State != "queued" {
t.Errorf("#3 is not queued - %s instead", q.Downloads[2].State)
}
if q.Downloads[3].State != "complete" {
t.Errorf("#4 is not complete - %s instead", q.Downloads[3].State)
}
// // reset them all // but if we allow two per domain, the other queued one will start
// dls[0].State = "queued" q.startQueued(2)
// dls[1].State = "queued" time.Sleep(time.Millisecond * 100)
// dls[2].State = "queued" if q.Downloads[0].State != "complete" {
// dls[3].State = "queued" t.Errorf("#1 was not complete - %s instead ", q.Downloads[0].State)
}
if q.Downloads[1].State != "downloading" {
t.Errorf("#2 is not downloading - %s instead", q.Downloads[1].State)
}
if q.Downloads[2].State != "downloading" {
t.Errorf("#3 is not downloading - %s instead", q.Downloads[2].State)
}
if q.Downloads[3].State != "complete" {
t.Errorf("#4 is not complete - %s instead", q.Downloads[3].State)
}
// dls.StartQueued(2) }
// time.Sleep(time.Millisecond * 100)
// // first two should be running, third not (same domain) and 4th running (different domain)
// if dls[0].State == "queued" || dls[1].State == "queued" || dls[2].State != "queued" || dls[3].State == "queued" {
// t.Error("incorrect queued")
// }
// }
func TestUpdateMetadataPlaylist(t *testing.T) { func TestUpdateMetadataPlaylist(t *testing.T) {