Artifact 458c8e12bdfb797542017b33b522506642fd70a7e76097bd0c306fafbd8b563f:
- File
internal/xfer/tally_test.go
— part of check-in
[dc058fa551]
at
2026-08-24 19:16:15
on branch clone-counts
— Count clones and fetches
A clone reads and writes nothing, so it is the one kind of forge activity that leaves no trace in the DAG at all.
The sync edge classifies the protocol's cards: clone SEQNO 1 opens a new clone, later rounds do not, so a big store cloned in forty rounds still counts once. Two sinks: the vocabulary event for anything reacting, and a JetStream counter for how many, which converges across nodes instead of losing increments to a read-modify-write. (user: dmestas, size: 2382) [annotate] [blame] [check-ins using] [more...]
package xfer import "testing" // The protocol gives a clone an opening marker and a fetch none, so the // two are counted differently and this pins the difference. func TestScanClassifiesCloneAndPull(t *testing.T) { for _, tc := range []struct { name string body string wantClone bool wantPull bool }{ {"a clone opening", "clone 3 1\n", true, false}, // Later rounds of the SAME clone must not each count as one. {"a later clone round", "clone 3 2\n", false, false}, {"a much later round", "clone 3 47\n", false, false}, {"a pull", "pull aaaa bbbb\n", false, true}, {"a sync carries both", "push aaaa bbbb\npull aaaa bbbb\n", false, true}, // The spec's rule is digit-only recognition of SEQNO, so these // are not sequence one however much they look like it. {"a padded seqno", "clone 3 01\n", false, false}, {"wrong arity", "clone 1\n", false, false}, {"no operation card", "# just a comment\n", false, false}, // Cards are classified after whitespace skipping, never by byte // prefix — an indented card the backend honours must be seen. {"an indented clone", " clone 3 1\n", true, false}, } { pr := scanRequest([]byte(tc.body)) if pr.newClone != tc.wantClone { t.Errorf("%s: newClone = %v, want %v", tc.name, pr.newClone, tc.wantClone) } if pr.hasPull != tc.wantPull { t.Errorf("%s: hasPull = %v, want %v", tc.name, pr.hasPull, tc.wantPull) } } } // A clone is counted as a clone and not also as a fetch, or every clone // would inflate both numbers. func TestTallyPrefersCloneOverPull(t *testing.T) { var got []string f := New() f.SetCounted(func(repo string, clone bool) { kind := "fetch" if clone { kind = "clone" } got = append(got, repo+":"+kind) }) f.tally("alpha", scanRequest([]byte("clone 3 1\npull aaaa bbbb\n"))) f.tally("alpha", scanRequest([]byte("pull aaaa bbbb\n"))) f.tally("alpha", scanRequest([]byte("push aaaa bbbb\n"))) f.tally("alpha", scanRequest([]byte("clone 3 2\n"))) want := []string{"alpha:clone", "alpha:fetch"} if len(got) != len(want) { t.Fatalf("tallied %v, want %v", got, want) } for i := range want { if got[i] != want[i] { t.Fatalf("tallied %v, want %v", got, want) } } } // No tally installed must cost nothing and crash nothing. func TestTallyWithoutACounter(t *testing.T) { New().tally("alpha", scanRequest([]byte("clone 3 1\n"))) }