Vasiliy Tolstov
856aac4aa9
Some checks failed
/ autoupdate (push) Failing after 1m12s
Reviewed-on: #319 Co-authored-by: Vasiliy Tolstov <v.tolstov@unistack.org> Co-committed-by: Vasiliy Tolstov <v.tolstov@unistack.org>
38 lines
654 B
Go
38 lines
654 B
Go
package sync
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestWaitGroupContext(t *testing.T) {
|
|
wg := NewWaitGroup()
|
|
_ = t
|
|
wg.Add(1)
|
|
ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Second)
|
|
defer cancel()
|
|
wg.WaitContext(ctx)
|
|
}
|
|
|
|
func TestWaitGroupReuse(t *testing.T) {
|
|
wg := NewWaitGroup()
|
|
defer func() {
|
|
if wg.Waiters() != 0 {
|
|
t.Fatal("lost goroutines")
|
|
}
|
|
}()
|
|
|
|
wg.Add(1)
|
|
defer wg.Done()
|
|
ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Second)
|
|
defer cancel()
|
|
wg.WaitContext(ctx)
|
|
|
|
wg.Add(1)
|
|
defer wg.Done()
|
|
ctx, cancel = context.WithTimeout(context.TODO(), 1*time.Second)
|
|
defer cancel()
|
|
wg.WaitContext(ctx)
|
|
}
|