checkpoint_test.go raw

   1  package relay
   2  
   3  import (
   4  	"fmt"
   5  	"testing"
   6  
   7  	"git.smesh.lol/torly/pkg/store"
   8  )
   9  
  10  // TestCheckpointUnderTraffic drives more saves than the checkpoint threshold so
  11  // the database domain's checkpoint branch runs while clients are publishing, then
  12  // asks for everything back. The point is that moving the checkpoint out of the
  13  // save path did not lose or duplicate events.
  14  func TestCheckpointUnderTraffic(t *testing.T) {
  15  	tr := startTestRelay(t, false)
  16  	pub := dialWS(t, tr.addr)
  17  
  18  	// One past the store's checkpoint threshold.
  19  	const total = store.CheckpointEvery + 4
  20  	for i := 0; i < total; i++ {
  21  		publish(t, pub, testEvent(t, byte(i%200)+1, 1, nil, fmt.Sprintf("note %d", i)))
  22  	}
  23  
  24  	if n, _ := countFilter(t, tr.addr, `{"kinds":[1]}`); n != total {
  25  		t.Fatalf("stored %d events, want %d", n, total)
  26  	}
  27  }
  28