feat(tests): add TestTransportLeak to check for goroutine leaks in transport instances
Some checks failed
Bearer / scan (pull_request) Successful in 43s
Go Build Test / Build (darwin, amd64) (pull_request) Successful in 41s
Go Benchmarks / Run Benchmarks (pull_request) Failing after 1m2s
Go Build Test / Build (linux, amd64) (pull_request) Successful in 31s
Go Build Test / Build (windows, amd64) (pull_request) Successful in 38s
Go Build Test / Build (freebsd, amd64) (pull_request) Successful in 27s
Go Build Test / Build (freebsd, arm) (pull_request) Successful in 38s
Go Build Test / Build (linux, arm) (pull_request) Successful in 36s
Go Build Test / Build (darwin, arm64) (pull_request) Successful in 51s
Go Build Test / Build (windows, arm64) (pull_request) Successful in 38s
Go Build Test / Build (linux, arm64) (pull_request) Successful in 40s
Go Build Test / Build (windows, arm) (pull_request) Successful in 27s
Go Build Test / Build (freebsd, arm64) (pull_request) Successful in 49s
Go Test Multi-Platform / Test (ubuntu-latest, amd64) (pull_request) Failing after 58s
Go Build Test / Build (js, wasm) (pull_request) Successful in 21s
Go Test Multi-Platform / Test (ubuntu-latest, arm64) (pull_request) Failing after 1m16s
Go Revive Lint / lint (pull_request) Successful in 59s
Run Gosec / tests (pull_request) Successful in 1m20s

This commit is contained in:
2026-01-02 16:39:50 -06:00
parent 03753bf9bc
commit 548ec55248

View File

@@ -0,0 +1,40 @@
// SPDX-License-Identifier: 0BSD
// Copyright (c) 2024-2026 Sudo-Ivan / Quad4.io
package transport
import (
"runtime"
"testing"
"time"
"git.quad4.io/Networks/Reticulum-Go/pkg/common"
)
func TestTransportLeak(t *testing.T) {
// Baseline goroutine count
runtime.GC()
baseline := runtime.NumGoroutine()
cfg := &common.ReticulumConfig{}
// Create and close many transport instances
for i := 0; i < 100; i++ {
tr := NewTransport(cfg)
// Give it a tiny bit of time to start the goroutine
time.Sleep(1 * time.Millisecond)
tr.Close()
}
// Wait for goroutines to finish
time.Sleep(100 * time.Millisecond)
runtime.GC()
final := runtime.NumGoroutine()
// We allow a small margin for other system goroutines,
// but 100 leaks would be very obvious.
if final > baseline+5 {
t.Errorf("Potential goroutine leak: baseline %d, final %d", baseline, final)
}
}