Import Anubis v1.28.2
Replace the tree with upstream TecharoHQ/anubis v1.28.2 (a1384fbf42e3). Masyunis customizations are re-applied in the following commits.
This commit is contained in:
1 parent
eb3e46d8d0
commit
e07de898cd
573 files changed
+35846
-6807
No files matched your search
@@ -0,0 +1,56 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/TecharoHQ/anubis/lib/store"
|
||||
)
|
||||
|
||||
func TestStoreCapacity(t *testing.T) {
|
||||
st := New(t.Context())
|
||||
for idx := range 10001 {
|
||||
if err := st.Set(t.Context(), fmt.Sprint(idx), []byte("value"), time.Hour); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := st.Get(t.Context(), "0"); !errors.Is(err, store.ErrNotFound) {
|
||||
t.Fatalf("oldest key retained beyond capacity: %v", err)
|
||||
}
|
||||
if _, err := st.Get(t.Context(), "10000"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreCapacityPreservesUpdates(t *testing.T) {
|
||||
st := New(t.Context())
|
||||
for range 10001 {
|
||||
if err := st.Set(t.Context(), "same", []byte("value"), time.Hour); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := st.Get(t.Context(), "same"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCapacityWithConcurrentWrites(t *testing.T) {
|
||||
st := New(t.Context()).(*impl)
|
||||
var wg sync.WaitGroup
|
||||
for worker := range 16 {
|
||||
wg.Go(func() {
|
||||
for idx := range 1000 {
|
||||
if err := st.Set(t.Context(), fmt.Sprintf("%d-%d", worker, idx), []byte("value"), time.Hour); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
if got := st.store.Len(); got > maxEntries {
|
||||
t.Fatalf("concurrent writes exceeded capacity: %d", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user