package storage import ( "testing" ) // TestAwayWindowOnlyMovesOnANewVisit pins the session gap directly. Within the // gap the window is held; past it, it advances to where the reader actually left // off — never to now, or everything between their last load and this one would // fall down the crack. func TestAwayWindowOnlyMovesOnANewVisit(t *testing.T) { if err := Init(t.TempDir() + "/visit.db"); err != nil { t.Fatal(err) } t.Cleanup(func() { Close() }) t0 := int64(1_000_000) if _, first, err := AdvVisitWindow("sub-1", t0); err != nil || !first { t.Fatalf("first call: first=%v err=%v", first, err) } // A minute later: same visit, window pinned to where it started. from, _, err := AdvVisitWindow("sub-1", t0+60) if err != nil || from != t0 { t.Fatalf("window = %d (err %v), want it held at %d inside the session", from, err, t0) } // Well past the gap: a new visit, reading from the last heartbeat (t0+60), // not from now. from, _, err = AdvVisitWindow("sub-1", t0+60+advVisitSessionGap+1) if err != nil { t.Fatal(err) } if from != t0+60 { t.Errorf("window = %d, want the previous heartbeat %d — anything else drops or replays events", from, t0+60) } }