fuzz_test.go 960 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package telemetry_test
  2. import (
  3. "testing"
  4. "time"
  5. hthv1 "hth/internal/gen/hth/api/v1"
  6. "hth/internal/telemetry"
  7. )
  8. func FuzzResumeIDs(f *testing.F) {
  9. f.Add(uint64(0), uint64(1))
  10. f.Add(uint64(1), uint64(0))
  11. f.Add(uint64(9), uint64(3))
  12. f.Fuzz(func(t *testing.T, resumeAfter, publishN uint64) {
  13. if publishN > 64 {
  14. publishN = 64
  15. }
  16. h := telemetry.NewHub(8, 4, 8, 4)
  17. now := time.Unix(1, 0)
  18. for i := uint64(0); i < publishN; i++ {
  19. h.PublishSnapshot(&hthv1.Snapshot{DeviceId: "d0", SnapshotSeq: i + 1}, now)
  20. }
  21. newest := h.NewestEventID()
  22. sub, replay, gap, err := h.SubscribeEventsPeer(resumeAfter, "fuzz")
  23. if resumeAfter > newest {
  24. if err == nil {
  25. t.Fatalf("future resume %d newest %d must fail", resumeAfter, newest)
  26. }
  27. if sub != nil || gap != nil || len(replay) != 0 {
  28. t.Fatal("future resume must not create a subscriber")
  29. }
  30. return
  31. }
  32. if err != nil {
  33. return
  34. }
  35. if sub != nil {
  36. sub.Cancel()
  37. }
  38. })
  39. }