Skip to content

Commit bb7ebc6

Browse files
committed
Add "read extended file" test (currently broken)
1 parent 31f0562 commit bb7ebc6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

internal/goofys_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,33 @@ func (s *GoofysTest) TestMultipartWriteAndTruncate(t *C) {
733733
fh.Release()
734734
}
735735

736+
func (s *GoofysTest) TestReadExtendedFile(t *C) {
737+
// Create a 8k file
738+
fh := s.testCreateAndWrite(t, "test8k", 8*1024, 128*1024, true)
739+
inode := fh.inode
740+
err := inode.SyncFile()
741+
t.Assert(err, IsNil)
742+
fh.Release()
743+
// Reset its cache to remove cached 8k
744+
inode.mu.Lock()
745+
inode.resetCache()
746+
inode.mu.Unlock()
747+
// Resize it to 10M while opened
748+
fh, err = inode.OpenFile()
749+
t.Assert(err, IsNil)
750+
err = inode.SetAttributes(PUInt64(10*1024*1024), nil, nil, nil, nil)
751+
t.Assert(err, IsNil)
752+
// Read 1kb from the beginning - it was previously broken because readahead
753+
// tried to extend read to 0..5M, beyond server-side EOF
754+
oldAttempts := s.fs.flags.ReadRetryAttempts
755+
s.fs.flags.ReadRetryAttempts = 1
756+
_, nread, err := fh.ReadFile(0, 1024)
757+
t.Assert(err, IsNil)
758+
t.Assert(nread, Equals, 1024)
759+
fh.Release()
760+
s.fs.flags.ReadRetryAttempts = oldAttempts
761+
}
762+
736763
func (s *GoofysTest) TestReadWriteMinimumMemory(t *C) {
737764
// First part is fixed for "header hack", last part is "still written to"
738765
s.fs.bufferPool.max = 20*1024*1024

0 commit comments

Comments
 (0)