Skip to content

Commit b71555a

Browse files
authored
Merge pull request #3928 from zhsj/bpo-3720
[release/1.3 backport] Fix flaky btrfs test
2 parents e435601 + e49256e commit b71555a

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

snapshots/btrfs/btrfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
7777
return nil, err
7878
}
7979
if mnt.FSType != "btrfs" {
80-
return nil, errors.Wrapf(plugin.ErrSkipPlugin, "path %s must be a btrfs filesystem to be used with the btrfs snapshotter", root)
80+
return nil, errors.Wrapf(plugin.ErrSkipPlugin, "path %s (%s) must be a btrfs filesystem to be used with the btrfs snapshotter", root, mnt.FSType)
8181
}
8282
var (
8383
active = filepath.Join(root, "active")

snapshots/btrfs/btrfs_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/containerd/containerd/mount"
3232
"github.com/containerd/containerd/pkg/testutil"
33+
"github.com/containerd/containerd/plugin"
3334
"github.com/containerd/containerd/snapshots"
3435
"github.com/containerd/containerd/snapshots/testsuite"
3536
"github.com/containerd/continuity/testutil/loopback"
@@ -66,27 +67,31 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
6667
// sync after a mkfs on the loopback before trying to mount the device
6768
unix.Sync()
6869

70+
var snapshotter snapshots.Snapshotter
6971
for i := 0; i < 5; i++ {
7072
if out, err := exec.Command("mount", loop.Device, root).CombinedOutput(); err != nil {
7173
loop.Close()
7274
return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", loop.Device, out)
7375
}
74-
var stat unix.Statfs_t
75-
if err := unix.Statfs(root, &stat); err != nil {
76-
unix.Unmount(root, 0)
77-
return nil, nil, errors.Wrapf(err, "unable to statfs btrfs mount %s", root)
76+
77+
if i > 0 {
78+
time.Sleep(10 * time.Duration(i) * time.Millisecond)
7879
}
79-
if stat.Type == unix.BTRFS_SUPER_MAGIC {
80+
81+
snapshotter, err = NewSnapshotter(root)
82+
if err == nil {
8083
break
84+
} else if errors.Cause(err) != plugin.ErrSkipPlugin {
85+
return nil, nil, err
8186
}
87+
88+
t.Logf("Attempt %d to create btrfs snapshotter failed: %#v", i+1, err)
89+
8290
// unmount and try again
8391
unix.Unmount(root, 0)
84-
time.Sleep(100 * time.Millisecond)
8592
}
86-
snapshotter, err := NewSnapshotter(root)
87-
if err != nil {
88-
loop.Close()
89-
return nil, nil, errors.Wrap(err, "failed to create new snapshotter")
93+
if snapshotter == nil {
94+
return nil, nil, errors.Wrap(err, "failed to successfully create snapshotter after 5 attempts")
9095
}
9196

9297
return snapshotter, func() error {

0 commit comments

Comments
 (0)