~james/core

core/spindle/db/pull_events_limit_test.go -rw-r--r-- 921 bytes
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
package db

import (
	"fmt"
	"testing"
	"time"

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

func TestDuePullEventsReadsOnlyALimitOldestFirst(t *testing.T) {
	d := newTestDB(t)
	repo := syntax.DID("did:plc:a")
	if err := d.AddPullTicket(repo, "t1", PullTicket{Author: "did:plc:bob", State: "open", Version: "v0"}); err != nil {
		t.Fatal(err)
	}
	for i := 1; i <= 5; i++ {
		ev := PullEvent{RepoDid: repo, Ticket: "t1", Event: "closed", Pull: []byte("{}")}
		if err := d.AdvancePullTicket(repo, "t1", fmt.Sprintf("v%d", i-1), fmt.Sprintf("v%d", i), "closed", &ev); err != nil {
			t.Fatal(err)
		}
	}

	due, err := d.DuePullEvents(repo, time.Now().Add(time.Hour), 3)
	if err != nil || len(due) != 3 {
		t.Fatalf("read %d events, %v, want the limit of 3", len(due), err)
	}
	if due[0].ID >= due[1].ID || due[1].ID >= due[2].ID {
		t.Fatalf("ids %d %d %d, want oldest first", due[0].ID, due[1].ID, due[2].ID)
	}
}