Files
kandev/apps/backend/internal/common/taskdependencies/lock_test.go
T
2026-09-04 02:35:15 +00:00

30 lines
589 B
Go

package taskdependencies
import (
"testing"
"time"
)
func TestAcquireMutationLockSerializesCallers(t *testing.T) {
unlock := AcquireMutationLock()
acquired := make(chan struct{})
go func() {
secondUnlock := AcquireMutationLock()
close(acquired)
secondUnlock()
}()
select {
case <-acquired:
t.Fatal("second caller acquired the mutation lock before the first released it")
case <-time.After(100 * time.Millisecond):
}
unlock()
select {
case <-acquired:
case <-time.After(time.Second):
t.Fatal("second caller did not acquire the mutation lock after release")
}
}