~james/core

core/spindle/backfill_skip_test.go -rw-r--r-- 2.3 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
58
59
60
61
62
63
64
65
package spindle

import (
	"log/slog"
	"testing"

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

	"tangled.org/core/api/org_tangled"
	"tangled.org/core/tapc"
)

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

	manifest := markEvent(testRepoDid, env.spindleDid(), testOwner)
	collaborator := recordEvent(testRepoDid, org_tangled.GraphCollaboratorNSID, testBob.String(), tapc.RecordCreateAction, map[string]string{})
	handleBackfilled(t, b, manifest, collaborator)
	requireMarked(t, env.s.db, testRepoDid, false, "a served repo's backfilled records marked it")
	if got := env.knot.count(); got != before {
		t.Fatalf("backfilled records cost %d knot requests", got-before)
	}

	handleBackfilled(t, b, declarationEvent(testOwner, testRepoDid, tapc.RecordCreateAction))
	requireMarked(t, env.s.db, testRepoDid, false, "a served repo's backfilled declaration marked it")
}

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

	handleBackfilled(t, b, declarationEvent(testOwner, testRepoDid, tapc.RecordCreateAction))
	requireMarked(t, env.s.db, testRepoDid, true, "a new repo's backfilled declaration left no mark")
}

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

	other := syntax.DID("did:plc:otherrepo")
	handleBackfilled(t, b, declarationEvent(testOwner, other, tapc.RecordCreateAction))
	requireMarked(t, env.s.db, other, true, "a backfilled declaration naming another repo left no mark")
}

func TestAServedRepoWhoseBackfillFailedIsMarkedAnyway(t *testing.T) {
	f := &fakeHydrant{}
	failOn(f, pendingRepo)
	b := catchUpBackfill(t, f)
	if err := b.CatchUp(); err != nil {
		t.Fatal(err)
	}

	runRound(t, b)

	requireMarked(t, b.s.db, pendingRepo, true, "the served repo wasn't marked after its backfill failed")
	if got := pendingDids(t, b); len(got) == 0 {
		t.Fatal("the failed repo left the pending list, it has to stay for the next round")
	}
}