浏览代码

[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>
(cherry picked from commit 4e0319c87857f180b01f9b072603cc385d7fcee1)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Cory Snider 2 年之前
父节点
当前提交
f77a3274b4

+ 5 - 2
builder/dockerfile/evaluator_test.go

@@ -21,8 +21,11 @@ type dispatchTestCase struct {
 	files               map[string]string
 	files               map[string]string
 }
 }
 
 
-func init() {
-	reexec.Init()
+func TestMain(m *testing.M) {
+	if reexec.Init() {
+		return
+	}
+	os.Exit(m.Run())
 }
 }
 
 
 func TestDispatch(t *testing.T) {
 func TestDispatch(t *testing.T) {

+ 5 - 2
builder/remotecontext/tarsum_test.go

@@ -17,8 +17,11 @@ const (
 	contents = "contents test"
 	contents = "contents test"
 )
 )
 
 
-func init() {
-	reexec.Init()
+func TestMain(m *testing.M) {
+	if reexec.Init() {
+		return
+	}
+	os.Exit(m.Run())
 }
 }
 
 
 func TestCloseRootDirectory(t *testing.T) {
 func TestCloseRootDirectory(t *testing.T) {

+ 0 - 3
daemon/graphdriver/fuse-overlayfs/fuseoverlayfs_test.go

@@ -9,7 +9,6 @@ import (
 	"github.com/docker/docker/daemon/graphdriver"
 	"github.com/docker/docker/daemon/graphdriver"
 	"github.com/docker/docker/daemon/graphdriver/graphtest"
 	"github.com/docker/docker/daemon/graphdriver/graphtest"
 	"github.com/docker/docker/pkg/archive"
 	"github.com/docker/docker/pkg/archive"
-	"github.com/docker/docker/pkg/reexec"
 )
 )
 
 
 func init() {
 func init() {
@@ -17,8 +16,6 @@ func init() {
 	// errors or hangs to be debugged directly from the test process.
 	// errors or hangs to be debugged directly from the test process.
 	untar = archive.UntarUncompressed
 	untar = archive.UntarUncompressed
 	graphdriver.ApplyUncompressedLayer = archive.ApplyUncompressedLayer
 	graphdriver.ApplyUncompressedLayer = archive.ApplyUncompressedLayer
-
-	reexec.Init()
 }
 }
 
 
 // This avoids creating a new driver for each test if all tests are run
 // This avoids creating a new driver for each test if all tests are run

+ 0 - 3
daemon/graphdriver/overlay2/overlay_test.go

@@ -10,7 +10,6 @@ import (
 	"github.com/docker/docker/daemon/graphdriver"
 	"github.com/docker/docker/daemon/graphdriver"
 	"github.com/docker/docker/daemon/graphdriver/graphtest"
 	"github.com/docker/docker/daemon/graphdriver/graphtest"
 	"github.com/docker/docker/pkg/archive"
 	"github.com/docker/docker/pkg/archive"
-	"github.com/docker/docker/pkg/reexec"
 )
 )
 
 
 func init() {
 func init() {
@@ -18,8 +17,6 @@ func init() {
 	// errors or hangs to be debugged directly from the test process.
 	// errors or hangs to be debugged directly from the test process.
 	untar = archive.UntarUncompressed
 	untar = archive.UntarUncompressed
 	graphdriver.ApplyUncompressedLayer = archive.ApplyUncompressedLayer
 	graphdriver.ApplyUncompressedLayer = archive.ApplyUncompressedLayer
-
-	reexec.Init()
 }
 }
 
 
 func skipIfNaive(t *testing.T) {
 func skipIfNaive(t *testing.T) {

+ 0 - 6
daemon/graphdriver/vfs/vfs_test.go

@@ -7,14 +7,8 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/docker/docker/daemon/graphdriver/graphtest"
 	"github.com/docker/docker/daemon/graphdriver/graphtest"
-
-	"github.com/docker/docker/pkg/reexec"
 )
 )
 
 
-func init() {
-	reexec.Init()
-}
-
 // This avoids creating a new driver for each test if all tests are run
 // This avoids creating a new driver for each test if all tests are run
 // Make sure to put new tests between TestVfsSetup and TestVfsTeardown
 // Make sure to put new tests between TestVfsSetup and TestVfsTeardown
 func TestVfsSetup(t *testing.T) {
 func TestVfsSetup(t *testing.T) {

+ 0 - 3
integration-cli/check_test.go

@@ -18,7 +18,6 @@ import (
 	"github.com/docker/docker/integration-cli/daemon"
 	"github.com/docker/docker/integration-cli/daemon"
 	"github.com/docker/docker/integration-cli/environment"
 	"github.com/docker/docker/integration-cli/environment"
 	"github.com/docker/docker/internal/test/suite"
 	"github.com/docker/docker/internal/test/suite"
-	"github.com/docker/docker/pkg/reexec"
 	testdaemon "github.com/docker/docker/testutil/daemon"
 	testdaemon "github.com/docker/docker/testutil/daemon"
 	ienv "github.com/docker/docker/testutil/environment"
 	ienv "github.com/docker/docker/testutil/environment"
 	"github.com/docker/docker/testutil/fakestorage"
 	"github.com/docker/docker/testutil/fakestorage"
@@ -50,8 +49,6 @@ var (
 func init() {
 func init() {
 	var err error
 	var err error
 
 
-	reexec.Init() // This is required for external graphdriver tests
-
 	testEnv, err = environment.New()
 	testEnv, err = environment.New()
 	if err != nil {
 	if err != nil {
 		panic(err)
 		panic(err)

+ 0 - 4
integration/plugin/common/main_test.go

@@ -5,16 +5,12 @@ import (
 	"os"
 	"os"
 	"testing"
 	"testing"
 
 
-	"github.com/docker/docker/pkg/reexec"
 	"github.com/docker/docker/testutil/environment"
 	"github.com/docker/docker/testutil/environment"
 )
 )
 
 
 var testEnv *environment.Execution
 var testEnv *environment.Execution
 
 
 func TestMain(m *testing.M) {
 func TestMain(m *testing.M) {
-	if reexec.Init() {
-		return
-	}
 	var err error
 	var err error
 	testEnv, err = environment.New()
 	testEnv, err = environment.New()
 	if err != nil {
 	if err != nil {

+ 0 - 5
integration/plugin/graphdriver/main_test.go

@@ -5,7 +5,6 @@ import (
 	"os"
 	"os"
 	"testing"
 	"testing"
 
 
-	"github.com/docker/docker/pkg/reexec"
 	"github.com/docker/docker/testutil/environment"
 	"github.com/docker/docker/testutil/environment"
 )
 )
 
 
@@ -13,10 +12,6 @@ var (
 	testEnv *environment.Execution
 	testEnv *environment.Execution
 )
 )
 
 
-func init() {
-	reexec.Init() // This is required for external graphdriver tests
-}
-
 func TestMain(m *testing.M) {
 func TestMain(m *testing.M) {
 	var err error
 	var err error
 	testEnv, err = environment.New()
 	testEnv, err = environment.New()

+ 0 - 5
libnetwork/cmd/readme_test/readme.go

@@ -8,14 +8,9 @@ import (
 	"github.com/docker/docker/libnetwork/config"
 	"github.com/docker/docker/libnetwork/config"
 	"github.com/docker/docker/libnetwork/netlabel"
 	"github.com/docker/docker/libnetwork/netlabel"
 	"github.com/docker/docker/libnetwork/options"
 	"github.com/docker/docker/libnetwork/options"
-	"github.com/docker/docker/pkg/reexec"
 )
 )
 
 
 func main() {
 func main() {
-	if reexec.Init() {
-		return
-	}
-
 	// Select and configure the network driver
 	// Select and configure the network driver
 	networkType := "bridge"
 	networkType := "bridge"
 
 

+ 0 - 9
libnetwork/drivers/bridge/port_mapping_test.go

@@ -4,23 +4,14 @@
 package bridge
 package bridge
 
 
 import (
 import (
-	"os"
 	"testing"
 	"testing"
 
 
 	"github.com/docker/docker/libnetwork/netlabel"
 	"github.com/docker/docker/libnetwork/netlabel"
 	"github.com/docker/docker/libnetwork/ns"
 	"github.com/docker/docker/libnetwork/ns"
 	"github.com/docker/docker/libnetwork/testutils"
 	"github.com/docker/docker/libnetwork/testutils"
 	"github.com/docker/docker/libnetwork/types"
 	"github.com/docker/docker/libnetwork/types"
-	"github.com/docker/docker/pkg/reexec"
 )
 )
 
 
-func TestMain(m *testing.M) {
-	if reexec.Init() {
-		return
-	}
-	os.Exit(m.Run())
-}
-
 func TestPortMappingConfig(t *testing.T) {
 func TestPortMappingConfig(t *testing.T) {
 	defer testutils.SetupTestOSContext(t)()
 	defer testutils.SetupTestOSContext(t)()
 	d := newDriver()
 	d := newDriver()

+ 0 - 11
libnetwork/libnetwork_test.go

@@ -10,7 +10,6 @@ import (
 	"net/http/httptest"
 	"net/http/httptest"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
-	"runtime"
 	"testing"
 	"testing"
 
 
 	"github.com/docker/docker/libnetwork"
 	"github.com/docker/docker/libnetwork"
@@ -23,19 +22,9 @@ import (
 	"github.com/docker/docker/libnetwork/testutils"
 	"github.com/docker/docker/libnetwork/testutils"
 	"github.com/docker/docker/libnetwork/types"
 	"github.com/docker/docker/libnetwork/types"
 	"github.com/docker/docker/pkg/plugins"
 	"github.com/docker/docker/pkg/plugins"
-	"github.com/docker/docker/pkg/reexec"
-	"github.com/sirupsen/logrus"
 )
 )
 
 
 func TestMain(m *testing.M) {
 func TestMain(m *testing.M) {
-	if runtime.GOOS == "windows" {
-		logrus.Info("Test suite does not currently support windows")
-		os.Exit(0)
-	}
-	if reexec.Init() {
-		return
-	}
-
 	// Cleanup local datastore file
 	// Cleanup local datastore file
 	_ = os.Remove(datastore.DefaultScope("").Client.Address)
 	_ = os.Remove(datastore.DefaultScope("").Client.Address)
 
 

+ 0 - 8
libnetwork/osl/sandbox_linux_test.go

@@ -15,7 +15,6 @@ import (
 	"github.com/docker/docker/libnetwork/ns"
 	"github.com/docker/docker/libnetwork/ns"
 	"github.com/docker/docker/libnetwork/testutils"
 	"github.com/docker/docker/libnetwork/testutils"
 	"github.com/docker/docker/libnetwork/types"
 	"github.com/docker/docker/libnetwork/types"
-	"github.com/docker/docker/pkg/reexec"
 	"github.com/vishvananda/netlink"
 	"github.com/vishvananda/netlink"
 	"github.com/vishvananda/netlink/nl"
 	"github.com/vishvananda/netlink/nl"
 	"github.com/vishvananda/netns"
 	"github.com/vishvananda/netns"
@@ -382,13 +381,6 @@ func TestLiveRestore(t *testing.T) {
 	}
 	}
 }
 }
 
 
-func TestMain(m *testing.M) {
-	if reexec.Init() {
-		return
-	}
-	os.Exit(m.Run())
-}
-
 func TestSandboxCreate(t *testing.T) {
 func TestSandboxCreate(t *testing.T) {
 	defer testutils.SetupTestOSContext(t)()
 	defer testutils.SetupTestOSContext(t)()
 
 

+ 0 - 5
pkg/chrootarchive/archive_test.go

@@ -14,14 +14,9 @@ import (
 
 
 	"github.com/docker/docker/pkg/archive"
 	"github.com/docker/docker/pkg/archive"
 	"github.com/docker/docker/pkg/idtools"
 	"github.com/docker/docker/pkg/idtools"
-	"github.com/docker/docker/pkg/reexec"
 	"gotest.tools/v3/skip"
 	"gotest.tools/v3/skip"
 )
 )
 
 
-func init() {
-	reexec.Init()
-}
-
 var chrootArchiver = NewArchiver(idtools.IdentityMapping{})
 var chrootArchiver = NewArchiver(idtools.IdentityMapping{})
 
 
 func TarUntar(src, dst string) error {
 func TarUntar(src, dst string) error {