Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyXSD committed May 12, 2023
1 parent 364311d commit c9b88f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
9 changes: 3 additions & 6 deletions pkg/fuse/fuse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (
)

func format(url string) {
m := meta.NewClient(url, &meta.Config{})
m := meta.NewClient(url, nil)
format := &meta.Format{
Name: "test",
UUID: uuid.New().String(),
Expand All @@ -63,11 +63,8 @@ func mount(url, mp string) {
log.Fatalf("create %s: %s", mp, err)
}

metaConf := &meta.Config{
Retries: 10,
Strict: true,
MountPoint: mp,
}
metaConf := meta.DefaultConf()
metaConf.MountPoint = mp
m := meta.NewClient(url, metaConf)
format, err := m.Load(true)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ func (m *baseMeta) getTreeSummary(ctx Context, tree *TreeSummary, depth, topN ui
}

func (m *baseMeta) atimeNeedsUpdate(attr *Attr, now time.Time) bool {
return relatimeNeedUpdate(attr, now) ||
return m.conf.AtimeMode != NoAtime && relatimeNeedUpdate(attr, now) ||
// update atime only for > 1 second accesses
m.conf.AtimeMode == StrictAtime && now.Sub(time.Unix(attr.Atime, int64(attr.Atimensec))) > time.Second
}
Expand Down
19 changes: 9 additions & 10 deletions pkg/meta/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,29 @@ func TestAtimeNeedsUpdate(t *testing.T) {
attr := &Attr{
Atime: 1000,
}
if m.atimeNeedsUpdate(attr, time.Now()) {
now := time.Now()
if m.atimeNeedsUpdate(attr, now) {
t.Fatal("atime updated for noatime")
}

m.conf.AtimeMode = RelAtime
if !m.atimeNeedsUpdate(attr, time.Now()) {
if !m.atimeNeedsUpdate(attr, now) {
t.Fatal("atime not updated for relatime")
}
attr.Atime = time.Now().Unix()
if m.atimeNeedsUpdate(attr, time.Now()) {
attr.Atime = now.Unix()
if m.atimeNeedsUpdate(attr, now) {
t.Fatal("atime updated for relatime")
}

m.conf.AtimeMode = StrictAtime
time.Sleep(2 * time.Second)
if !m.atimeNeedsUpdate(attr, time.Now()) {
attr.Atime = now.Unix() - 2
if !m.atimeNeedsUpdate(attr, now) {
t.Fatal("atime not updated for strictatime")
}

now := time.Now()
attr.Atime = now.Unix()
attr.Atime = now.Unix() - 1
attr.Atimensec = uint32(now.Nanosecond())
time.Sleep(time.Millisecond)
if m.atimeNeedsUpdate(attr, time.Now()) {
if m.atimeNeedsUpdate(attr, now) {
t.Fatal("atime updated for strictatime when < 1s")
}
}

0 comments on commit c9b88f2

Please sign in to comment.