mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-15 11:21:04 +01:00
35 lines
612 B
Go
35 lines
612 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestServerPicker_UnavailableServers(t *testing.T) {
|
|
connectionTimeout = 5 * time.Second
|
|
|
|
sp := ServerPicker{
|
|
TokenStore: nil,
|
|
PeerID: "test",
|
|
}
|
|
sp.ServerURLs.Store([]string{"rel://dummy1", "rel://dummy2"})
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout+1)
|
|
defer cancel()
|
|
|
|
go func() {
|
|
_, err := sp.PickServer(ctx)
|
|
if err == nil {
|
|
t.Error(err)
|
|
}
|
|
cancel()
|
|
}()
|
|
|
|
<-ctx.Done()
|
|
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
|
|
t.Errorf("PickServer() took too long to complete")
|
|
}
|
|
}
|