-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexport_test.go
More file actions
71 lines (53 loc) · 1.75 KB
/
Copy pathexport_test.go
File metadata and controls
71 lines (53 loc) · 1.75 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
62
63
64
65
66
67
68
69
70
71
package king
import (
"context"
"github.com/quic-go/quic-go"
)
// SetQUICConn sets a QUIC connection for a service ID (test helper).
func (tunnelSrv *TunnelServer) SetQUICConn(serviceID string, conn *quic.Conn) {
tunnelSrv.mu.Lock()
defer tunnelSrv.mu.Unlock()
tunnelSrv.quicConns[serviceID] = conn
}
// GetServiceAuth returns the service auth and whether it exists (test helper).
func (tunnelSrv *TunnelServer) GetServiceAuth(serviceID string) (ServiceAuth, bool) {
tunnelSrv.mu.RLock()
defer tunnelSrv.mu.RUnlock()
auth, exists := tunnelSrv.services[serviceID]
return auth, exists
}
// ServiceCount returns the number of registered services (test helper).
func (tunnelSrv *TunnelServer) ServiceCount() int {
tunnelSrv.mu.RLock()
defer tunnelSrv.mu.RUnlock()
return len(tunnelSrv.services)
}
// SetServiceAuth sets a service auth entry (test helper).
func (tunnelSrv *TunnelServer) SetServiceAuth(serviceID string, auth ServiceAuth) {
tunnelSrv.mu.Lock()
defer tunnelSrv.mu.Unlock()
tunnelSrv.services[serviceID] = auth
}
// RemoveQUICConn removes a QUIC connection and signals drainNotify (test helper).
func (tunnelSrv *TunnelServer) RemoveQUICConn(serviceID string) {
tunnelSrv.mu.Lock()
delete(tunnelSrv.quicConns, serviceID)
empty := len(tunnelSrv.quicConns) == 0
tunnelSrv.mu.Unlock()
if empty {
select {
case tunnelSrv.drainNotify <- struct{}{}:
default:
}
}
}
// QUICConnCount returns the number of QUIC connections (test helper).
func (tunnelSrv *TunnelServer) QUICConnCount() int {
tunnelSrv.mu.RLock()
defer tunnelSrv.mu.RUnlock()
return len(tunnelSrv.quicConns)
}
// WaitForDrain exposes the private waitForDrain method (test helper).
func (tunnelSrv *TunnelServer) WaitForDrain(ctx context.Context) {
tunnelSrv.waitForDrain(ctx)
}