Files
1641c3c852 feat: update for Ledger v2 (#468)
Co-authored-by: Antoine Wacheux <[email protected]>
Co-authored-by: Maxence Maireaux <[email protected]>
Co-authored-by: Brieuc Caillot <[email protected]>
2023-09-20 16:40:28 +02:00

45 lines
801 B
Go

package command
import (
"fmt"
"math/rand"
"sync"
"testing"
"time"
"github.com/formancehq/stack/libs/go-libs/logging"
"github.com/stretchr/testify/require"
)
func TestLock(t *testing.T) {
locker := NewDefaultLocker()
var accounts []string
for i := 0; i < 10; i++ {
accounts = append(accounts, fmt.Sprintf("accounts:%d", i))
}
r := rand.New(rand.NewSource(time.Now().Unix()))
ctx := logging.TestingContext()
const nbLoop = 1000
wg := sync.WaitGroup{}
wg.Add(nbLoop)
for i := 0; i < nbLoop; i++ {
go func() {
unlock, err := locker.Lock(ctx, Accounts{
Read: []string{accounts[r.Int31n(10)]},
Write: []string{accounts[r.Int31n(10)]},
})
require.NoError(t, err)
defer unlock(ctx)
<-time.After(10 * time.Millisecond)
wg.Add(-1)
}()
}
wg.Wait()
}