summaryrefslogtreecommitdiff
path: root/internal/lsp/debounce_throttle_more_test.go
blob: 7657cabc4b360a78596c63841f29e38223eb7bcb (plain)
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
32
33
34
35
36
37
38
39
package lsp

import (
	"context"
	"testing"
	"time"
)

func TestWaitForDebounce_WaitsRoughlyDebounce(t *testing.T) {
	s := newTestServer()
	cfg := s.cfg
	cfg.CompletionDebounceMs = 20
	s.cfg = cfg
	s.mu.Lock()
	s.lastInput = time.Now()
	s.mu.Unlock()
	start := time.Now()
	s.waitForDebounce(context.Background())
	if elapsed := time.Since(start); elapsed < 15*time.Millisecond {
		t.Fatalf("debounce did not wait long enough: %v", elapsed)
	}
}

func TestWaitForThrottle_WaitsRoughlyInterval(t *testing.T) {
	s := newTestServer()
	cfg := s.cfg
	cfg.CompletionThrottleMs = 20
	s.cfg = cfg
	s.mu.Lock()
	s.lastLLMCall = time.Now()
	s.mu.Unlock()
	start := time.Now()
	if !s.waitForThrottle(context.Background()) {
		t.Fatalf("waitForThrottle returned false")
	}
	if elapsed := time.Since(start); elapsed < 15*time.Millisecond {
		t.Fatalf("throttle did not wait long enough: %v", elapsed)
	}
}