From 4e6d37095c6c75632ca9c4af2cbb3276364c2e5a Mon Sep 17 00:00:00 2001 From: Marc Pervaz Boocha Date: Tue, 25 Feb 2025 09:46:37 +0530 Subject: Add additional test cases to improve coverage and robustness --- conn_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'conn_test.go') 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) { -- cgit v1.2.3-70-g09d2