test/snapshots: umount before committing snapshot

For block device like devicemapper, umount before committing
active snapshot can sync data onto disk. Otherewise:

1. deactivating a block device in use will fail or IO error
when forced;
2. new snapshot on it will not catch the data not laid on disk yet.

Signed-off-by: Eric Ren <renzhen.rz@alibaba-linux.com>
This commit is contained in:
Eric Ren 2019-05-08 11:19:23 +08:00 committed by renzhen.rz
parent 3887053177
commit 6f463d3505

View File

@ -149,11 +149,12 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
if err := mount.All(mounts, preparing); err != nil {
t.Fatalf("failure reason: %+v", err)
}
defer testutil.Unmount(t, preparing)
if err := initialApplier.Apply(preparing); err != nil {
t.Fatalf("failure reason: %+v", err)
}
// unmount before commit
testutil.Unmount(t, preparing)
committed := filepath.Join(work, "committed")
if err := snapshotter.Commit(ctx, committed, preparing, opt); err != nil {
@ -185,7 +186,6 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
if err := mount.All(mounts, next); err != nil {
t.Fatalf("failure reason: %+v", err)
}
defer testutil.Unmount(t, next)
if err := fstest.CheckDirectoryEqualWithApplier(next, initialApplier); err != nil {
t.Fatalf("failure reason: %+v", err)
@ -194,6 +194,8 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
if err := diffApplier.Apply(next); err != nil {
t.Fatalf("failure reason: %+v", err)
}
// unmount before commit
testutil.Unmount(t, next)
ni, err := snapshotter.Stat(ctx, next)
if err != nil {