Safety
Checks Against Leaked Resources (Goroutines, File Descriptors)
Assertions
All links point to https://pkg.go.dev/github.com/go-openapi/testify/v2
This domain exposes 2 functionalities.
NoFileDescriptorLeak
NoFileDescriptorLeak ensures that no file descriptor leaks from inside the tested function.
This assertion works on Linux only (via /proc/self/fd). On other platforms, the test is skipped.
NOTE: this assertion is not compatible with parallel tests. File descriptors are a process-wide resource; concurrent tests opening files would cause false positives.
Sockets, pipes, and anonymous inodes are filtered out by default, as these are typically managed by the Go runtime.
Concurrency
NoFileDescriptorLeak is not compatible with parallel tests. File descriptors are a process-wide resource; any concurrent I/O from other goroutines may cause false positives.
Calls to NoFileDescriptorLeak are serialized with a mutex to prevent multiple leak checks from interfering with each other.
| Signature | Usage |
|---|---|
assert.NoFileDescriptorLeak(t T, tested func(), msgAndArgs ...any) bool | package-level function |
assert.NoFileDescriptorLeakf(t T, tested func(), msg string, args ...any) bool | formatted variant |
assert.(*Assertions).NoFileDescriptorLeak(tested func()) bool | method variant |
assert.(*Assertions).NoFileDescriptorLeakf(tested func(), msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
require.NoFileDescriptorLeak(t T, tested func(), msgAndArgs ...any) bool | package-level function |
require.NoFileDescriptorLeakf(t T, tested func(), msg string, args ...any) bool | formatted variant |
require.(*Assertions).NoFileDescriptorLeak(tested func()) bool | method variant |
require.(*Assertions).NoFileDescriptorLeakf(tested func(), msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
assertions.NoFileDescriptorLeak(t T, tested func(), msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#NoFileDescriptorLeak
NoGoRoutineLeak
NoGoRoutineLeak ensures that no goroutine did leak from inside the tested function.
NOTE: only the go routines spawned from inside the tested function are checked for leaks. No filter or configuration is needed to exclude “known go routines”.
Resource cleanup should be done inside the tested function, and not using testing.T.Cleanup, as t.Cleanup is called after the leak check.
Edge cases
- if the tested function panics leaving behind leaked goroutines, these are detected.
- if the tested function calls runtime.Goexit (e.g. from testing.T.FailNow) leaving behind leaked goroutines, these are detected.
- if a panic occurs in one of the leaked go routines, it cannot be recovered with certainty and the calling program will usually panic.
Concurrency
NoGoRoutineLeak may be used safely in parallel tests.
| Signature | Usage |
|---|---|
assert.NoGoRoutineLeak(t T, tested func(), msgAndArgs ...any) bool | package-level function |
assert.NoGoRoutineLeakf(t T, tested func(), msg string, args ...any) bool | formatted variant |
assert.(*Assertions).NoGoRoutineLeak(tested func()) bool | method variant |
assert.(*Assertions).NoGoRoutineLeakf(tested func(), msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
require.NoGoRoutineLeak(t T, tested func(), msgAndArgs ...any) bool | package-level function |
require.NoGoRoutineLeakf(t T, tested func(), msg string, args ...any) bool | formatted variant |
require.(*Assertions).NoGoRoutineLeak(tested func()) bool | method variant |
require.(*Assertions).NoGoRoutineLeakf(tested func(), msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
assertions.NoGoRoutineLeak(t T, tested func(), msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#NoGoRoutineLeak
Generated with github.com/go-openapi/testify/codegen/v2