perf(playout): parallelize playlist validation with dedup and worker pool
CI / test (push) Successful in 1m52s
CI / docker (push) Successful in 55s

This commit is contained in:
zwitschi committed 2026-08-16 10:30:15 +02:00
1 parent bde3dc3a46
commit c2f9f9ed62
7 files changed
+152 -36

No files matched your search

+48
View File
@@ -465,6 +465,54 @@ func TestValidatePlaylist(t *testing.T) {
t.Skip("requires ffprobe mock or test media fixtures")
}
func TestValidateWorkersConfig(t *testing.T) {
os.Unsetenv("PLAYOUT_VALIDATE_WORKERS")
if got := validateWorkers(); got < 1 {
t.Errorf("validateWorkers() = %d, want >= 1", got)
}
os.Setenv("PLAYOUT_VALIDATE_WORKERS", "3")
if got := validateWorkers(); got != 3 {
t.Errorf("validateWorkers() = %d, want 3", got)
}
os.Setenv("PLAYOUT_VALIDATE_WORKERS", "invalid")
if got := validateWorkers(); got < 1 {
t.Errorf("validateWorkers() = %d, want fallback >= 1", got)
}
os.Unsetenv("PLAYOUT_VALIDATE_WORKERS")
}
func TestValidatePlaylist_Dedup(t *testing.T) {
ensureFFProbeInPath(t)
valid := filepath.Join("..", "testdata", "valid_720p30.mp4")
playlistDir := t.TempDir()
p := filepath.Join(playlistDir, "playlist.txt")
// Same file listed three times to exercise dedup + order preservation.
content := fmt.Sprintf("file '%s'\nfile '%s'\nfile '%s'\n", valid, valid, valid)
if err := os.WriteFile(p, []byte(content), 0o644); err != nil {
t.Fatalf("write playlist: %v", err)
}
videos, err := ValidatePlaylist(p)
if err != nil {
t.Fatalf("ValidatePlaylist error: %v", err)
}
if len(videos) != 3 {
t.Fatalf("len = %d, want 3", len(videos))
}
for i, v := range videos {
if !v.Valid {
t.Errorf("entry %d invalid: %s", i, v.Validation)
}
if v.Path != valid {
t.Errorf("entry %d path = %q, want %q", i, v.Path, valid)
}
}
}
func TestSyncToR2(t *testing.T) {
prevClient := r2Client
prevBucket := bucket