~james/core

core/spindle/backfill_marks_test.go -rw-r--r-- 1.6 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package spindle

import (
	"context"
	"log/slog"
	"testing"

	"github.com/bluesky-social/indigo/atproto/syntax"

	"tangled.org/core/spindle/db"
	"tangled.org/core/tapc"
)

func handleBackfilled(t *testing.T, b *backfill, evts ...tapc.Event) {
	t.Helper()
	for _, evt := range evts {
		evt.Record.Live = false
		if err := b.handle(context.Background(), evt); err != nil {
			t.Fatal(err)
		}
	}
}

func requireMarked(t *testing.T, d *db.DB, did syntax.DID, want bool, msg string) {
	t.Helper()
	if _, marked, err := d.RepoRetryRow(did); err != nil || marked != want {
		t.Fatalf("%s, marked = %v, %v", msg, marked, err)
	}
}

func TestBackfilledRecordsOnlyMarkTheirRepo(t *testing.T) {
	env := newEnsureEnv(t)
	env.serve("repo")
	b := newBackfill(env.s, slog.Default(), shortTempDir(t))

	handleBackfilled(t, b, markEvent(testRepoDid, env.spindleDid(), testOwner))
	if got := env.knot.count(); got != 0 {
		t.Fatalf("a backfilled manifest cost %d knot requests", got)
	}
	requireMarked(t, env.s.db, testRepoDid, true, "no mark for the backfilled repo")
}

func TestACatchUpMarksServedReposInsteadOfRefreshingThemOneByOne(t *testing.T) {
	env := newEnsureEnv(t)
	env.serve("repo")
	env.ensure(t)
	b := newBackfill(env.s, slog.Default(), shortTempDir(t))
	before := env.knot.count()

	if err := b.refresh(context.Background(), testRepoDid); err != nil {
		t.Fatal(err)
	}
	if got := env.knot.count(); got != before {
		t.Fatalf("the catch-up's refresh cost %d knot requests, it should leave that to the repo's job", got-before)
	}
	requireMarked(t, env.s.db, testRepoDid, true, "the served repo wasn't marked")
}