Skip to content
quarry Artifact [16db42dd95]
Login

Artifact [16db42dd95]

Artifact 16db42dd9584218c7a6d57c94db5c8bf144564a83874ac75bbaadfdb56bf9218:


package main

import "testing"

// A leaf mark is a claim — "this is the tip of its branch and nothing
// follows it" — and the instant that stops being true is a merge, which
// is exactly when somebody is reading the timeline. Serving the set
// derived before the merge puts rings on the check-ins that just
// stopped being leaves.
//
// So a set from an older ingest generation is not served at all. No
// ring says "not known"; a wrong ring says "still open", and only one
// of those is recoverable by looking again.
func TestStaleLeafSetIsNeverServed(t *testing.T) {
	set := map[string]bool{"abc123abc123": true}

	if got, ok := leafAnswer(set, 7, 7); !ok || got == nil {
		t.Error("a set derived at the current generation was withheld")
	}
	if got, ok := leafAnswer(set, 6, 7); ok || got != nil {
		t.Errorf("a set from generation 6 was served at generation 7: %v", got)
	}
	// Cold is the case this already handled: nothing derived yet.
	if got, ok := leafAnswer(nil, 7, 7); ok || got != nil {
		t.Error("a nil set was reported as usable")
	}
	// And a generation that somehow ran ahead is still not this one.
	if _, ok := leafAnswer(set, 8, 7); ok {
		t.Error("a set from a different generation was served")
	}
}