Skip to content

Commit d472a98

Browse files
committed
Test multiple multiple row iters at the same time
Signed-off-by: Javi Fontan <[email protected]>
1 parent 7deadee commit d472a98

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

repositories_test.go

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gitquery
22

33
import (
44
"io"
5+
"sync"
56
"testing"
67

78
"github.com/stretchr/testify/require"
@@ -159,6 +160,29 @@ func (d *testCommitIter) Close() error {
159160
return nil
160161
}
161162

163+
func testRepoIter(num int, require *require.Assertions, pool *RepositoryPool) {
164+
cIter := &testCommitIter{}
165+
166+
rowRepoIter, err := NewRowRepoIter(pool, cIter)
167+
require.Nil(err)
168+
169+
count := 0
170+
for {
171+
row, err := rowRepoIter.Next()
172+
if err != nil {
173+
require.Equal(io.EOF, err)
174+
break
175+
}
176+
177+
require.Nil(row)
178+
179+
count++
180+
}
181+
182+
// 9 is the number of commits from the test repo
183+
require.Equal(9*num, count)
184+
}
185+
162186
func TestRepositoryRowIterator(t *testing.T) {
163187
require := require.New(t)
164188

@@ -173,24 +197,19 @@ func TestRepositoryRowIterator(t *testing.T) {
173197
require.Nil(err)
174198
}
175199

176-
cIter := &testCommitIter{}
177-
178-
rowRepoIter, err := NewRowRepoIter(&pool, cIter)
179-
require.Nil(err)
200+
testRepoIter(max, require, &pool)
180201

181-
count := 0
182-
for {
183-
row, err := rowRepoIter.Next()
184-
if err != nil {
185-
require.Equal(io.EOF, err)
186-
break
187-
}
202+
// Test multiple iterators at the same time
188203

189-
require.Nil(row)
204+
var wg sync.WaitGroup
190205

191-
count++
206+
for i := 0; i < 4; i++ {
207+
wg.Add(1)
208+
go func() {
209+
testRepoIter(max, require, &pool)
210+
wg.Done()
211+
}()
192212
}
193213

194-
// 9 is the number of commits from the test repo
195-
require.Equal(9*max, count)
214+
wg.Wait()
196215
}

0 commit comments

Comments
 (0)