From ab2977bb8069601408a3f60b63396a115457322c Mon Sep 17 00:00:00 2001 From: Thomas Hallgren Date: Thu, 27 Apr 2023 08:02:03 +0200 Subject: [PATCH] Ensure that things happen in the correct order in Test_ManyLargeFiles Signed-off-by: Thomas Hallgren --- pkg/fs/ftp_test.go | 24 +++++++++++++++--------- pkg/fs/ftp_test_unix.go | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pkg/fs/ftp_test.go b/pkg/fs/ftp_test.go index 4e5687d..ec1a3c9 100644 --- a/pkg/fs/ftp_test.go +++ b/pkg/fs/ftp_test.go @@ -602,13 +602,6 @@ func TestManyLargeFiles(t *testing.T) { root, port := startFTPServer(t, ctx, tmp, &wg) require.NotEqual(t, uint16(0), port) - _, host, mountPoint := startFUSEHost(t, ctx, port, tmp) - t.Cleanup(func() { - host.Stop() - cancel() - wg.Wait() - }) - const fileSize = 100 * 1024 * 1024 names := make([]string, manyLargeFilesCount) @@ -629,6 +622,18 @@ func TestManyLargeFiles(t *testing.T) { t.Fatal("failed attempting to create large files") } + _, host, mountPoint := startFUSEHost(t, ctx, port, tmp) + stopped := false + stopFuse := func() { + if !stopped { + stopped = true + host.Stop() + cancel() + wg.Wait() + } + } + t.Cleanup(stopFuse) + // Using the local filesystem, read the remote files while writing new ones. All in parallel. readWriteWg := &sync.WaitGroup{} readWriteWg.Add(manyLargeFilesCount * 2) @@ -651,6 +656,7 @@ func TestManyLargeFiles(t *testing.T) { }(i) } readWriteWg.Wait() + stopFuse() // Read files "on the remote server" and validate them. readRemoteWg := &sync.WaitGroup{} @@ -709,7 +715,7 @@ func validateLargeFile(name string, sz int) error { return err } if st.Size() != int64(sz) { - return fmt.Errorf("file size differ. Expected %d, got %d", sz, st.Size()) + return fmt.Errorf("file size of %s differ. Expected %d, got %d", name, sz, st.Size()) } bf := bufio.NewReader(f) qz := uint32(sz / 4) @@ -724,7 +730,7 @@ func validateLargeFile(name string, sz int) error { } x := binary.BigEndian.Uint32(buf) if i != x { - return fmt.Errorf("content differ at position %d: expected %d, got %d", i*4, i, x) + return fmt.Errorf("content of %s differ at position %d: expected %d, got %d", name, i*4, i, x) } } return nil diff --git a/pkg/fs/ftp_test_unix.go b/pkg/fs/ftp_test_unix.go index 8d57eb4..4f5129d 100644 --- a/pkg/fs/ftp_test_unix.go +++ b/pkg/fs/ftp_test_unix.go @@ -6,6 +6,6 @@ import ( "syscall" ) -const manyLargeFilesCount = 20 +const manyLargeFilesCount = 12 var interruptableSysProcAttr *syscall.SysProcAttr = nil //nolint:gochecknoglobals // OS-specific constant