Enhance DiskFS initialization and error handling
- Updated `disk.New` to support asynchronous initialization for large caches, improving responsiveness during startup. - Introduced an eviction function parameter to `disk.New`, ensuring proper handling of over-capacity scenarios. - Enhanced error handling in various components, including memory and disk tests, to ensure robustness and clarity. - Refactored tests to validate new behaviors, including checks for delayed attachment and proper error propagation. - Removed obsolete error handling code and tests related to the now-deleted errors package, streamlining the codebase.
This commit is contained in:
@@ -15,7 +15,10 @@ func TestGetEvictionFunction_Default(t *testing.T) {
|
||||
t.Fatal("default eviction fn nil")
|
||||
}
|
||||
// Should be LRU
|
||||
m := memory.New(1024)
|
||||
m, err := memory.New(1024)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// create something to evict
|
||||
w, _ := m.Create("f", 100)
|
||||
w.Write(make([]byte, 100))
|
||||
@@ -28,7 +31,10 @@ func TestGetEvictionFunction_Default(t *testing.T) {
|
||||
|
||||
func TestEvictLRU_Delegates(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := memory.New(1024)
|
||||
m, err := memory.New(1024)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w, _ := m.Create("f1", 1000) // > cap - needed to force
|
||||
w.Write(make([]byte, 1000))
|
||||
w.Close()
|
||||
@@ -55,14 +61,20 @@ func TestEviction_StrategiesAndDispatch(t *testing.T) {
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
m := memory.New(2048)
|
||||
m, err := memory.New(2048)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w, _ := m.Create(fmt.Sprintf("e%04d", 1), 1500)
|
||||
w.Write(make([]byte, 1500))
|
||||
w.Close()
|
||||
_ = c.fn(m, 100)
|
||||
// disk path too (no real fs ops needed for dispatch)
|
||||
td := t.TempDir()
|
||||
d := disk.New(td, 2048)
|
||||
d, err := disk.New(td, 2048, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w2, _ := d.Create(fmt.Sprintf("e%04d", 2), 1500)
|
||||
w2.Write(make([]byte, 1500))
|
||||
w2.Close()
|
||||
|
||||
Reference in New Issue
Block a user