test embedded derp with derp updater, check client health (#2030)
This commit is contained in:
parent
948d53f934
commit
ece907d878
2 changed files with 58 additions and 11 deletions
|
@ -125,10 +125,5 @@ func GetDERPMap(cfg types.DERPConfig) *tailcfg.DERPMap {
|
||||||
|
|
||||||
log.Trace().Interface("derpMap", derpMap).Msg("DERPMap loaded")
|
log.Trace().Interface("derpMap", derpMap).Msg("DERPMap loaded")
|
||||||
|
|
||||||
if len(derpMap.Regions) == 0 {
|
|
||||||
log.Warn().
|
|
||||||
Msg("DERP map is empty, not a single DERP map datasource was loaded correctly or contained a region")
|
|
||||||
}
|
|
||||||
|
|
||||||
return derpMap
|
return derpMap
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/juanfont/headscale/hscontrol/util"
|
"github.com/juanfont/headscale/hscontrol/util"
|
||||||
"github.com/juanfont/headscale/integration/dockertestutil"
|
"github.com/juanfont/headscale/integration/dockertestutil"
|
||||||
|
@ -33,8 +35,7 @@ func TestDERPServerScenario(t *testing.T) {
|
||||||
defer scenario.Shutdown()
|
defer scenario.Shutdown()
|
||||||
|
|
||||||
spec := map[string]int{
|
spec := map[string]int{
|
||||||
"user1": 10,
|
"user1": len(MustTestVersions),
|
||||||
// "user1": len(MustTestVersions),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = scenario.CreateHeadscaleEnv(
|
err = scenario.CreateHeadscaleEnv(
|
||||||
|
@ -44,24 +45,75 @@ func TestDERPServerScenario(t *testing.T) {
|
||||||
hsic.WithEmbeddedDERPServerOnly(),
|
hsic.WithEmbeddedDERPServerOnly(),
|
||||||
hsic.WithTLS(),
|
hsic.WithTLS(),
|
||||||
hsic.WithHostnameAsServerURL(),
|
hsic.WithHostnameAsServerURL(),
|
||||||
|
hsic.WithConfigEnv(map[string]string{
|
||||||
|
"HEADSCALE_DERP_AUTO_UPDATE_ENABLED": "true",
|
||||||
|
"HEADSCALE_DERP_UPDATE_FREQUENCY": "10s",
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
assertNoErrHeadscaleEnv(t, err)
|
assertNoErrHeadscaleEnv(t, err)
|
||||||
|
|
||||||
allClients, err := scenario.ListTailscaleClients()
|
allClients, err := scenario.ListTailscaleClients()
|
||||||
assertNoErrListClients(t, err)
|
assertNoErrListClients(t, err)
|
||||||
|
|
||||||
allIps, err := scenario.ListTailscaleClientsIPs()
|
|
||||||
assertNoErrListClientIPs(t, err)
|
|
||||||
|
|
||||||
err = scenario.WaitForTailscaleSync()
|
err = scenario.WaitForTailscaleSync()
|
||||||
assertNoErrSync(t, err)
|
assertNoErrSync(t, err)
|
||||||
|
|
||||||
allHostnames, err := scenario.ListTailscaleClientsFQDNs()
|
allHostnames, err := scenario.ListTailscaleClientsFQDNs()
|
||||||
assertNoErrListFQDN(t, err)
|
assertNoErrListFQDN(t, err)
|
||||||
|
|
||||||
|
for _, client := range allClients {
|
||||||
|
status, err := client.Status()
|
||||||
|
assertNoErr(t, err)
|
||||||
|
|
||||||
|
for _, health := range status.Health {
|
||||||
|
if strings.Contains(health, "could not connect to any relay server") {
|
||||||
|
t.Errorf("expected to be connected to derp, found: %s", health)
|
||||||
|
}
|
||||||
|
if strings.Contains(health, "could not connect to the 'Headscale Embedded DERP' relay server.") {
|
||||||
|
t.Errorf("expected to be connected to derp, found: %s", health)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
success := pingDerpAllHelper(t, allClients, allHostnames)
|
success := pingDerpAllHelper(t, allClients, allHostnames)
|
||||||
|
|
||||||
t.Logf("%d successful pings out of %d", success, len(allClients)*len(allIps))
|
for _, client := range allClients {
|
||||||
|
status, err := client.Status()
|
||||||
|
assertNoErr(t, err)
|
||||||
|
|
||||||
|
for _, health := range status.Health {
|
||||||
|
if strings.Contains(health, "could not connect to any relay server") {
|
||||||
|
t.Errorf("expected to be connected to derp, found: %s", health)
|
||||||
|
}
|
||||||
|
if strings.Contains(health, "could not connect to the 'Headscale Embedded DERP' relay server.") {
|
||||||
|
t.Errorf("expected to be connected to derp, found: %s", health)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("Run 1: %d successful pings out of %d", success, len(allClients)*len(allHostnames))
|
||||||
|
|
||||||
|
// Let the DERP updater run a couple of times to ensure it does not
|
||||||
|
// break the DERPMap.
|
||||||
|
time.Sleep(30 * time.Second)
|
||||||
|
|
||||||
|
success = pingDerpAllHelper(t, allClients, allHostnames)
|
||||||
|
|
||||||
|
for _, client := range allClients {
|
||||||
|
status, err := client.Status()
|
||||||
|
assertNoErr(t, err)
|
||||||
|
|
||||||
|
for _, health := range status.Health {
|
||||||
|
if strings.Contains(health, "could not connect to any relay server") {
|
||||||
|
t.Errorf("expected to be connected to derp, found: %s", health)
|
||||||
|
}
|
||||||
|
if strings.Contains(health, "could not connect to the 'Headscale Embedded DERP' relay server.") {
|
||||||
|
t.Errorf("expected to be connected to derp, found: %s", health)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("Run2: %d successful pings out of %d", success, len(allClients)*len(allHostnames))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EmbeddedDERPServerScenario) CreateHeadscaleEnv(
|
func (s *EmbeddedDERPServerScenario) CreateHeadscaleEnv(
|
||||||
|
|
Loading…
Reference in a new issue