internal/providers/anipub_long_live_test.go

81 lines · 1873 bytes

3 symbols in this file
 1package providers_test
 2
 3import (
 4	"net/http"
 5	"os"
 6	"strconv"
 7	"testing"
 8	"time"
 9
10	"github.com/wraient/curd/internal/curdhost"
11)
12
13// Run AniPub edge cases in isolation with generous pacing to avoid rate limits:
14//
15//	CURD_LIVE_ANIPUB=1 go test ./internal/providers -run TestLiveAnipubLong -v -timeout 60m
16//
17// Optional: CURD_LIVE_ANIPUB_DELAY_MS=2500 (default 2000)
18func initLiveAnipub(tb testing.TB) {
19	tb.Helper()
20	if os.Getenv("CURD_LIVE_ANIPUB") == "" {
21		tb.Skip("set CURD_LIVE_ANIPUB=1 to run isolated long AniPub live tests")
22	}
23	if curdhost.HTTPClient == nil {
24		curdhost.HTTPClient = func() *http.Client { return http.DefaultClient }
25	}
26}
27
28func anipubLiveDelay() time.Duration {
29	ms := 2000
30	if raw := os.Getenv("CURD_LIVE_ANIPUB_DELAY_MS"); raw != "" {
31		if parsed, err := strconv.Atoi(raw); err == nil && parsed > 0 {
32			ms = parsed
33		}
34	}
35	return time.Duration(ms) * time.Millisecond
36}
37
38func TestLiveAnipubLong(t *testing.T) {
39	initLiveAnipub(t)
40
41	delay := anipubLiveDelay()
42	t.Logf("anipub long run: %d cases, %v delay between requests", len(edgeAnimeCases), delay)
43
44	var anipub edgeProvider
45	for _, p := range edgeProviders() {
46		if p.name == "anipub" {
47			anipub = p
48			break
49		}
50	}
51	if anipub.name == "" {
52		t.Fatal("anipub provider not found")
53	}
54
55	type counts struct{ search, match, episodes, stream, total int }
56	var c counts
57
58	for i, tc := range edgeAnimeCases {
59		res := runEdgeCase(anipub, tc)
60		c.total++
61		if res.searchOK {
62			c.search++
63		}
64		if res.matchOK {
65			c.match++
66		}
67		if res.episodesOK {
68			c.episodes++
69		}
70		if res.streamOK {
71			c.stream++
72		}
73		t.Logf("[%d/%d] %s", i+1, len(edgeAnimeCases), edgeStatusLine(res))
74		if i < len(edgeAnimeCases)-1 {
75			time.Sleep(delay)
76		}
77	}
78
79	t.Logf("anipub long: search %d/%d match %d/%d episodes %d/%d stream %d/%d",
80		c.search, c.total, c.match, c.total, c.episodes, c.total, c.stream, c.total)
81}