mirror of
https://github.com/pgsty/minio.git
synced 2026-07-19 12:10:24 +03:00
fix: allow diskInfo at storageRPC to be cached (#19112)
Bonus: convert timedValue into a typed implementation
This commit is contained in:
+5
-8
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user