@@ -2,6 +2,7 @@ package gitquery
2
2
3
3
import (
4
4
"io"
5
+ "sync"
5
6
"testing"
6
7
7
8
"github.com/stretchr/testify/require"
@@ -159,6 +160,29 @@ func (d *testCommitIter) Close() error {
159
160
return nil
160
161
}
161
162
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
+
162
186
func TestRepositoryRowIterator (t * testing.T ) {
163
187
require := require .New (t )
164
188
@@ -173,24 +197,19 @@ func TestRepositoryRowIterator(t *testing.T) {
173
197
require .Nil (err )
174
198
}
175
199
176
- cIter := & testCommitIter {}
177
-
178
- rowRepoIter , err := NewRowRepoIter (& pool , cIter )
179
- require .Nil (err )
200
+ testRepoIter (max , require , & pool )
180
201
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
188
203
189
- require . Nil ( row )
204
+ var wg sync. WaitGroup
190
205
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
+ }()
192
212
}
193
213
194
- // 9 is the number of commits from the test repo
195
- require .Equal (9 * max , count )
214
+ wg .Wait ()
196
215
}
0 commit comments