Smail/backend/utils/id/logid_test.go
smail 44111ae659
Some checks are pending
Security Checks / security (push) Waiting to run
fix(id): 使用sync.Once与sync.RWMutex消除getLocalIP并发数据竞争
2026-10-18 13:22:19 +08:00

32 lines
495 B
Go

package id
import (
"sync"
"testing"
)
func TestGetLocalIPConcurrent(t *testing.T) {
const goroutines = 50
const iterations = 100
var wg sync.WaitGroup
wg.Add(goroutines)
for i := 0; i < goroutines; i++ {
go func() {
defer wg.Done()
for j := 0; j < iterations; j++ {
ip := getLocalIP()
if ip == "" {
t.Errorf("getLocalIP returned empty")
}
logID := GenLogID()
if logID == "" {
t.Errorf("GenLogID returned empty")
}
}
}()
}
wg.Wait()
}