fix: allow diskInfo at storageRPC to be cached (#19112)

Bonus: convert timedValue into a typed implementation
This commit is contained in:
Harshavardhana
2024-02-23 09:21:38 -08:00
committed by GitHub
parent ee158e1610
commit 2faba02d6b
10 changed files with 124 additions and 126 deletions
+5 -8
View File
@@ -402,28 +402,25 @@ func TestGetMinioMode(t *testing.T) {
}
func TestTimedValue(t *testing.T) {
var cache timedValue
cache := newTimedValue[time.Time]()
t.Parallel()
cache.Once.Do(func() {
cache.TTL = 2 * time.Second
cache.Update = func() (interface{}, error) {
cache.Update = func() (time.Time, error) {
return time.Now(), nil
}
})
i, _ := cache.Get()
t1 := i.(time.Time)
t1, _ := cache.Get()
j, _ := cache.Get()
t2 := j.(time.Time)
t2, _ := cache.Get()
if !t1.Equal(t2) {
t.Fatalf("expected time to be equal: %s != %s", t1, t2)
}
time.Sleep(3 * time.Second)
k, _ := cache.Get()
t3 := k.(time.Time)
t3, _ := cache.Get()
if t1.Equal(t3) {
t.Fatalf("expected time to be un-equal: %s == %s", t1, t3)