Files
EdgeNode/internal/utils/fs/stat_test.go

71 lines
1.4 KiB
Go
Raw Permalink Normal View History

2024-07-27 15:42:50 +08:00
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package fsutils_test
import (
"sync"
"testing"
"time"
2024-07-27 15:42:50 +08:00
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
)
func TestStat(t *testing.T) {
2023-08-15 15:49:23 +08:00
stat, err := fsutils.StatDevice("/usr/local")
if err != nil {
t.Fatal(err)
}
t.Log("free:", stat.FreeSize()/(1<<30), "total:", stat.TotalSize()/(1<<30), "used:", stat.UsedSize()/(1<<30))
}
func TestStatCache(t *testing.T) {
for i := 0; i < 10; i++ {
2023-08-15 15:49:23 +08:00
stat, err := fsutils.StatDeviceCache("/usr/local")
if err != nil {
t.Fatal(err)
}
t.Log("free:", stat.FreeSize()/(1<<30), "total:", stat.TotalSize()/(1<<30), "used:", stat.UsedSize()/(1<<30))
}
}
func TestConcurrent(t *testing.T) {
var before = time.Now()
defer func() {
t.Log(time.Since(before).Seconds()*1000, "ms")
}()
var count = 10000
var wg = sync.WaitGroup{}
wg.Add(count)
for i := 0; i < count; i++ {
go func() {
defer wg.Done()
2023-08-15 15:49:23 +08:00
_, _ = fsutils.StatDevice("/usr/local")
}()
}
wg.Wait()
}
2023-08-15 15:49:23 +08:00
func BenchmarkStatDevice(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
2023-08-15 15:49:23 +08:00
_, err := fsutils.StatDevice("/usr/local")
if err != nil {
b.Fatal(err)
}
}
})
}
2023-08-15 15:49:23 +08:00
func BenchmarkStatCacheDevice(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
2023-08-15 15:49:23 +08:00
_, err := fsutils.StatDeviceCache("/usr/local")
if err != nil {
b.Fatal(err)
}
}
})
}