mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2026-12-03 17:46:44 +00:00
test(geo): 动态扩容 goroutine 堆栈快照
- 检测截断并扩容至 16 MiB 后再扫描完整 dump - 同步覆盖 util 与 ipgeo 两条 resolver scope 阻塞测试
This commit is contained in:
1 parent
75a5db6ffb
commit
a2cfb9a39f
2 files changed
+24
-4
No files matched your search
+12
-2
@@ -183,7 +183,7 @@ func TestGetSourceWithGeoDNSEmptyResolverUsesIsolatedScope(t *testing.T) {
|
||||
go observeEmptyGeoSourceScope(GetSourceWithGeoDNS("disable-geoip", ""), sourceStarted, sourceDone)
|
||||
<-sourceStarted
|
||||
|
||||
blocked, completed, earlyErr := waitForGeoSourceScopeBlock(sourceDone)
|
||||
blocked, completed, earlyErr := waitForGeoSourceScopeBlock(t, sourceDone)
|
||||
if completed {
|
||||
close(releaseDot)
|
||||
<-dotDone
|
||||
@@ -212,7 +212,9 @@ func observeEmptyGeoSourceScope(source Source, started chan<- struct{}, result c
|
||||
result <- err
|
||||
}
|
||||
|
||||
func waitForGeoSourceScopeBlock(result <-chan error) (blocked bool, completed bool, err error) {
|
||||
func waitForGeoSourceScopeBlock(t *testing.T, result <-chan error) (blocked bool, completed bool, err error) {
|
||||
t.Helper()
|
||||
const maxStackDumpSize = 16 << 20
|
||||
deadline := time.Now().Add(2 * time.Second)
|
||||
stack := make([]byte, 1<<20)
|
||||
for time.Now().Before(deadline) {
|
||||
@@ -222,6 +224,14 @@ func waitForGeoSourceScopeBlock(result <-chan error) (blocked bool, completed bo
|
||||
default:
|
||||
}
|
||||
n := runtime.Stack(stack, true)
|
||||
for n == len(stack) {
|
||||
if len(stack) >= maxStackDumpSize {
|
||||
t.Errorf("goroutine stack dump exceeded %d bytes", maxStackDumpSize)
|
||||
return false, false, err
|
||||
}
|
||||
stack = make([]byte, min(len(stack)*2, maxStackDumpSize))
|
||||
n = runtime.Stack(stack, true)
|
||||
}
|
||||
for _, goroutine := range bytes.Split(stack[:n], []byte("\n\n")) {
|
||||
if bytes.Contains(goroutine, []byte("observeEmptyGeoSourceScope")) &&
|
||||
bytes.Contains(goroutine, []byte("[sync.Mutex.Lock")) {
|
||||
|
||||
@@ -318,7 +318,7 @@ func TestWithGeoDNSResolver_EmptyScopeIsolatedFromConcurrentDoT(t *testing.T) {
|
||||
go observeEmptyGeoResolverScope(emptyStarted, emptyDone, emptyPolicy)
|
||||
<-emptyStarted
|
||||
|
||||
blocked, completed, got := waitForGeoResolverScopeBlock(emptyPolicy)
|
||||
blocked, completed, got := waitForGeoResolverScopeBlock(t, emptyPolicy)
|
||||
if completed {
|
||||
close(releaseDot)
|
||||
<-dotDone
|
||||
@@ -361,7 +361,9 @@ func observeEmptyGeoResolverScope(started chan<- struct{}, done chan<- struct{},
|
||||
})
|
||||
}
|
||||
|
||||
func waitForGeoResolverScopeBlock(result <-chan geoResolverScopeObservation) (blocked bool, completed bool, got geoResolverScopeObservation) {
|
||||
func waitForGeoResolverScopeBlock(t *testing.T, result <-chan geoResolverScopeObservation) (blocked bool, completed bool, got geoResolverScopeObservation) {
|
||||
t.Helper()
|
||||
const maxStackDumpSize = 16 << 20
|
||||
deadline := time.Now().Add(2 * time.Second)
|
||||
stack := make([]byte, 1<<20)
|
||||
for time.Now().Before(deadline) {
|
||||
@@ -371,6 +373,14 @@ func waitForGeoResolverScopeBlock(result <-chan geoResolverScopeObservation) (bl
|
||||
default:
|
||||
}
|
||||
n := runtime.Stack(stack, true)
|
||||
for n == len(stack) {
|
||||
if len(stack) >= maxStackDumpSize {
|
||||
t.Errorf("goroutine stack dump exceeded %d bytes", maxStackDumpSize)
|
||||
return false, false, got
|
||||
}
|
||||
stack = make([]byte, min(len(stack)*2, maxStackDumpSize))
|
||||
n = runtime.Stack(stack, true)
|
||||
}
|
||||
for _, goroutine := range bytes.Split(stack[:n], []byte("\n\n")) {
|
||||
if bytes.Contains(goroutine, []byte("observeEmptyGeoResolverScope")) &&
|
||||
bytes.Contains(goroutine, []byte("[sync.Mutex.Lock")) {
|
||||
|
||||
Reference in new issue
Block a user