Files
Reticulum-Go/pkg/transport/leak_test.go
Sudo-Ivan f80d50c27b
All checks were successful
Go Build Test / Build (windows, arm) (pull_request) Successful in 9m26s
Go Build Test / Build (darwin, arm64) (pull_request) Successful in 9m24s
Bearer / scan (pull_request) Successful in 9s
Go Benchmarks / Run Benchmarks (pull_request) Successful in 55s
Go Build Test / Build (linux, arm64) (pull_request) Successful in 39s
Go Build Test / Build (windows, arm64) (pull_request) Successful in 38s
Go Build Test / Build (windows, amd64) (pull_request) Successful in 44s
Go Build Test / Build (linux, arm) (pull_request) Successful in 42s
Go Build Test / Build (freebsd, amd64) (pull_request) Successful in 46s
Go Build Test / Build (freebsd, arm64) (pull_request) Successful in 30s
Go Build Test / Build (js, wasm) (pull_request) Successful in 34s
Go Test Multi-Platform / Test (ubuntu-latest, arm64) (pull_request) Successful in 1m18s
Go Revive Lint / lint (pull_request) Successful in 1m14s
Run Gosec / tests (pull_request) Successful in 1m28s
Go Test Multi-Platform / Test (ubuntu-latest, amd64) (pull_request) Successful in 3m6s
Go Build Test / Build (darwin, amd64) (pull_request) Successful in 9m23s
Go Build Test / Build (freebsd, arm) (pull_request) Successful in 9m23s
Go Build Test / Build (linux, amd64) (pull_request) Successful in 9m26s
refactor(tests): clean up whitespace in TestTransportLeak function
2026-01-02 17:47:34 -06:00

40 lines
879 B
Go

// 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)
}
}