Skip to content

Commit

Permalink
Ensure that things happen in the correct order in Test_ManyLargeFiles
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed Apr 27, 2023
1 parent 025dacf commit ab2977b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions pkg/fs/ftp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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{}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/fs/ftp_test_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
"syscall"
)

const manyLargeFilesCount = 20
const manyLargeFilesCount = 12

var interruptableSysProcAttr *syscall.SysProcAttr = nil //nolint:gochecknoglobals // OS-specific constant

0 comments on commit ab2977b

Please sign in to comment.