mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-09 20:10:27 +08:00
增加${requestId}变量
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package nodes
|
||||
|
||||
import (
|
||||
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"runtime"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHTTPRequest_httpRequestParseContentRange(t *testing.T) {
|
||||
@@ -53,3 +57,60 @@ func TestHTTPRequest_httpRequestParseContentRange(t *testing.T) {
|
||||
t.Log(set)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPRequest_httpRequestNextId(t *testing.T) {
|
||||
teaconst.NodeId = 123
|
||||
teaconst.NodeIdString = "123"
|
||||
t.Log(httpRequestNextId())
|
||||
t.Log(httpRequestNextId())
|
||||
t.Log(httpRequestNextId())
|
||||
time.Sleep(1 * time.Second)
|
||||
t.Log(httpRequestNextId())
|
||||
t.Log(httpRequestNextId())
|
||||
time.Sleep(1 * time.Second)
|
||||
t.Log(httpRequestNextId())
|
||||
}
|
||||
|
||||
func TestHTTPRequest_httpRequestNextId_Concurrent(t *testing.T) {
|
||||
var m = map[string]bool{}
|
||||
var locker = sync.Mutex{}
|
||||
|
||||
var count = 4000
|
||||
var wg = &sync.WaitGroup{}
|
||||
wg.Add(count)
|
||||
|
||||
var countDuplicated = 0
|
||||
for i := 0; i < count; i++ {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
var requestId = httpRequestNextId()
|
||||
|
||||
locker.Lock()
|
||||
|
||||
_, ok := m[requestId]
|
||||
if ok {
|
||||
t.Log("duplicated:", requestId)
|
||||
countDuplicated++
|
||||
}
|
||||
|
||||
m[requestId] = true
|
||||
locker.Unlock()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
t.Log("ok", countDuplicated, "duplicated")
|
||||
|
||||
var a = assert.NewAssertion(t)
|
||||
a.IsTrue(countDuplicated == 0)
|
||||
}
|
||||
|
||||
func BenchmarkHTTPRequest_httpRequestNextId(b *testing.B) {
|
||||
runtime.GOMAXPROCS(1)
|
||||
|
||||
teaconst.NodeIdString = "123"
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = httpRequestNextId()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user