concurrency_slot_cleanup_test.go 749 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package service
  2. import (
  3. "context"
  4. "sync/atomic"
  5. "testing"
  6. "time"
  7. )
  8. type slotCleanupCache struct {
  9. ConcurrencyCache
  10. calls atomic.Int64
  11. }
  12. func (c *slotCleanupCache) CleanupExpiredAccountSlotKeys(context.Context) error {
  13. c.calls.Add(1)
  14. return nil
  15. }
  16. func TestStartSlotCleanupWorker_UsesCacheWideCleanupWithoutAccountRepo(t *testing.T) {
  17. cache := &slotCleanupCache{}
  18. svc := NewConcurrencyService(cache)
  19. svc.StartSlotCleanupWorker(nil, time.Hour)
  20. deadline := time.After(time.Second)
  21. ticker := time.NewTicker(10 * time.Millisecond)
  22. defer ticker.Stop()
  23. for {
  24. if cache.calls.Load() > 0 {
  25. return
  26. }
  27. select {
  28. case <-deadline:
  29. t.Fatal("cleanup worker did not call cache-wide account slot cleanup")
  30. case <-ticker.C:
  31. }
  32. }
  33. }