|
| 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