Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334package db
import ( "context" "slices" "testing")
func TestReleasedNarsFreeTheirQuotaAgain(t *testing.T) { ctx := context.Background() qs := NewQuotaStore(newTestDB(t), cacheDefaults(0, 100))
commitReservation(t, qs, reserveBytes(t, qs, alice1, "nar/a.nar.xz", 80)) if res := reserveBytes(t, qs, alice1, "nar/b.nar.xz", 50); res.Allowed { t.Fatal("a 50 byte nar fit next to 80 of a 100 byte limit") }
released, bytes, unmatched, err := qs.ReleaseNixObjects(ctx, []string{"nar/a.nar.xz", "nar/gone.nar.xz"}) if err != nil { t.Fatal(err) } if released != 1 || bytes != 80 || !slices.Equal(unmatched, []string{"nar/gone.nar.xz"}) { t.Fatalf("released %d allocations, %d bytes, unmatched %v, want 1, 80 and the unknown one", released, bytes, unmatched) } if res := reserveBytes(t, qs, alice1, "nar/b.nar.xz", 50); !res.Allowed { t.Fatalf("the nar still doesn't fit after the release: %+v", res) }
released, bytes, unmatched, err = qs.ReleaseNixObjects(ctx, []string{"nar/a.nar.xz"}) if err != nil || released != 0 || bytes != 0 || len(unmatched) != 1 { t.Fatalf("second release = %d, %d, %v, %v, want nothing released", released, bytes, unmatched, err) }}