-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathcsc_coalesce_options_test.go
More file actions
61 lines (57 loc) · 2.53 KB
/
Copy pathcsc_coalesce_options_test.go
File metadata and controls
61 lines (57 loc) · 2.53 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package redis
import (
"testing"
"time"
)
// TestCSCCoalesceModeRejectsPinnedPublicly pins that the buggy "pinned" PROTOTYPE
// engine (no idle invalidation drain; can serve stale) is NOT selectable from the
// public ClientSideCacheCoalesceMode option — it falls back to "workers" — while
// the internal benchmark hook can still force it.
func TestCSCCoalesceModeRejectsPinnedPublicly(t *testing.T) {
if got := cscCoalesceMode(&Options{ClientSideCacheCoalesceMode: "pinned"}); got != "workers" {
t.Fatalf("public \"pinned\" => %q, want \"workers\"", got)
}
if got := cscCoalesceMode(&Options{ClientSideCacheCoalesceMode: "fullduplex"}); got != "fullduplex" {
t.Fatalf("\"fullduplex\" => %q, want \"fullduplex\"", got)
}
if got := cscCoalesceMode(&Options{ClientSideCacheCoalesceMode: ""}); got != "workers" {
t.Fatalf("\"\" => %q, want \"workers\"", got)
}
if got := cscCoalesceMode(nil); got != "workers" {
t.Fatalf("nil opt => %q, want \"workers\"", got)
}
cscForcePinned = true
defer func() { cscForcePinned = false }()
if got := cscCoalesceMode(&Options{ClientSideCacheCoalesceMode: "pinned"}); got != "pinned" {
t.Fatalf("forced \"pinned\" => %q, want \"pinned\" (benchmark hook)", got)
}
}
// TestUniversalOptionsSimpleCopiesCSCCoalesce guards that the new CSC miss-
// coalescing / invalidation-batching knobs reach a standalone Client through
// UniversalOptions.Simple() (they were previously Options-only, so UniversalClient
// users could not enable them).
func TestUniversalOptionsSimpleCopiesCSCCoalesce(t *testing.T) {
u := &UniversalOptions{
ClientSideCacheRefreshOnInvalidate: true,
ClientSideCacheCoalesceMisses: true,
ClientSideCacheCoalesceMode: "fullduplex",
ClientSideCacheCoalesceWorkers: 5,
ClientSideCacheInvalidationBatchWindow: 7 * time.Millisecond,
}
o := u.Simple()
if !o.ClientSideCacheRefreshOnInvalidate {
t.Error("Simple() dropped ClientSideCacheRefreshOnInvalidate")
}
if !o.ClientSideCacheCoalesceMisses {
t.Error("Simple() dropped ClientSideCacheCoalesceMisses")
}
if o.ClientSideCacheCoalesceMode != "fullduplex" {
t.Errorf("Simple() ClientSideCacheCoalesceMode = %q, want \"fullduplex\"", o.ClientSideCacheCoalesceMode)
}
if o.ClientSideCacheCoalesceWorkers != 5 {
t.Errorf("Simple() ClientSideCacheCoalesceWorkers = %d, want 5", o.ClientSideCacheCoalesceWorkers)
}
if o.ClientSideCacheInvalidationBatchWindow != 7*time.Millisecond {
t.Errorf("Simple() ClientSideCacheInvalidationBatchWindow = %v, want 7ms", o.ClientSideCacheInvalidationBatchWindow)
}
}