Refactor healthcheck sender and receiver to use configurable options (#4433)

This commit is contained in:
Zoltan Papp
2025-09-12 09:31:03 +02:00
committed by GitHub
parent cf7f6c355f
commit 0c6f671a7c
10 changed files with 186 additions and 176 deletions

View File

@@ -78,9 +78,10 @@ func NewManager(ctx context.Context, serverURLs []string, peerID string, mtu uin
tokenStore: tokenStore,
mtu: mtu,
serverPicker: &ServerPicker{
TokenStore: tokenStore,
PeerID: peerID,
MTU: mtu,
TokenStore: tokenStore,
PeerID: peerID,
MTU: mtu,
ConnectionTimeout: defaultConnectionTimeout,
},
relayClients: make(map[string]*RelayTrack),
onDisconnectedListeners: make(map[string]*list.List),

View File

@@ -13,11 +13,8 @@ import (
)
const (
maxConcurrentServers = 7
)
var (
connectionTimeout = 30 * time.Second
maxConcurrentServers = 7
defaultConnectionTimeout = 30 * time.Second
)
type connResult struct {
@@ -27,14 +24,15 @@ type connResult struct {
}
type ServerPicker struct {
TokenStore *auth.TokenStore
ServerURLs atomic.Value
PeerID string
MTU uint16
TokenStore *auth.TokenStore
ServerURLs atomic.Value
PeerID string
MTU uint16
ConnectionTimeout time.Duration
}
func (sp *ServerPicker) PickServer(parentCtx context.Context) (*Client, error) {
ctx, cancel := context.WithTimeout(parentCtx, connectionTimeout)
ctx, cancel := context.WithTimeout(parentCtx, sp.ConnectionTimeout)
defer cancel()
totalServers := len(sp.ServerURLs.Load().([]string))

View File

@@ -8,15 +8,15 @@ import (
)
func TestServerPicker_UnavailableServers(t *testing.T) {
connectionTimeout = 5 * time.Second
timeout := 5 * time.Second
sp := ServerPicker{
TokenStore: nil,
PeerID: "test",
TokenStore: nil,
PeerID: "test",
ConnectionTimeout: timeout,
}
sp.ServerURLs.Store([]string{"rel://dummy1", "rel://dummy2"})
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout+1)
ctx, cancel := context.WithTimeout(context.Background(), timeout+1)
defer cancel()
go func() {