@@ -58,6 +58,7 @@ func TestFakeBuffer(t *testing.T) {
5858 wantCalled bool
5959 // expected value of BufferedTransactionAttempts
6060 wantAttempted int
61+ wantErr error
6162 }{
6263 {
6364 desc : "enableFakeBuffer=False" ,
@@ -88,6 +89,7 @@ func TestFakeBuffer(t *testing.T) {
8889 bufferedTransactions : * maxBufferSize ,
8990 // When the buffer is full, bufferedTransactionsAttempted should still be incremented
9091 wantAttempted : 1 ,
92+ wantErr : errBufferFull ,
9193 },
9294 {
9395 desc : "buffered successful" ,
@@ -107,7 +109,11 @@ func TestFakeBuffer(t *testing.T) {
107109
108110 * enableFakeTxBuffer = test .enableFakeBuffer
109111
110- FakeBuffer (test .keyspace , test .shard , test .attemptNumber )
112+ gotErr := FakeBuffer (test .keyspace , test .shard , test .attemptNumber )
113+
114+ if gotErr != test .wantErr {
115+ t .Errorf ("With %v, FakeBuffer() => %v; want: %v" , test .desc , gotErr , test .wantErr )
116+ }
111117
112118 if controller .called != test .wantCalled {
113119 t .Errorf ("With %v, FakeBuffer() => timeSleep.called: %v; want: %v" ,
@@ -162,23 +168,27 @@ func TestParallelFakeBuffer(t *testing.T) {
162168
163169 wg .Add (1 )
164170 finished := make (chan struct {})
171+ var gotErr error
165172 go func () {
166173 defer wg .Done ()
167- FakeBuffer (* bufferKeyspace , * bufferShard , 0 )
174+ gotErr = FakeBuffer (* bufferKeyspace , * bufferShard , 0 )
168175 close (finished )
169176 }()
170177
171- if wantFakeSleepCalled {
172- // the first maxBufferSize calls to FakeBuffer
173- // should call sleep, wait until they do
174- <- controller .blocked
175- } else {
176- // the rest should not block, wait until they're done
177- <- finished
178+ // wait until either the gorouotine is blocked (because it's buffering) or until
179+ // it's finished (because it shouldn't be buffered).
180+ select {
181+ case <- controller .blocked :
182+ case <- finished :
178183 }
179184
180185 if controller .called {
181186 controllers = append (controllers , controller )
187+ } else {
188+ // if we didn't call fakeSleep, the buffer is full and should return an error saying so.
189+ if gotErr != errBufferFull {
190+ t .Errorf ("On iteration %v, FakeBuffer() => %v; want: %v" , i , gotErr , errBufferFull )
191+ }
182192 }
183193
184194 if controller .called != wantFakeSleepCalled {
0 commit comments