swarm/fuse: Fix flaky FUSE tests (#398)

* swarm/fuse: Run encrypted/nonencrypted cases in separate tests

Encrypted/non-encrypted cases were running in single tests. That could
cause problems because cleanup was done with defers, and they did not run
between the encrypted/non-encrypted cases

* swarm/fuse: Fix typo

* swarm/storage: Fix test function parameter order convention
This commit is contained in:
Balint Gabor 2018-04-18 16:09:32 +02:00 committed by GitHub
parent 4e32271d08
commit a715a46bf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -209,7 +209,15 @@ type testAPI struct {
api *api.Api
}
func (ta *testAPI) mountListAndUnmount(t *testing.T) {
func (ta *testAPI) mountListAndUnmountEncrypted(t *testing.T) {
ta.mountListAndUnmount(t, true)
}
func (ta *testAPI) mountListAndUnmountNonEncrypted(t *testing.T) {
ta.mountListAndUnmount(t, false)
}
func (ta *testAPI) mountListAndUnmount(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "fuse-source")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "fuse-dest")
@ -231,7 +239,6 @@ func (ta *testAPI) mountListAndUnmount(t *testing.T) {
files["one/two/three/four/five/six/seven/eight/nine/10.txt"] = fileInfo{0777, 333, 444, getRandomBytes(10240)}
files["one/two/three/four/five/six/six"] = fileInfo{0777, 333, 444, getRandomBytes(10)}
for _, toEncrypt := range []bool{false, true} {
bzzHash := createTestFilesAndUploadToSwarm(t, ta.api, files, testUploadDir, toEncrypt)
swarmfs := mountDir(t, ta.api, files, bzzHash, testMountDir)
@ -247,14 +254,15 @@ func (ta *testAPI) mountListAndUnmount(t *testing.T) {
}
}
func (ta *testAPI) maxMountsEncrypted(t *testing.T) {
ta.runMaxMounts(t, true)
}
func (ta *testAPI) maxMounts(t *testing.T) {
ta.runMaxMounts(false, t)
ta.runMaxMounts(true, t)
func (ta *testAPI) maxMountsNonEncrypted(t *testing.T) {
ta.runMaxMounts(t, false)
}
func (ta *testAPI) runMaxMounts(toEncrypt bool, t *testing.T) {
func (ta *testAPI) runMaxMounts(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
uploadDir1, _ := ioutil.TempDir(os.TempDir(), "max-upload1")
@ -304,8 +312,14 @@ func (ta *testAPI) runMaxMounts(toEncrypt bool, t *testing.T) {
}
}
func (ta *testAPI) remount(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) remountEncrypted(t *testing.T) {
ta.remount(t, true)
}
func (ta *testAPI) remountNonEncrypted(t *testing.T) {
ta.remount(t, false)
}
func (ta *testAPI) remount(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
files["1.txt"] = fileInfo{0700, 333, 444, getRandomBytes(10)}
uploadDir1, _ := ioutil.TempDir(os.TempDir(), "re-upload1")
@ -338,10 +352,16 @@ func (ta *testAPI) remount(t *testing.T) {
t.Fatalf("Error mounting hash %v", bzzHash2)
}
}
func (ta *testAPI) unmountEncrypted(t *testing.T) {
ta.unmount(t, true)
}
func (ta *testAPI) unmount(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) unmountNonEncrypted(t *testing.T) {
ta.unmount(t, false)
}
func (ta *testAPI) unmount(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
uploadDir, _ := ioutil.TempDir(os.TempDir(), "ex-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "ex-mount")
@ -361,10 +381,15 @@ func (ta *testAPI) unmount(t *testing.T) {
}
}
}
func (ta *testAPI) unmountWhenResourceBusyEncrypted(t *testing.T) {
ta.unmountWhenResourceBusy(t, true)
}
func (ta *testAPI) unmountWhenResourceBusyNonEncrypted(t *testing.T) {
ta.unmountWhenResourceBusy(t, false)
}
func (ta *testAPI) unmountWhenResourceBusy(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) unmountWhenResourceBusy(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "ex-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "ex-mount")
@ -392,10 +417,16 @@ func (ta *testAPI) unmountWhenResourceBusy(t *testing.T) {
}
}
}
func (ta *testAPI) seekInMultiChunkFileEncrypted(t *testing.T) {
ta.seekInMultiChunkFile(t, true)
}
func (ta *testAPI) seekInMultiChunkFile(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) seekInMultiChunkFileNonEncrypted(t *testing.T) {
ta.seekInMultiChunkFile(t, false)
}
func (ta *testAPI) seekInMultiChunkFile(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "seek-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "seek-mount")
@ -421,10 +452,16 @@ func (ta *testAPI) seekInMultiChunkFile(t *testing.T) {
}
d.Close()
}
func (ta *testAPI) createNewFileEncrypted(t *testing.T) {
ta.createNewFile(t, true)
}
func (ta *testAPI) createNewFile(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) createNewFileNonEncrypted(t *testing.T) {
ta.createNewFile(t, false)
}
func (ta *testAPI) createNewFile(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "create-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "create-mount")
@ -460,10 +497,16 @@ func (ta *testAPI) createNewFile(t *testing.T) {
checkFile(t, testMountDir, "2.txt", contents)
}
func (ta *testAPI) createNewFileInsideDirectoryEncrypted(t *testing.T) {
ta.createNewFileInsideDirectory(t, true)
}
func (ta *testAPI) createNewFileInsideDirectory(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) createNewFileInsideDirectoryNonEncrypted(t *testing.T) {
ta.createNewFileInsideDirectory(t, false)
}
func (ta *testAPI) createNewFileInsideDirectory(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "createinsidedir-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "createinsidedir-mount")
@ -498,10 +541,16 @@ func (ta *testAPI) createNewFileInsideDirectory(t *testing.T) {
checkFile(t, testMountDir, "one/2.txt", contents)
}
func (ta *testAPI) createNewFileInsideNewDirectoryEncrypted(t *testing.T) {
ta.createNewFileInsideNewDirectory(t, true)
}
func (ta *testAPI) createNewFileInsideNewDirectory(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) createNewFileInsideNewDirectoryNonEncrypted(t *testing.T) {
ta.createNewFileInsideNewDirectory(t, false)
}
func (ta *testAPI) createNewFileInsideNewDirectory(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "createinsidenewdir-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "createinsidenewdir-mount")
@ -537,10 +586,16 @@ func (ta *testAPI) createNewFileInsideNewDirectory(t *testing.T) {
checkFile(t, testMountDir, "one/2.txt", contents)
}
func (ta *testAPI) removeExistingFileEncrypted(t *testing.T) {
ta.removeExistingFile(t, true)
}
func (ta *testAPI) removeExistingFile(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) removeExistingFileNonEncrypted(t *testing.T) {
ta.removeExistingFile(t, false)
}
func (ta *testAPI) removeExistingFile(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "remove-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "remove-mount")
@ -567,10 +622,16 @@ func (ta *testAPI) removeExistingFile(t *testing.T) {
swarmfs2 := mountDir(t, ta.api, files, mi.LatestManifest, testMountDir)
defer swarmfs2.Stop()
}
func (ta *testAPI) removeExistingFileInsideDirEncrypted(t *testing.T) {
ta.removeExistingFileInsideDir(t, true)
}
func (ta *testAPI) removeExistingFileInsideDir(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) removeExistingFileInsideDirNonEncrypted(t *testing.T) {
ta.removeExistingFileInsideDir(t, false)
}
func (ta *testAPI) removeExistingFileInsideDir(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "remove-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "remove-mount")
@ -597,10 +658,16 @@ func (ta *testAPI) removeExistingFileInsideDir(t *testing.T) {
swarmfs2 := mountDir(t, ta.api, files, mi.LatestManifest, testMountDir)
defer swarmfs2.Stop()
}
func (ta *testAPI) removeNewlyAddedFileEncrypted(t *testing.T) {
ta.removeNewlyAddedFile(t, true)
}
func (ta *testAPI) removeNewlyAddedFile(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) removeNewlyAddedFileNonEncrypted(t *testing.T) {
ta.removeNewlyAddedFile(t, false)
}
func (ta *testAPI) removeNewlyAddedFile(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "removenew-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "removenew-mount")
@ -643,10 +710,16 @@ func (ta *testAPI) removeNewlyAddedFile(t *testing.T) {
t.Fatalf("same contents different hash orig(%v): new(%v)", bzzHash, mi.LatestManifest)
}
}
func (ta *testAPI) addNewFileAndModifyContentsEncrypted(t *testing.T) {
ta.addNewFileAndModifyContents(t, true)
}
func (ta *testAPI) addNewFileAndModifyContents(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) addNewFileAndModifyContentsNonEncrypted(t *testing.T) {
ta.addNewFileAndModifyContents(t, false)
}
func (ta *testAPI) addNewFileAndModifyContents(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "modifyfile-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "modifyfile-mount")
@ -715,10 +788,16 @@ func (ta *testAPI) addNewFileAndModifyContents(t *testing.T) {
checkFile(t, testMountDir, "2.txt", line1and2)
}
func (ta *testAPI) removeEmptyDirEncrypted(t *testing.T) {
ta.removeEmptyDir(t, true)
}
func (ta *testAPI) removeEmptyDir(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) removeEmptyDirNonEncrypted(t *testing.T) {
ta.removeEmptyDir(t, false)
}
func (ta *testAPI) removeEmptyDir(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "rmdir-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "rmdir-mount")
@ -741,10 +820,15 @@ func (ta *testAPI) removeEmptyDir(t *testing.T) {
t.Fatalf("same contents different hash orig(%v): new(%v)", bzzHash, mi.LatestManifest)
}
}
func (ta *testAPI) removeDirWhichHasFilesEncrypted(t *testing.T) {
ta.removeDirWhichHasFiles(t, true)
}
func (ta *testAPI) removeDirWhichHasFilesNonEncrypted(t *testing.T) {
ta.removeDirWhichHasFiles(t, false)
}
func (ta *testAPI) removeDirWhichHasFiles(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) removeDirWhichHasFiles(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "rmdir-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "rmdir-mount")
@ -772,10 +856,15 @@ func (ta *testAPI) removeDirWhichHasFiles(t *testing.T) {
swarmfs2 := mountDir(t, ta.api, files, mi.LatestManifest, testMountDir)
defer swarmfs2.Stop()
}
func (ta *testAPI) removeDirWhichHasSubDirsEncrypted(t *testing.T) {
ta.removeDirWhichHasSubDirs(t, true)
}
func (ta *testAPI) removeDirWhichHasSubDirs(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) removeDirWhichHasSubDirsNonEncrypted(t *testing.T) {
ta.removeDirWhichHasSubDirs(t, false)
}
func (ta *testAPI) removeDirWhichHasSubDirs(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "rmsubdir-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "rmsubdir-mount")
@ -810,10 +899,16 @@ func (ta *testAPI) removeDirWhichHasSubDirs(t *testing.T) {
swarmfs2 := mountDir(t, ta.api, files, mi.LatestManifest, testMountDir)
defer swarmfs2.Stop()
}
func (ta *testAPI) appendFileContentsToEndEncrypted(t *testing.T) {
ta.appendFileContentsToEnd(t, true)
}
func (ta *testAPI) appendFileContentsToEnd(t *testing.T) {
for _, toEncrypt := range []bool{false, true} {
func (ta *testAPI) appendFileContentsToEndNonEncrypted(t *testing.T) {
ta.appendFileContentsToEnd(t, false)
}
func (ta *testAPI) appendFileContentsToEnd(t *testing.T, toEncrypt bool) {
files := make(map[string]fileInfo)
testUploadDir, _ := ioutil.TempDir(os.TempDir(), "appendlargefile-upload")
testMountDir, _ := ioutil.TempDir(os.TempDir(), "appendlargefile-mount")
@ -851,7 +946,6 @@ func (ta *testAPI) appendFileContentsToEnd(t *testing.T) {
checkFile(t, testMountDir, "1.txt", line1and2)
}
}
func TestFUSE(t *testing.T) {
datadir, err := ioutil.TempDir("", "fuse")
@ -866,21 +960,38 @@ func TestFUSE(t *testing.T) {
}
ta := &testAPI{api: api.NewApi(dpa, nil, nil)}
t.Run("mountListAndUmount", ta.mountListAndUnmount)
t.Run("maxMounts", ta.maxMounts)
t.Run("remount", ta.remount)
t.Run("unmount", ta.unmount)
t.Run("unmountWhenResourceBusy", ta.unmountWhenResourceBusy)
t.Run("seekInMultiChunkFile", ta.seekInMultiChunkFile)
t.Run("createNewFile", ta.createNewFile)
t.Run("createNewFileInsideDirectory", ta.createNewFileInsideDirectory)
t.Run("createNewFileInsideNewDirectory", ta.createNewFileInsideNewDirectory)
t.Run("removeExistingFile", ta.removeExistingFile)
t.Run("removeExistingFileInsideDir", ta.removeExistingFileInsideDir)
t.Run("removeNewlyAddedFile", ta.removeNewlyAddedFile)
t.Run("addNewFileAndModifyContents", ta.addNewFileAndModifyContents)
t.Run("removeEmptyDir", ta.removeEmptyDir)
t.Run("removeDirWhichHasFiles", ta.removeDirWhichHasFiles)
t.Run("removeDirWhichHasSubDirs", ta.removeDirWhichHasSubDirs)
t.Run("appendFileContentsToEnd", ta.appendFileContentsToEnd)
t.Run("mountListAndUnmountEncrypted", ta.mountListAndUnmountEncrypted)
t.Run("mountListAndUnmountNonEncrypted", ta.mountListAndUnmountNonEncrypted)
t.Run("maxMountsEncrypted", ta.maxMountsEncrypted)
t.Run("maxMountsNonEncrypted", ta.maxMountsNonEncrypted)
t.Run("remountEncrypted", ta.remountEncrypted)
t.Run("remountNonEncrypted", ta.remountNonEncrypted)
t.Run("unmountEncrypted", ta.unmountEncrypted)
t.Run("unmountNonEncrypted", ta.unmountNonEncrypted)
t.Run("unmountWhenResourceBusyEncrypted", ta.unmountWhenResourceBusyEncrypted)
t.Run("unmountWhenResourceBusyNonEncrypted", ta.unmountWhenResourceBusyNonEncrypted)
t.Run("seekInMultiChunkFileEncrypted", ta.seekInMultiChunkFileEncrypted)
t.Run("seekInMultiChunkFileNonEncrypted", ta.seekInMultiChunkFileNonEncrypted)
t.Run("createNewFileEncrypted", ta.createNewFileEncrypted)
t.Run("createNewFileNonEncrypted", ta.createNewFileNonEncrypted)
t.Run("createNewFileInsideDirectoryEncrypted", ta.createNewFileInsideDirectoryEncrypted)
t.Run("createNewFileInsideDirectoryNonEncrypted", ta.createNewFileInsideDirectoryNonEncrypted)
t.Run("createNewFileInsideNewDirectoryEncrypted", ta.createNewFileInsideNewDirectoryEncrypted)
t.Run("createNewFileInsideNewDirectoryNonEncrypted", ta.createNewFileInsideNewDirectoryNonEncrypted)
t.Run("removeExistingFileEncrypted", ta.removeExistingFileEncrypted)
t.Run("removeExistingFileNonEncrypted", ta.removeExistingFileNonEncrypted)
t.Run("removeExistingFileInsideDirEncrypted", ta.removeExistingFileInsideDirEncrypted)
t.Run("removeExistingFileInsideDirNonEncrypted", ta.removeExistingFileInsideDirNonEncrypted)
t.Run("removeNewlyAddedFileEncrypted", ta.removeNewlyAddedFileEncrypted)
t.Run("removeNewlyAddedFileNonEncrypted", ta.removeNewlyAddedFileNonEncrypted)
t.Run("addNewFileAndModifyContentsEncrypted", ta.addNewFileAndModifyContentsEncrypted)
t.Run("addNewFileAndModifyContentsNonEncrypted", ta.addNewFileAndModifyContentsNonEncrypted)
t.Run("removeEmptyDirEncrypted", ta.removeEmptyDirEncrypted)
t.Run("removeEmptyDirNonEncrypted", ta.removeEmptyDirNonEncrypted)
t.Run("removeDirWhichHasFilesEncrypted", ta.removeDirWhichHasFilesEncrypted)
t.Run("removeDirWhichHasFilesNonEncrypted", ta.removeDirWhichHasFilesNonEncrypted)
t.Run("removeDirWhichHasSubDirsEncrypted", ta.removeDirWhichHasSubDirsEncrypted)
t.Run("removeDirWhichHasSubDirsNonEncrypted", ta.removeDirWhichHasSubDirsNonEncrypted)
t.Run("appendFileContentsToEndEncrypted", ta.appendFileContentsToEndEncrypted)
t.Run("appendFileContentsToEndNonEncrypted", ta.appendFileContentsToEndNonEncrypted)
}