aboutsummaryrefslogtreecommitdiffstats
path: root/conn_test.go
diff options
context:
space:
mode:
authorMarc Pervaz Boocha <marcpervaz@qburst.com>2025-02-25 09:46:37 +0530
committerMarc Pervaz Boocha <marcpervaz@qburst.com>2025-02-27 13:38:02 +0530
commit4e6d37095c6c75632ca9c4af2cbb3276364c2e5a (patch)
tree22540501437a80f8c36d3075eb8372444f513ad4 /conn_test.go
parentAdded examples and documentation (diff)
downloadcache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar
cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.gz
cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.bz2
cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.lz
cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.xz
cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.zst
cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.zip
Add additional test cases to improve coverage and robustness
Diffstat (limited to 'conn_test.go')
-rw-r--r--conn_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/conn_test.go b/conn_test.go
index d1581f3..d6c284e 100644
--- a/conn_test.go
+++ b/conn_test.go
@@ -17,6 +17,23 @@ func setupTestDB[K any, V any](t testing.TB) *DB[K, V] {
db.Close()
})
return &db
+func TestDBConcurrentAccess(t *testing.T) {
+ db := setupTestDB[string, string](t)
+
+ go func() {
+ for i := 0; i < 100; i++ {
+ db.Set(fmt.Sprintf("Key%d", i), "Value", 0)
+ }
+ }()
+
+ go func() {
+ for i := 0; i < 100; i++ {
+ db.GetValue(fmt.Sprintf("Key%d", i))
+ }
+ }()
+
+ // Allow some time for goroutines to complete
+ time.Sleep(1 * time.Second)
}
func TestDBGetSet(t *testing.T) {
@@ -64,6 +81,20 @@ func TestDBGetSet(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, want, got)
})
+
+ t.Run("Key Expiry", func(t *testing.T) {
+ t.Parallel()
+
+ db := setupTestDB[string, string](t)
+
+ err := db.Set("Key", "Value", 500*time.Millisecond)
+ assert.NoError(t, err)
+
+ time.Sleep(600 * time.Millisecond)
+
+ _, _, err = db.GetValue("Key")
+ assert.ErrorIs(t, err, ErrKeyNotFound)
+ })
}
func TestDBDelete(t *testing.T) {