nezha/cmd/dashboard/controller/ws_test.go
naiba f212144310
Some checks are pending
CodeQL / Analyze (go) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Contributors / contributors (push) Waiting to run
Sync / sync-to-jihulab (push) Waiting to run
Run Tests / tests (macos) (push) Waiting to run
Run Tests / tests (ubuntu) (push) Waiting to run
Run Tests / tests (windows) (push) Waiting to run
feat: add online user count
2024-12-21 10:59:05 +08:00

27 lines
527 B
Go

package controller
import (
"sync/atomic"
"testing"
)
func TestWs(t *testing.T) {
onlineUsers := new(atomic.Uint64)
onlineUsers.Add(1)
if onlineUsers.Load() != 1 {
t.Error("onlineUsers.Add(1) failed")
}
onlineUsers.Add(1)
if onlineUsers.Load() != 2 {
t.Error("onlineUsers.Add(1) failed")
}
onlineUsers.Add(^uint64(0))
if onlineUsers.Load() != 1 {
t.Error("onlineUsers.Add(^uint64(0)) failed")
}
onlineUsers.Add(^uint64(0))
if onlineUsers.Load() != 0 {
t.Error("onlineUsers.Add(^uint64(0)) failed")
}
}