diff options
| author | RanXom <saiyedshizain@gmail.com> | 2026-07-17 11:02:36 +0530 |
|---|---|---|
| committer | RanXom <saiyedshizain@gmail.com> | 2026-07-17 11:02:36 +0530 |
| commit | 868c02846962558a97a84c085c92baa5ba6e535f (patch) | |
| tree | 00db7d8d6ce25c7178df1bf257a0a3818fa0f030 /internal/watcher | |
| parent | cc42b82782eca935beb6b552e293e4458bb715bc (diff) | |
| download | galleryd-868c02846962558a97a84c085c92baa5ba6e535f.tar.xz galleryd-868c02846962558a97a84c085c92baa5ba6e535f.zip | |
refactor(watcher): refactor tests for faster testing time
Diffstat (limited to 'internal/watcher')
| -rw-r--r-- | internal/watcher/debounce_test.go | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/internal/watcher/debounce_test.go b/internal/watcher/debounce_test.go index a93ba05..007dbd4 100644 --- a/internal/watcher/debounce_test.go +++ b/internal/watcher/debounce_test.go @@ -7,12 +7,18 @@ import ( ) func TestDebounceCollapsesNotifications(t *testing.T) { + done := make(chan struct{}, 1) var calls atomic.Int32 w := New(Config{ Debounce: 25 * time.Millisecond, OnChange: func() { calls.Add(1) + + select { + case done <- struct{}{}: + default: + } }, }) @@ -22,7 +28,11 @@ func TestDebounceCollapsesNotifications(t *testing.T) { w.notify() } - time.Sleep(75 * time.Millisecond) + select { + case <-done: + case <-time.After(time.Second): + t.Fatal("timed out waiting for callback") + } if got := calls.Load(); got != 1 { t.Fatalf("expected 1 callback, got %d", got) @@ -30,12 +40,18 @@ func TestDebounceCollapsesNotifications(t *testing.T) { } func TestDebounceSeparateBursts(t *testing.T) { + done := make(chan struct{}, 2) var calls atomic.Int32 w := New(Config{ Debounce: 20 * time.Millisecond, OnChange: func() { calls.Add(1) + + select { + case done <- struct{}{}: + default: + } }, }) @@ -43,11 +59,19 @@ func TestDebounceSeparateBursts(t *testing.T) { w.notify() - time.Sleep(40 * time.Millisecond) + select { + case <-done: + case <-time.After(time.Second): + t.Fatal("timed out waiting for first callback") + } w.notify() - time.Sleep(40 * time.Millisecond) + select { + case <-done: + case <-time.After(time.Second): + t.Fatal("timed out waiting for second callback") + } if got := calls.Load(); got != 2 { t.Fatalf("expected 2 callbacks, got %d", got) |