Skip to content

Commit

Permalink
count nodes after each step in relogin tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Jan 26, 2025
1 parent 4a72c19 commit 5ffe036
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 7 deletions.
40 changes: 37 additions & 3 deletions integration/auth_web_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import (
"strings"
"testing"

v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/juanfont/headscale/integration/hsic"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var errParseAuthPage = errors.New("failed to parse auth page")
Expand Down Expand Up @@ -106,6 +109,25 @@ func TestAuthWebFlowLogoutAndRelogin(t *testing.T) {
success := pingAllHelper(t, allClients, allAddrs)
t.Logf("%d successful pings out of %d", success, len(allClients)*len(allIps))

headscale, err := scenario.Headscale()
assertNoErrGetHeadscale(t, err)

var listNodes []v1.Node
err = executeAndUnmarshal(headscale,
[]string{
"headscale",
"nodes",
"list",
"--output",
"json",
},
&listNodes,
)
assertNoErr(t, err)
assert.Equal(t, len(listNodes), len(allClients))
nodeCountBeforeLogout := len(listNodes)
t.Logf("node count before logout: %d", nodeCountBeforeLogout)

clientIPs := make(map[TailscaleClient][]netip.Addr)
for _, client := range allClients {
ips, err := client.IPs()
Expand All @@ -127,9 +149,6 @@ func TestAuthWebFlowLogoutAndRelogin(t *testing.T) {

t.Logf("all clients logged out")

headscale, err := scenario.Headscale()
assertNoErrGetHeadscale(t, err)

for userName := range spec {
err = scenario.runTailscaleUp(userName, headscale.GetEndpoint())
if err != nil {
Expand All @@ -152,6 +171,21 @@ func TestAuthWebFlowLogoutAndRelogin(t *testing.T) {
success = pingAllHelper(t, allClients, allAddrs)
t.Logf("%d successful pings out of %d", success, len(allClients)*len(allIps))

listNodes = nil
err = executeAndUnmarshal(headscale,
[]string{
"headscale",
"nodes",
"list",
"--output",
"json",
},
&listNodes,
)
assertNoErr(t, err)
require.Equal(t, nodeCountBeforeLogout, len(listNodes))
t.Logf("node count first login: %d, after relogin: %d", nodeCountBeforeLogout, len(listNodes))

for _, client := range allClients {
ips, err := client.IPs()
if err != nil {
Expand Down
37 changes: 34 additions & 3 deletions integration/general_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ func TestAuthKeyLogoutAndRelogin(t *testing.T) {
clientIPs[client] = ips
}

headscale, err := scenario.Headscale()
assertNoErrGetHeadscale(t, err)

var listNodes []v1.Node
err = executeAndUnmarshal(headscale,
[]string{
"headscale",
"nodes",
"list",
"--output",
"json",
},
&listNodes,
)
assertNoErr(t, err)
assert.Equal(t, len(listNodes), len(allClients))
nodeCountBeforeLogout := len(listNodes)
t.Logf("node count before logout: %d", nodeCountBeforeLogout)

for _, client := range allClients {
err := client.Logout()
if err != nil {
Expand All @@ -159,9 +178,6 @@ func TestAuthKeyLogoutAndRelogin(t *testing.T) {

t.Logf("all clients logged out")

headscale, err := scenario.Headscale()
assertNoErrGetHeadscale(t, err)

// if the server is not running with HTTPS, we have to wait a bit before
// reconnection as the newest Tailscale client has a measure that will only
// reconnect over HTTPS if they saw a noise connection previously.
Expand Down Expand Up @@ -201,6 +217,21 @@ func TestAuthKeyLogoutAndRelogin(t *testing.T) {
success := pingAllHelper(t, allClients, allAddrs)
t.Logf("%d successful pings out of %d", success, len(allClients)*len(allIps))

listNodes = nil
err = executeAndUnmarshal(headscale,
[]string{
"headscale",
"nodes",
"list",
"--output",
"json",
},
&listNodes,
)
assertNoErr(t, err)
require.Equal(t, nodeCountBeforeLogout, len(listNodes))
t.Logf("node count first login: %d, after relogin: %d", nodeCountBeforeLogout, len(listNodes))

for _, client := range allClients {
ips, err := client.IPs()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion integration/hsic/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func DefaultConfigEnv() map[string]string {
"HEADSCALE_POLICY_PATH": "",
"HEADSCALE_DATABASE_TYPE": "sqlite",
"HEADSCALE_DATABASE_SQLITE_PATH": "/tmp/integration_test_db.sqlite3",
"HEADSCALE_DATABASE_DEBUG": "1",
"HEADSCALE_DATABASE_DEBUG": "0",
"HEADSCALE_DATABASE_GORM_SLOW_THRESHOLD": "1",
"HEADSCALE_EPHEMERAL_NODE_INACTIVITY_TIMEOUT": "30m",
"HEADSCALE_PREFIXES_V4": "100.64.0.0/10",
Expand Down

0 comments on commit 5ffe036

Please sign in to comment.