Skip to content

Commit

Permalink
adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Apr 29, 2024
1 parent 06e9b1b commit f785d20
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/cespare/xxhash v1.1.0
github.com/charmbracelet/glamour v0.6.0
github.com/docker/go-units v0.5.0
github.com/fortytw2/leaktest v1.3.0
github.com/google/go-github/v30 v30.1.0
github.com/google/uuid v1.3.1
github.com/hdm/jarm-go v0.0.7
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ github.com/ebitengine/purego v0.4.0 h1:RQVuMIxQPQ5iCGEJvjQ17YOK+1tMKjVau2FUMvXH4
github.com/ebitengine/purego v0.4.0/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
Expand Down
49 changes: 49 additions & 0 deletions sync/adaptivewaitgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sync/atomic"
"testing"

"github.com/fortytw2/leaktest"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -91,3 +92,51 @@ func TestAddWithContext(t *testing.T) {
}

}

func TestMultipleResizes(t *testing.T) {
var c atomic.Int32
swg, err := New(WithSize(2)) // Start with a size of 2
require.Nil(t, err)

for i := 0; i < 10000; i++ {
if i == 250 {
swg.Resize(context.TODO(), 5) // Increase size at 2500th iteration

Check failure on line 103 in sync/adaptivewaitgroup_test.go

View workflow job for this annotation

GitHub Actions / Lint Test

Error return value of `swg.Resize` is not checked (errcheck)
}
if i == 500 {
swg.Resize(context.TODO(), 1) // Decrease size at 5000th iteration

Check failure on line 106 in sync/adaptivewaitgroup_test.go

View workflow job for this annotation

GitHub Actions / Lint Test

Error return value of `swg.Resize` is not checked (errcheck)
}
if i == 750 {
swg.Resize(context.TODO(), 3) // Increase size again at 7500th iteration

Check failure on line 109 in sync/adaptivewaitgroup_test.go

View workflow job for this annotation

GitHub Actions / Lint Test

Error return value of `swg.Resize` is not checked (errcheck)
}

swg.Add()
go func() {
defer swg.Done()
c.Add(1)
}()
}

swg.Wait()
if c.Load() != 10000 {
t.Fatalf("%d, not all routines have been executed.", c.Load())
}
}

func Test_AdaptiveWaitGroup_Leak(t *testing.T) {
defer leaktest.Check(t)()

for j := 0; j < 1000; j++ {
wg, err := New(WithSize(10))
if err != nil {
t.Fatal(err)
}

for i := 0; i < 10000; i++ {
wg.Add()
go func(awg *AdaptiveWaitGroup) {
defer awg.Done()
}(wg)
}
wg.Wait()
}
}

0 comments on commit f785d20

Please sign in to comment.