Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
komuw committed Dec 20, 2023
1 parent b199944 commit cce600b
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,46 +55,46 @@ func TestSync(t *testing.T) {
}
})

// go func() {
// {
// err := wg.Go(func() error {
// count = count + 1
// fmt.Println("\n\t count1: ", count)
// return nil
// })

// attest.Ok(t, err)
// }

// {
// err := wg.Go(func() error {
// count = count + 1
// fmt.Println("\n\t count1: ", count)
// return nil
// })

// attest.Ok(t, err)
// }
// }()

// var active int32
// funcs := []func() error{}
// for i := 0; i <= 1<<10; i++ {
// funcs = append(
// funcs,
// func() error {
// n := atomic.AddInt32(&active, 1)
// if n > limit {
// return fmt.Errorf("saw %d active goroutines; want ≤ %d", n, limit)
// }
// time.Sleep(1 * time.Microsecond) // Give other goroutines a chance to increment active.
// atomic.AddInt32(&active, -1)
// return nil
// },
// )
// }

// if err := g.Go(funcs...); err != nil {
// t.Fatal(err)
// }
t.Run("concurrency", func(t *testing.T) {
t.Parallel()

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

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

go func() {
err := wgLimited.Go(funcs...)
attest.Ok(t, err)
}()
err := wgLimited.Go(funcs...)
attest.Ok(t, err)
}

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

go func() {
err := wgUnlimited.Go(funcs...)
attest.Ok(t, err)
}()
err := wgUnlimited.Go(funcs...)
attest.Ok(t, err)
}
})
}

0 comments on commit cce600b

Please sign in to comment.