Merge pull request #3680 from crosbymichael/btrfs-flake

Sync and stat btrfs loopback in tests
This commit is contained in:
Derek McGowan 2019-09-25 13:47:31 -07:00 committed by GitHub
commit 1c42610d98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
"time"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/containerd/containerd/pkg/testutil" "github.com/containerd/containerd/pkg/testutil"
@ -62,11 +63,26 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
loop.Close() loop.Close()
return nil, nil, errors.Wrapf(err, "failed to make btrfs filesystem (out: %q)", out) return nil, nil, errors.Wrapf(err, "failed to make btrfs filesystem (out: %q)", out)
} }
if out, err := exec.Command("mount", loop.Device, root).CombinedOutput(); err != nil { // sync after a mkfs on the loopback before trying to mount the device
loop.Close() unix.Sync()
return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", loop.Device, out)
}
for i := 0; i < 5; i++ {
if out, err := exec.Command("mount", loop.Device, root).CombinedOutput(); err != nil {
loop.Close()
return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", loop.Device, out)
}
var stat unix.Statfs_t
if err := unix.Statfs(root, &stat); err != nil {
unix.Unmount(root, 0)
return nil, nil, errors.Wrapf(err, "unable to statfs btrfs mount %s", root)
}
if stat.Type == unix.BTRFS_SUPER_MAGIC {
break
}
// unmount and try again
unix.Unmount(root, 0)
time.Sleep(100 * time.Millisecond)
}
snapshotter, err := NewSnapshotter(root) snapshotter, err := NewSnapshotter(root)
if err != nil { if err != nil {
loop.Close() loop.Close()