aboutsummaryrefslogtreecommitdiff
path: root/hotline/server_test.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2026-05-28 16:22:24 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2026-05-28 16:22:24 -0700
commitb772019454ebb804c313e717ae98eb68430e780e (patch)
treea12ffc1e5de4d7e1612edaea03174043a6c55784 /hotline/server_test.go
parent2f46f87177234070044b5304ca3e0db471699ad8 (diff)
Refactor Stats to typed keys and fix peak-tracking race
Replace the map-backed Stats counter with a fixed [numStats]int array indexed by a new StatKey enum, eliminating the hand-maintained map initialization and the parallel string-keyed Values() map. Fix a check-then-act race in the connection peak tracking: the old Get-then-Set across two lock acquisitions could let concurrent connections clobber each other's update. The new atomic Max method does the compare-and-set under a single lock. Values() now returns a typed StatValues struct whose JSON tags preserve the existing /api/v1/stats wire format.
Diffstat (limited to 'hotline/server_test.go')
-rw-r--r--hotline/server_test.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/hotline/server_test.go b/hotline/server_test.go
index 4bb3669..bebde8f 100644
--- a/hotline/server_test.go
+++ b/hotline/server_test.go
@@ -759,9 +759,9 @@ func TestServer_CurrentStats(t *testing.T) {
srv := &Server{Stats: stats}
result := srv.CurrentStats()
- assert.Equal(t, 1, result["CurrentlyConnected"])
- assert.Equal(t, 2, result["DownloadCounter"])
- assert.Equal(t, 0, result["UploadsInProgress"])
+ assert.Equal(t, 1, result.CurrentlyConnected)
+ assert.Equal(t, 2, result.DownloadCounter)
+ assert.Equal(t, 0, result.UploadsInProgress)
}
func TestServer_sendTransaction(t *testing.T) {