integration: make timestamp const

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby
2025-09-08 11:18:42 +02:00
committed by Kristoffer Dalby
parent 476f30ab20
commit 4893cdac74
5 changed files with 42 additions and 29 deletions

View File

@@ -34,8 +34,6 @@ import (
"tailscale.com/wgengine/filter"
)
const timestampFormat = "15:04:05.000"
var allPorts = filter.PortRange{First: 0, Last: 0xffff}
// This test is both testing the routes command and the propagation of
@@ -305,7 +303,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
t.Logf("%s (%s) picked as client", client.Hostname(), client.MustID())
t.Logf("=== Initial Route Advertisement - Setting up HA configuration with 3 routers ===")
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" - Router 1 (%s): Advertising route %s - will become PRIMARY when approved", subRouter1.Hostname(), pref.String())
t.Logf(" - Router 2 (%s): Advertising route %s - will be STANDBY when approved", subRouter2.Hostname(), pref.String())
t.Logf(" - Router 3 (%s): Advertising route %s - will be STANDBY when approved", subRouter3.Hostname(), pref.String())
@@ -363,7 +361,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
// Helper function to check test failure and print route map if needed
checkFailureAndPrintRoutes := func(t *testing.T, client TailscaleClient) {
if t.Failed() {
t.Logf("[%s] Test failed at this checkpoint", time.Now().Format(timestampFormat))
t.Logf("[%s] Test failed at this checkpoint", time.Now().Format(TimestampFormat))
status, err := client.Status()
if err == nil {
printCurrentRouteMap(t, xmaps.Values(status.Peer)...)
@@ -382,7 +380,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
// Enable route on node 1
t.Logf("=== Approving route on router 1 (%s) - Single router mode (no HA yet) ===", subRouter1.Hostname())
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Expected: Router 1 becomes PRIMARY with route %s active", pref.String())
t.Logf(" Expected: Routers 2 & 3 remain with advertised but unapproved routes")
t.Logf(" Expected: Client can access webservice through router 1 only")
@@ -445,7 +443,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
}, propagationTime, 200*time.Millisecond, "Verifying Router 1 is PRIMARY with routes after approval")
t.Logf("=== Validating connectivity through PRIMARY router 1 (%s) to webservice at %s ===", must.Get(subRouter1.IPv4()).String(), webip.String())
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Expected: Traffic flows through router 1 as it's the only approved route")
assert.EventuallyWithT(t, func(c *assert.CollectT) {
result, err := client.Curl(weburl)
@@ -478,7 +476,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
// Enable route on node 2, now we will have a HA subnet router
t.Logf("=== Enabling High Availability by approving route on router 2 (%s) ===", subRouter2.Hostname())
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Current state: Router 1 is PRIMARY and actively serving traffic")
t.Logf(" Expected: Router 2 becomes STANDBY (approved but not primary)")
t.Logf(" Expected: Router 1 remains PRIMARY (no flapping - stability preferred)")
@@ -556,7 +554,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
checkFailureAndPrintRoutes(t, client)
t.Logf("=== Validating HA configuration - Router 1 PRIMARY, Router 2 STANDBY ===")
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Current routing: Traffic through router 1 (%s) to %s", must.Get(subRouter1.IPv4()), webip.String())
t.Logf(" Expected: Router 1 continues to handle all traffic (no change from before)")
t.Logf(" Expected: Router 2 is ready to take over if router 1 fails")
@@ -593,7 +591,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
// Enable route on node 3, now we will have a second standby and all will
// be enabled.
t.Logf("=== Adding second STANDBY router by approving route on router 3 (%s) ===", subRouter3.Hostname())
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Current state: Router 1 PRIMARY, Router 2 STANDBY")
t.Logf(" Expected: Router 3 becomes second STANDBY (approved but not primary)")
t.Logf(" Expected: Router 1 remains PRIMARY, Router 2 remains first STANDBY")
@@ -699,7 +697,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
// Take down the current primary
t.Logf("=== FAILOVER TEST: Taking down PRIMARY router 1 (%s) ===", subRouter1.Hostname())
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Current state: Router 1 PRIMARY (serving traffic), Router 2 & 3 STANDBY")
t.Logf(" Action: Shutting down router 1 to simulate failure")
t.Logf(" Expected: Router 2 (%s) should automatically become new PRIMARY", subRouter2.Hostname())
@@ -777,7 +775,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
// Take down subnet router 2, leaving none available
t.Logf("=== FAILOVER TEST: Taking down NEW PRIMARY router 2 (%s) ===", subRouter2.Hostname())
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Current state: Router 1 OFFLINE, Router 2 PRIMARY (serving traffic), Router 3 STANDBY")
t.Logf(" Action: Shutting down router 2 to simulate cascading failure")
t.Logf(" Expected: Router 3 (%s) should become new PRIMARY (last remaining router)", subRouter3.Hostname())
@@ -847,7 +845,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
// Bring up subnet router 1, making the route available from there.
t.Logf("=== RECOVERY TEST: Bringing router 1 (%s) back online ===", subRouter1.Hostname())
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Current state: Router 1 OFFLINE, Router 2 OFFLINE, Router 3 PRIMARY (only router)")
t.Logf(" Action: Starting router 1 to restore HA capability")
t.Logf(" Expected: Router 3 remains PRIMARY (stability - no unnecessary failover)")
@@ -925,7 +923,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
// Bring up subnet router 2, should result in no change.
t.Logf("=== FULL RECOVERY TEST: Bringing router 2 (%s) back online ===", subRouter2.Hostname())
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Current state: Router 1 STANDBY, Router 2 OFFLINE, Router 3 PRIMARY")
t.Logf(" Action: Starting router 2 to restore full HA (3 routers)")
t.Logf(" Expected: Router 3 (%s) remains PRIMARY (stability - avoid unnecessary failovers)", subRouter3.Hostname())
@@ -1004,7 +1002,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
checkFailureAndPrintRoutes(t, client)
t.Logf("=== ROUTE DISABLE TEST: Removing approved route from PRIMARY router 3 (%s) ===", subRouter3.Hostname())
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Current state: Router 1 STANDBY, Router 2 STANDBY, Router 3 PRIMARY")
t.Logf(" Action: Disabling route approval on router 3 (route still advertised but not approved)")
t.Logf(" Expected: Router 1 (%s) should become new PRIMARY (lowest ID with approved route)", subRouter1.Hostname())
@@ -1090,7 +1088,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
// Disable the route of subnet router 1, making it failover to 2
t.Logf("=== ROUTE DISABLE TEST: Removing approved route from NEW PRIMARY router 1 (%s) ===", subRouter1.Hostname())
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Current state: Router 1 PRIMARY, Router 2 STANDBY, Router 3 advertised-only")
t.Logf(" Action: Disabling route approval on router 1")
t.Logf(" Expected: Router 2 (%s) should become new PRIMARY (only remaining approved route)", subRouter2.Hostname())
@@ -1176,7 +1174,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
// enable the route of subnet router 1, no change expected
t.Logf("=== ROUTE RE-ENABLE TEST: Re-approving route on router 1 (%s) ===", subRouter1.Hostname())
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Current state: Router 1 advertised-only, Router 2 PRIMARY, Router 3 advertised-only")
t.Logf(" Action: Re-enabling route approval on router 1")
t.Logf(" Expected: Router 2 (%s) remains PRIMARY (stability - no unnecessary flapping)", subRouter2.Hostname())
@@ -1260,7 +1258,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
// Enable route on node 3, we now have all routes re-enabled
t.Logf("=== ROUTE RE-ENABLE TEST: Re-approving route on router 3 (%s) - Full HA Restoration ===", subRouter3.Hostname())
t.Logf("[%s] Starting test section", time.Now().Format(timestampFormat))
t.Logf("[%s] Starting test section", time.Now().Format(TimestampFormat))
t.Logf(" Current state: Router 1 STANDBY, Router 2 PRIMARY, Router 3 advertised-only")
t.Logf(" Action: Re-enabling route approval on router 3")
t.Logf(" Expected: Router 2 (%s) remains PRIMARY (stability preferred)", subRouter2.Hostname())