forked from TrueCloudLab/rclone
mounttest: wait for all background Close/Release after writing a file
The filesystem does a certain amount of things asynchronously waiting for the file to be released after writing it means everything should be in a consistent state.
This commit is contained in:
parent
60945d0a37
commit
e98e550021
4 changed files with 16 additions and 3 deletions
|
@ -52,6 +52,8 @@ func TestFileModTimeWithOpenWriters(t *testing.T) {
|
||||||
err = f.Close()
|
err = f.Close()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
run.waitForWriters()
|
||||||
|
|
||||||
info, err := os.Stat(filepath)
|
info, err := os.Stat(filepath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -304,10 +304,16 @@ func (r *Run) checkDir(t *testing.T, dirString string) {
|
||||||
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wait for any files being written to be released by fuse
|
||||||
|
func (r *Run) waitForWriters() {
|
||||||
|
run.vfs.WaitForWriters(10 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Run) createFile(t *testing.T, filepath string, contents string) {
|
func (r *Run) createFile(t *testing.T, filepath string, contents string) {
|
||||||
filepath = r.path(filepath)
|
filepath = r.path(filepath)
|
||||||
err := ioutil.WriteFile(filepath, []byte(contents), 0600)
|
err := ioutil.WriteFile(filepath, []byte(contents), 0600)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
r.waitForWriters()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Run) readFile(t *testing.T, filepath string) string {
|
func (r *Run) readFile(t *testing.T, filepath string) string {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package mounttest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -18,8 +17,7 @@ func TestWriteFileNoWrite(t *testing.T) {
|
||||||
err = fd.Close()
|
err = fd.Close()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// FIXME - wait for the Release on the file
|
run.waitForWriters()
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
|
|
||||||
run.checkDir(t, "testnowrite 0")
|
run.checkDir(t, "testnowrite 0")
|
||||||
|
|
||||||
|
@ -38,6 +36,8 @@ func FIXMETestWriteOpenFileInDirListing(t *testing.T) {
|
||||||
err = fd.Close()
|
err = fd.Close()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
run.waitForWriters()
|
||||||
|
|
||||||
run.rm(t, "testnowrite")
|
run.rm(t, "testnowrite")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +68,8 @@ func TestWriteFileOverwrite(t *testing.T) {
|
||||||
//
|
//
|
||||||
// NB the code for this is in file.go rather than write.go
|
// NB the code for this is in file.go rather than write.go
|
||||||
func TestWriteFileFsync(t *testing.T) {
|
func TestWriteFileFsync(t *testing.T) {
|
||||||
|
run.skipIfNoFUSE(t)
|
||||||
|
|
||||||
filepath := run.path("to be synced")
|
filepath := run.path("to be synced")
|
||||||
fd, err := osCreate(filepath)
|
fd, err := osCreate(filepath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -77,4 +79,6 @@ func TestWriteFileFsync(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = fd.Close()
|
err = fd.Close()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
run.waitForWriters()
|
||||||
|
run.rm(t, "to be synced")
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,5 +45,6 @@ func TestWriteFileDoubleClose(t *testing.T) {
|
||||||
err = syscall.Close(fd2)
|
err = syscall.Close(fd2)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
run.waitForWriters()
|
||||||
run.rm(t, "testdoubleclose")
|
run.rm(t, "testdoubleclose")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue