-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwormhole_lifecycle_internal_test.go
More file actions
55 lines (47 loc) · 1.15 KB
/
Copy pathwormhole_lifecycle_internal_test.go
File metadata and controls
55 lines (47 loc) · 1.15 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
package wormhole
import (
"context"
"sync"
"testing"
)
func TestRequestAdmissionIsClosedBeforeShutdownWaits(t *testing.T) {
client := New(WithDiscovery(false))
const workers = 32
start := make(chan struct{})
var workersWG sync.WaitGroup
workersWG.Add(workers)
for range workers {
go func() {
defer workersWG.Done()
<-start
for client.trackRequest() {
client.untrackRequest()
}
}()
}
close(start)
if err := client.Shutdown(context.Background()); err != nil {
t.Fatalf("shutdown: %v", err)
}
workersWG.Wait()
if client.trackRequest() {
client.untrackRequest()
t.Fatal("request admitted after shutdown")
}
}
func TestSweepIdempotencyCache(t *testing.T) {
client := New(WithDiscovery(false))
client.idempotencyMu.Lock()
if client.idempotencyCache == nil {
client.idempotencyCache = make(map[string]*idempotencyEntry)
}
client.idempotencyCache["expired-key"] = &idempotencyEntry{}
client.idempotencyMu.Unlock()
client.sweepIdempotencyCache()
client.idempotencyMu.Lock()
_, exists := client.idempotencyCache["expired-key"]
client.idempotencyMu.Unlock()
if exists {
t.Fatal("expired-key was not swept from cache")
}
}