Skip to content

Commit b7bc2b4

Browse files
committed
Enable leak detection for tests under test
Signed-off-by: apostasie <[email protected]>
1 parent 08debf6 commit b7bc2b4

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

mod/tigron/internal/highk/fileleak.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030
//
3131
//nolint:gochecknoglobals
3232
var whitelist = map[string]bool{
33-
"5u KQUEUE": true,
34-
"10u a_inode": true,
33+
"KQUEUE": true,
34+
"a_inode": true,
3535
}
3636

3737
// SnapshotOpenFiles will capture the list of currently open-files for the process.

mod/tigron/test/package_test.go

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package test_test
18+
19+
import (
20+
"fmt"
21+
"os"
22+
"testing"
23+
24+
"github.com/containerd/nerdctl/mod/tigron/internal/highk"
25+
)
26+
27+
func TestMain(m *testing.M) {
28+
// Prep exit code
29+
exitCode := 0
30+
defer func() { os.Exit(exitCode) }()
31+
32+
var (
33+
snapFile *os.File
34+
before, after []byte
35+
)
36+
37+
if os.Getenv("HIGHK_EXPERIMENTAL_FD") != "" {
38+
snapFile, _ = os.CreateTemp("", "fileleaks")
39+
before, _ = highk.SnapshotOpenFiles(snapFile)
40+
}
41+
42+
exitCode = m.Run()
43+
44+
if exitCode != 0 {
45+
return
46+
}
47+
48+
if os.Getenv("HIGHK_EXPERIMENTAL_FD") != "" {
49+
after, _ = highk.SnapshotOpenFiles(snapFile)
50+
diff := highk.Diff(string(before), string(after))
51+
52+
if len(diff) != 0 {
53+
_, _ = fmt.Fprintln(os.Stderr, "Leaking file descriptors")
54+
55+
for _, file := range diff {
56+
_, _ = fmt.Fprintln(os.Stderr, file)
57+
}
58+
59+
exitCode = 1
60+
}
61+
}
62+
63+
if err := highk.FindGoRoutines(); err != nil {
64+
_, _ = fmt.Fprintln(os.Stderr, "Leaking go routines")
65+
_, _ = fmt.Fprintln(os.Stderr, os.Stderr, err.Error())
66+
67+
exitCode = 1
68+
}
69+
}

0 commit comments

Comments
 (0)