Skip to content

Commit

Permalink
d
Browse files Browse the repository at this point in the history
  • Loading branch information
komuw committed Dec 20, 2023
1 parent cce600b commit 5e94264
Showing 1 changed file with 68 additions and 6 deletions.
74 changes: 68 additions & 6 deletions sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@ import (
"context"
"testing"

"golang.org/x/sync/errgroup"

"go.akshayshah.org/attest"
)

func TestSync(t *testing.T) {
t.Parallel()

wgLimited, _ := New(context.Background(), 1)
wgUnlimited, _ := New(context.Background(), -1)

t.Run("zero funcs", func(t *testing.T) {
t.Parallel()

{
wgLimited, _ := New(context.Background(), 1)
count := 0
err := wgLimited.Go()
attest.Ok(t, err)
attest.Equal(t, count, 0)
}

{
wgUnlimited, _ := New(context.Background(), -1)
count := 0
err := wgUnlimited.Go()
attest.Ok(t, err)
Expand All @@ -35,6 +36,7 @@ func TestSync(t *testing.T) {
t.Parallel()

{
wgLimited, _ := New(context.Background(), 1)
count := 0
err := wgLimited.Go(func() error {
count = count + 1
Expand All @@ -45,6 +47,7 @@ func TestSync(t *testing.T) {
}

{
wgUnlimited, _ := New(context.Background(), -1)
count := 0
err := wgUnlimited.Go(func() error {
count = count + 1
Expand All @@ -58,10 +61,9 @@ func TestSync(t *testing.T) {
t.Run("concurrency", func(t *testing.T) {
t.Parallel()

wgLimited, _ := New(context.Background(), 1)
wgUnlimited, _ := New(context.Background(), -1)

{
wgLimited, _ := New(context.Background(), 1)

funcs := []func() error{}
for i := 0; i <= 4; i++ {
funcs = append(funcs,
Expand All @@ -80,6 +82,8 @@ func TestSync(t *testing.T) {
}

{
wgUnlimited, _ := New(context.Background(), -1)

funcs := []func() error{}
for i := 0; i <= 4; i++ {
funcs = append(funcs,
Expand All @@ -98,3 +102,61 @@ func TestSync(t *testing.T) {
}
})
}

func TestErrGroup(t *testing.T) {
t.Parallel()

t.Run("concurrency", func(t *testing.T) {
t.Parallel()

// wgLimited, _ := errgroup.WithContext(context.Background())
// wgLimited.SetLimit(1)
wgUnlimited, _ := errgroup.WithContext(context.Background())

// {
// funcs := []func() error{}
// for i := 0; i <= 4; i++ {
// funcs = append(funcs,
// func() error {
// return nil
// },
// )
// }

// go func() {
// wgLimited.Go(func() error {
// return nil
// })
// }()
// wgLimited.Go(func() error {
// return nil
// })

// err := wgLimited.Wait()
// attest.Ok(t, err)
// }

{
funcs := []func() error{}
for i := 0; i <= 4; i++ {
funcs = append(funcs,

Check failure on line 142 in sync/sync_test.go

View workflow job for this annotation

GitHub Actions / run_analysis (>=1.21.5, ubuntu-22.04)

this result of append is never used, except maybe in other appends (SA4010)
func() error {
return nil
},
)
}

go func() {
wgUnlimited.Go(func() error {
return nil
})
}()
wgUnlimited.Go(func() error {
return nil
})

err := wgUnlimited.Wait()
attest.Ok(t, err)
}
})
}

0 comments on commit 5e94264

Please sign in to comment.