mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-22 03:10:42 +08:00
将 webServiceCache 扩展为通用 serviceCache,所有指纹识别结果 统一缓存,插件匹配时端口不命中则回退到服务名称匹配。 删除多余的 service_cache.go,复用已有的 ServiceInfo 体系。 补充 nil 防御、Explicit 标记、大量单元/集成/回归测试。
47 lines
942 B
Go
47 lines
942 B
Go
package services
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func TestProtocolIDsAreConcurrentSafe(t *testing.T) {
|
|
const workers = 64
|
|
const perWorker = 64
|
|
|
|
tests := []struct {
|
|
name string
|
|
next func() uint32
|
|
}{
|
|
{"mongodb", nextRequestID},
|
|
{"kafka", func() uint32 { return uint32(nextKafkaCorrelationID()) }},
|
|
{"cassandra", func() uint32 { return uint32(nextCQLStreamID()) }},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
var wg sync.WaitGroup
|
|
values := make(chan uint32, workers*perWorker)
|
|
for i := 0; i < workers; i++ {
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
for j := 0; j < perWorker; j++ {
|
|
values <- tt.next()
|
|
}
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
close(values)
|
|
|
|
seen := make(map[uint32]struct{}, workers*perWorker)
|
|
for value := range values {
|
|
if _, ok := seen[value]; ok {
|
|
t.Fatalf("duplicate protocol id %d", value)
|
|
}
|
|
seen[value] = struct{}{}
|
|
}
|
|
})
|
|
}
|
|
}
|