[🤖] Add Unit-Tests
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m34s

This commit is contained in:
2026-04-27 10:46:08 +02:00
parent dad0e3240d
commit 02d6894ec6
116 changed files with 18795 additions and 1 deletions
+51
View File
@@ -0,0 +1,51 @@
package dataext
import (
"sync"
"sync/atomic"
"testing"
)
func TestMutexSet_BasicLockUnlock(t *testing.T) {
ms := NewMutexSet[string]()
ms.Lock("a")
ms.Unlock("a")
ms.RLock("b")
ms.RUnlock("b")
}
func TestMutexSet_DifferentKeysIndependent(t *testing.T) {
ms := NewMutexSet[int]()
ms.Lock(1)
ms.Lock(2)
ms.Unlock(1)
ms.Unlock(2)
}
func TestMutexSet_SameKeyMutuallyExclusive(t *testing.T) {
ms := NewMutexSet[string]()
var counter int64
const n = 50
var wg sync.WaitGroup
wg.Add(n)
for i := 0; i < n; i++ {
go func() {
defer wg.Done()
ms.Lock("shared")
atomic.AddInt64(&counter, 1)
ms.Unlock("shared")
}()
}
wg.Wait()
if atomic.LoadInt64(&counter) != n {
t.Fatalf("got %d want %d", counter, n)
}
}
func TestMutexSet_RLockMultiple(t *testing.T) {
ms := NewMutexSet[string]()
ms.RLock("k")
ms.RLock("k")
ms.RUnlock("k")
ms.RUnlock("k")
}