fix: gc was being stupid allowing another thread to take the space it made before it could not anymore
All checks were successful
PR Check / check-and-test (pull_request) Successful in 12s

This commit is contained in:
2025-07-13 07:50:22 -05:00
parent 7f744d04b0
commit 3427b8f5bc
6 changed files with 68 additions and 79 deletions

View File

@@ -5,13 +5,12 @@ import (
"errors"
"fmt"
"s1d3sw1ped/SteamCache2/vfs/memory"
"s1d3sw1ped/SteamCache2/vfs/vfserror"
"testing"
)
func TestGCOnFull(t *testing.T) {
m := memory.New(10)
gc := New(m, 2, LRUGC)
gc := New(m, LRUGC)
for i := 0; i < 5; i++ {
w, err := gc.Create(fmt.Sprintf("key%d", i), 2)
@@ -43,7 +42,7 @@ func TestGCOnFull(t *testing.T) {
func TestNoGCNeeded(t *testing.T) {
m := memory.New(20)
gc := New(m, 2, LRUGC)
gc := New(m, LRUGC)
for i := 0; i < 5; i++ {
w, err := gc.Create(fmt.Sprintf("key%d", i), 2)
@@ -61,13 +60,13 @@ func TestNoGCNeeded(t *testing.T) {
func TestGCInsufficientSpace(t *testing.T) {
m := memory.New(5)
gc := New(m, 1, LRUGC)
gc := New(m, LRUGC)
w, err := gc.Create("key0", 10)
if err == nil {
w.Close()
t.Error("Expected ErrDiskFull")
} else if !errors.Is(err, vfserror.ErrDiskFull) {
} else if !errors.Is(err, ErrInsufficientSpace) {
t.Errorf("Unexpected error: %v", err)
}
}