1
0
mirror of https://github.com/moby/moby.git synced 2025-12-03 07:41:01 +03:00

fix some leaking mounts in tests

This should help with errors such as:

    === RUN   TestSysctlOverride
        testing.go:1090: TempDir RemoveAll cleanup: unlinkat /tmp/TestSysctlOverride3702360633/001/mounts/shm: device or resource busy
    --- FAIL: TestSysctlOverride (0.00s)

    === RUN   TestSysctlOverrideHost
        testing.go:1090: TempDir RemoveAll cleanup: unlinkat /tmp/TestSysctlOverrideHost226485533/001/mounts/shm: device or resource busy
    --- FAIL: TestSysctlOverrideHost (0.00s)

    === RUN   TestDockerSuite/TestRunWithVolumesIsRecursive
        testing.go:1090: TempDir RemoveAll cleanup: unlinkat /tmp/TestDockerSuiteTestRunWithVolumesIsRecursive1156692230/001/tmpfs: device or resource busy
        --- FAIL: TestDockerSuite/TestRunWithVolumesIsRecursive (0.49s)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2022-05-31 23:49:50 +02:00
parent c87e0ad209
commit c482383458
4 changed files with 31 additions and 20 deletions

View File

@@ -1971,22 +1971,22 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) {
assert.NilError(c, err) assert.NilError(c, err)
defer os.RemoveAll(tmpDir3) defer os.RemoveAll(tmpDir3)
assert.Assert(c, mountWrapper(tmpDir3, tmpDir3, "none", "bind,shared") == nil) if assert.Check(c, mountWrapper(c, tmpDir3, tmpDir3, "none", "bind,shared")) {
cases = append(cases, []testCase{
cases = append(cases, []testCase{ {
{ spec: mount.Mount{Type: "bind", Source: tmpDir3, Target: destPath},
spec: mount.Mount{Type: "bind", Source: tmpDir3, Target: destPath}, expected: types.MountPoint{Type: "bind", RW: true, Destination: destPath, Source: tmpDir3},
expected: types.MountPoint{Type: "bind", RW: true, Destination: destPath, Source: tmpDir3}, },
}, {
{ spec: mount.Mount{Type: "bind", Source: tmpDir3, Target: destPath, ReadOnly: true},
spec: mount.Mount{Type: "bind", Source: tmpDir3, Target: destPath, ReadOnly: true}, expected: types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir3},
expected: types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir3}, },
}, {
{ spec: mount.Mount{Type: "bind", Source: tmpDir3, Target: destPath, ReadOnly: true, BindOptions: &mount.BindOptions{Propagation: "shared"}},
spec: mount.Mount{Type: "bind", Source: tmpDir3, Target: destPath, ReadOnly: true, BindOptions: &mount.BindOptions{Propagation: "shared"}}, expected: types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir3, Propagation: "shared"},
expected: types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir3, Propagation: "shared"}, },
}, }...)
}...) }
} }
} }

View File

@@ -2,8 +2,18 @@
package main package main
import "github.com/moby/sys/mount" import (
"testing"
func mountWrapper(device, target, mType, options string) error { "github.com/moby/sys/mount"
return mount.Mount(device, target, mType, options) )
func mountWrapper(t *testing.T, device, target, mType, options string) error {
t.Helper()
err := mount.Mount(device, target, mType, options)
if err != nil {
return err
}
t.Cleanup(func() { _ = mount.Unmount(target) })
return nil
} }

View File

@@ -73,7 +73,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsBindNamedPipe(c *testing.T
assert.Check(c, is.Equal(text, strings.TrimSpace(string(b)))) assert.Check(c, is.Equal(text, strings.TrimSpace(string(b))))
} }
func mountWrapper(device, target, mType, options string) error { func mountWrapper(t *testing.T, device, target, mType, options string) error {
// This should never be called. // This should never be called.
return errors.Errorf("there is no implementation of Mount on this platform") return errors.Errorf("there is no implementation of Mount on this platform")
} }

View File

@@ -70,6 +70,7 @@ func (s *DockerCLIRunSuite) TestRunWithVolumesIsRecursive(c *testing.T) {
tmpfsDir := filepath.Join(tmpDir, "tmpfs") tmpfsDir := filepath.Join(tmpDir, "tmpfs")
assert.Assert(c, os.MkdirAll(tmpfsDir, 0o777) == nil, "failed to mkdir at %s", tmpfsDir) assert.Assert(c, os.MkdirAll(tmpfsDir, 0o777) == nil, "failed to mkdir at %s", tmpfsDir)
assert.Assert(c, mount.Mount("tmpfs", tmpfsDir, "tmpfs", "") == nil, "failed to create a tmpfs mount at %s", tmpfsDir) assert.Assert(c, mount.Mount("tmpfs", tmpfsDir, "tmpfs", "") == nil, "failed to create a tmpfs mount at %s", tmpfsDir)
defer mount.Unmount(tmpfsDir)
f, err := os.CreateTemp(tmpfsDir, "touch-me") f, err := os.CreateTemp(tmpfsDir, "touch-me")
assert.NilError(c, err) assert.NilError(c, err)