(Feat): Initial Commit
Some checks failed
Build & Test / build-test (push) Has been cancelled
Build & Test / swagger-codegen-cli (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled

This commit is contained in:
2026-07-03 19:41:31 +05:30
commit 7e940c83a7
461 changed files with 45002 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package util_test
import (
"sync"
"sync/atomic"
"testing"
"time"
"allaboutapps.dev/aw/go-starter/internal/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestWaitTimeoutErr(t *testing.T) {
var wg sync.WaitGroup
var n int32
wg.Add(1)
go func() {
atomic.AddInt32(&n, 1)
time.Sleep(10 * time.Millisecond)
atomic.AddInt32(&n, 1)
wg.Done()
}()
wg.Add(1)
go func() {
atomic.AddInt32(&n, 1)
wg.Done()
}()
wg.Add(1)
go func() {
time.Sleep(400 * time.Millisecond)
atomic.AddInt32(&n, 1) // available after wg.Wait()
wg.Done()
}()
// timeout reached.
err := util.WaitTimeout(&wg, 200*time.Millisecond)
assert.Equal(t, util.ErrWaitTimeout, err)
assert.Equal(t, int32(3), atomic.LoadInt32(&n))
// ok (after timeout).
err = util.WaitTimeout(&wg, 800*time.Second)
require.NoError(t, err)
assert.Equal(t, int32(4), atomic.LoadInt32(&n))
}