/
githubmirror
/
rclone
Обзор
Документация
Войти
/
githubmirror
/
rclone
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
backend/sftp/stringlock_test.go
42 строки
651 B
Nick Craig-Wood
build: modernize Go usage
28 фев 2025, 14:31
28 фев 2025, 14:31
401cf81
Код
Авторство
О чём код?
//go:build !plan9 package sftp import ( "fmt" "sync" "testing" "time" "github.com/stretchr/testify/assert" ) func TestStringLock(t *testing.T) { var wg sync.WaitGroup counter := [3]int{} lock := newStringLock() const ( outer = 10 inner = 100 total = outer * inner ) for range outer { for j := range counter { wg.Add(1) go func(j int) { defer wg.Done() ID := fmt.Sprintf("%d", j) for range inner { lock.Lock(ID) n := counter[j] time.Sleep(1 * time.Millisecond) counter[j] = n + 1 lock.Unlock(ID) } }(j) } } wg.Wait() assert.Equal(t, [3]int{total, total, total}, counter) }