Browse code

[chore] clean up reexec.Init() calls

Now that most uses of reexec have been replaced with non-reexec
solutions, most of the reexec.Init() calls peppered throughout the test
suites are unnecessary. Furthermore, most of the reexec.Init() calls in
test code neglects to check the return value to determine whether to
exit, which would result in the reexec'ed subprocesses proceeding to run
the tests, which would reexec another subprocess which would proceed to
run the tests, recursively. (That would explain why every reexec
callback used to unconditionally call os.Exit() instead of returning...)

Remove unneeded reexec.Init() calls from test and example code which no
longer needs it, and fix the reexec.Init() calls which are not inert to
exit after a reexec callback is invoked.

Signed-off-by: Cory Snider <csnider@mirantis.com>

Cory Snider authored on 2023/05/10 07:27:40
Showing 13 changed files
... ...
@@ -21,8 +21,11 @@ type dispatchTestCase struct {
21 21
 	files               map[string]string
22 22
 }
23 23
 
24
-func init() {
25
-	reexec.Init()
24
+func TestMain(m *testing.M) {
25
+	if reexec.Init() {
26
+		return
27
+	}
28
+	os.Exit(m.Run())
26 29
 }
27 30
 
28 31
 func TestDispatch(t *testing.T) {
... ...
@@ -17,8 +17,11 @@ const (
17 17
 	contents = "contents test"
18 18
 )
19 19
 
20
-func init() {
21
-	reexec.Init()
20
+func TestMain(m *testing.M) {
21
+	if reexec.Init() {
22
+		return
23
+	}
24
+	os.Exit(m.Run())
22 25
 }
23 26
 
24 27
 func TestCloseRootDirectory(t *testing.T) {
... ...
@@ -9,7 +9,6 @@ import (
9 9
 	"github.com/docker/docker/daemon/graphdriver"
10 10
 	"github.com/docker/docker/daemon/graphdriver/graphtest"
11 11
 	"github.com/docker/docker/pkg/archive"
12
-	"github.com/docker/docker/pkg/reexec"
13 12
 )
14 13
 
15 14
 func init() {
... ...
@@ -17,8 +16,6 @@ func init() {
17 17
 	// errors or hangs to be debugged directly from the test process.
18 18
 	untar = archive.UntarUncompressed
19 19
 	graphdriver.ApplyUncompressedLayer = archive.ApplyUncompressedLayer
20
-
21
-	reexec.Init()
22 20
 }
23 21
 
24 22
 // This avoids creating a new driver for each test if all tests are run
... ...
@@ -10,7 +10,6 @@ import (
10 10
 	"github.com/docker/docker/daemon/graphdriver"
11 11
 	"github.com/docker/docker/daemon/graphdriver/graphtest"
12 12
 	"github.com/docker/docker/pkg/archive"
13
-	"github.com/docker/docker/pkg/reexec"
14 13
 )
15 14
 
16 15
 func init() {
... ...
@@ -18,8 +17,6 @@ func init() {
18 18
 	// errors or hangs to be debugged directly from the test process.
19 19
 	untar = archive.UntarUncompressed
20 20
 	graphdriver.ApplyUncompressedLayer = archive.ApplyUncompressedLayer
21
-
22
-	reexec.Init()
23 21
 }
24 22
 
25 23
 func skipIfNaive(t *testing.T) {
... ...
@@ -7,14 +7,8 @@ import (
7 7
 	"testing"
8 8
 
9 9
 	"github.com/docker/docker/daemon/graphdriver/graphtest"
10
-
11
-	"github.com/docker/docker/pkg/reexec"
12 10
 )
13 11
 
14
-func init() {
15
-	reexec.Init()
16
-}
17
-
18 12
 // This avoids creating a new driver for each test if all tests are run
19 13
 // Make sure to put new tests between TestVfsSetup and TestVfsTeardown
20 14
 func TestVfsSetup(t *testing.T) {
... ...
@@ -18,7 +18,6 @@ import (
18 18
 	"github.com/docker/docker/integration-cli/daemon"
19 19
 	"github.com/docker/docker/integration-cli/environment"
20 20
 	"github.com/docker/docker/internal/test/suite"
21
-	"github.com/docker/docker/pkg/reexec"
22 21
 	testdaemon "github.com/docker/docker/testutil/daemon"
23 22
 	ienv "github.com/docker/docker/testutil/environment"
24 23
 	"github.com/docker/docker/testutil/fakestorage"
... ...
@@ -50,8 +49,6 @@ var (
50 50
 func init() {
51 51
 	var err error
52 52
 
53
-	reexec.Init() // This is required for external graphdriver tests
54
-
55 53
 	testEnv, err = environment.New()
56 54
 	if err != nil {
57 55
 		panic(err)
... ...
@@ -5,16 +5,12 @@ import (
5 5
 	"os"
6 6
 	"testing"
7 7
 
8
-	"github.com/docker/docker/pkg/reexec"
9 8
 	"github.com/docker/docker/testutil/environment"
10 9
 )
11 10
 
12 11
 var testEnv *environment.Execution
13 12
 
14 13
 func TestMain(m *testing.M) {
15
-	if reexec.Init() {
16
-		return
17
-	}
18 14
 	var err error
19 15
 	testEnv, err = environment.New()
20 16
 	if err != nil {
... ...
@@ -5,7 +5,6 @@ import (
5 5
 	"os"
6 6
 	"testing"
7 7
 
8
-	"github.com/docker/docker/pkg/reexec"
9 8
 	"github.com/docker/docker/testutil/environment"
10 9
 )
11 10
 
... ...
@@ -13,10 +12,6 @@ var (
13 13
 	testEnv *environment.Execution
14 14
 )
15 15
 
16
-func init() {
17
-	reexec.Init() // This is required for external graphdriver tests
18
-}
19
-
20 16
 func TestMain(m *testing.M) {
21 17
 	var err error
22 18
 	testEnv, err = environment.New()
... ...
@@ -8,14 +8,9 @@ import (
8 8
 	"github.com/docker/docker/libnetwork/config"
9 9
 	"github.com/docker/docker/libnetwork/netlabel"
10 10
 	"github.com/docker/docker/libnetwork/options"
11
-	"github.com/docker/docker/pkg/reexec"
12 11
 )
13 12
 
14 13
 func main() {
15
-	if reexec.Init() {
16
-		return
17
-	}
18
-
19 14
 	// Select and configure the network driver
20 15
 	networkType := "bridge"
21 16
 
... ...
@@ -4,23 +4,14 @@
4 4
 package bridge
5 5
 
6 6
 import (
7
-	"os"
8 7
 	"testing"
9 8
 
10 9
 	"github.com/docker/docker/libnetwork/netlabel"
11 10
 	"github.com/docker/docker/libnetwork/ns"
12 11
 	"github.com/docker/docker/libnetwork/testutils"
13 12
 	"github.com/docker/docker/libnetwork/types"
14
-	"github.com/docker/docker/pkg/reexec"
15 13
 )
16 14
 
17
-func TestMain(m *testing.M) {
18
-	if reexec.Init() {
19
-		return
20
-	}
21
-	os.Exit(m.Run())
22
-}
23
-
24 15
 func TestPortMappingConfig(t *testing.T) {
25 16
 	defer testutils.SetupTestOSContext(t)()
26 17
 	d := newDriver()
... ...
@@ -10,7 +10,6 @@ import (
10 10
 	"net/http/httptest"
11 11
 	"os"
12 12
 	"path/filepath"
13
-	"runtime"
14 13
 	"testing"
15 14
 
16 15
 	"github.com/docker/docker/libnetwork"
... ...
@@ -23,19 +22,9 @@ import (
23 23
 	"github.com/docker/docker/libnetwork/testutils"
24 24
 	"github.com/docker/docker/libnetwork/types"
25 25
 	"github.com/docker/docker/pkg/plugins"
26
-	"github.com/docker/docker/pkg/reexec"
27
-	"github.com/sirupsen/logrus"
28 26
 )
29 27
 
30 28
 func TestMain(m *testing.M) {
31
-	if runtime.GOOS == "windows" {
32
-		logrus.Info("Test suite does not currently support windows")
33
-		os.Exit(0)
34
-	}
35
-	if reexec.Init() {
36
-		return
37
-	}
38
-
39 29
 	// Cleanup local datastore file
40 30
 	_ = os.Remove(datastore.DefaultScope("").Client.Address)
41 31
 
... ...
@@ -15,7 +15,6 @@ import (
15 15
 	"github.com/docker/docker/libnetwork/ns"
16 16
 	"github.com/docker/docker/libnetwork/testutils"
17 17
 	"github.com/docker/docker/libnetwork/types"
18
-	"github.com/docker/docker/pkg/reexec"
19 18
 	"github.com/vishvananda/netlink"
20 19
 	"github.com/vishvananda/netlink/nl"
21 20
 	"github.com/vishvananda/netns"
... ...
@@ -382,13 +381,6 @@ func TestLiveRestore(t *testing.T) {
382 382
 	}
383 383
 }
384 384
 
385
-func TestMain(m *testing.M) {
386
-	if reexec.Init() {
387
-		return
388
-	}
389
-	os.Exit(m.Run())
390
-}
391
-
392 385
 func TestSandboxCreate(t *testing.T) {
393 386
 	defer testutils.SetupTestOSContext(t)()
394 387
 
... ...
@@ -14,14 +14,9 @@ import (
14 14
 
15 15
 	"github.com/docker/docker/pkg/archive"
16 16
 	"github.com/docker/docker/pkg/idtools"
17
-	"github.com/docker/docker/pkg/reexec"
18 17
 	"gotest.tools/v3/skip"
19 18
 )
20 19
 
21
-func init() {
22
-	reexec.Init()
23
-}
24
-
25 20
 var chrootArchiver = NewArchiver(idtools.IdentityMapping{})
26 21
 
27 22
 func TarUntar(src, dst string) error {