Merge pull request #77 from ahmetalpbalkan/TestStatCall-fix
Allow modtime to be a few seconds off on TestStatCall
This commit is contained in:
commit
1650088629
1 changed files with 19 additions and 21 deletions
|
@ -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 a new issue