mirror of
https://github.com/distribution/distribution
synced 2024-11-12 05:45:51 +01:00
Modify TestStatCall to check if ModTime is increasing
Also removed ModTime checks on directories as it is not required and some drivers might fail to provide it. Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
This commit is contained in:
parent
769df8dabe
commit
51042da7fb
@ -705,42 +705,40 @@ func (suite *DriverSuite) TestStatCall(c *check.C) {
|
|||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
// Call on regular file, check results
|
// Call on regular file, check results
|
||||||
start := time.Now().Truncate(time.Second) // truncated for filesystem
|
|
||||||
fi, err = suite.StorageDriver.Stat(filePath)
|
fi, err = suite.StorageDriver.Stat(filePath)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
expectedModTime := time.Now()
|
|
||||||
c.Assert(fi, check.NotNil)
|
c.Assert(fi, check.NotNil)
|
||||||
c.Assert(fi.Path(), check.Equals, filePath)
|
c.Assert(fi.Path(), check.Equals, filePath)
|
||||||
c.Assert(fi.Size(), check.Equals, int64(len(content)))
|
c.Assert(fi.Size(), check.Equals, int64(len(content)))
|
||||||
c.Assert(fi.IsDir(), check.Equals, false)
|
c.Assert(fi.IsDir(), check.Equals, false)
|
||||||
|
createdTime := fi.ModTime()
|
||||||
|
|
||||||
if start.After(fi.ModTime()) {
|
// Sleep and modify the file
|
||||||
c.Errorf("modtime %s before file created (%v)", fi.ModTime(), start)
|
time.Sleep(time.Second * 10)
|
||||||
|
content = randomContents(4096)
|
||||||
|
err = suite.StorageDriver.PutContent(filePath, content)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
fi, err = suite.StorageDriver.Stat(filePath)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
c.Assert(fi, check.NotNil)
|
||||||
|
time.Sleep(time.Second * 5) // allow changes to propagate (eventual consistency)
|
||||||
|
|
||||||
|
// Check if the modification time is after the creation time.
|
||||||
|
// In case of cloud storage services, storage frontend nodes might have
|
||||||
|
// time drift between them, however that should be solved with sleeping
|
||||||
|
// before update.
|
||||||
|
modTime := fi.ModTime()
|
||||||
|
if !modTime.After(createdTime) {
|
||||||
|
c.Errorf("modtime (%s) is before the creation time (%s)", modTime, createdTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.ModTime().After(expectedModTime) {
|
// Call on directory (do not check ModTime as dirs don't need to support it)
|
||||||
c.Errorf("modtime %s after file created (%v)", fi.ModTime(), expectedModTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call on directory
|
|
||||||
start = time.Now().Truncate(time.Second)
|
|
||||||
fi, err = suite.StorageDriver.Stat(dirPath)
|
fi, err = suite.StorageDriver.Stat(dirPath)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
expectedModTime = time.Now()
|
|
||||||
c.Assert(fi, check.NotNil)
|
c.Assert(fi, check.NotNil)
|
||||||
c.Assert(fi.Path(), check.Equals, dirPath)
|
c.Assert(fi.Path(), check.Equals, dirPath)
|
||||||
c.Assert(fi.Size(), check.Equals, int64(0))
|
c.Assert(fi.Size(), check.Equals, int64(0))
|
||||||
c.Assert(fi.IsDir(), check.Equals, true)
|
c.Assert(fi.IsDir(), check.Equals, true)
|
||||||
|
|
||||||
// Directories do not need to support ModTime, since key-value stores
|
|
||||||
// cannot support it efficiently.
|
|
||||||
// if start.After(fi.ModTime()) {
|
|
||||||
// c.Errorf("modtime %s before file created (%v)", fi.ModTime(), start)
|
|
||||||
// }
|
|
||||||
|
|
||||||
if fi.ModTime().After(expectedModTime) {
|
|
||||||
c.Errorf("modtime %s after file created (%v)", fi.ModTime(), expectedModTime)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestConcurrentStreamReads checks that multiple clients can safely read from
|
// TestConcurrentStreamReads checks that multiple clients can safely read from
|
||||||
|
Loading…
Reference in New Issue
Block a user