@@ -130,7 +130,58 @@ func TestBroadcastBatch(t *testing.T) {
130
130
}
131
131
return
132
132
case <- time .After (500 * time .Millisecond ):
133
- t .Fatal ("Should have received the initialization block by now" )
133
+ t .Fatal ("Should have received a block by now" )
134
+ }
135
+ }
136
+ }
137
+
138
+ func TestBroadcastIncompleteBatch (t * testing.T ) {
139
+ if testConf .General .BatchSize <= 1 {
140
+ t .Skip ("Skipping test as it requires a batchsize > 1" )
141
+ }
142
+
143
+ messageCount := int (testConf .General .BatchSize ) - 1
144
+
145
+ disk := make (chan []byte )
146
+
147
+ mb := mockNewBroadcaster (t , testConf , oldestOffset , disk )
148
+ defer testClose (t , mb )
149
+
150
+ mbs := newMockBroadcastStream (t )
151
+ go func () {
152
+ if err := mb .Broadcast (mbs ); err != nil {
153
+ t .Fatal ("Broadcast error:" , err )
154
+ }
155
+ }()
156
+
157
+ <- disk // We tested the checkpoint block in a previous test, so we can ignore it now
158
+
159
+ // Pump less than batchSize messages into the system
160
+ go func () {
161
+ for i := 0 ; i < messageCount ; i ++ {
162
+ mbs .incoming <- & ab.BroadcastMessage {Data : []byte ("message " + strconv .Itoa (i ))}
163
+ }
164
+ }()
165
+
166
+ // Ignore the broadcast replies as they have been tested elsewhere
167
+ for i := 0 ; i < messageCount ; i ++ {
168
+ <- mbs .outgoing
169
+ }
170
+
171
+ for {
172
+ select {
173
+ case in := <- disk :
174
+ block := new (ab.Block )
175
+ err := proto .Unmarshal (in , block )
176
+ if err != nil {
177
+ t .Fatal ("Expected a block on the broker's disk" )
178
+ }
179
+ if len (block .Messages ) != messageCount {
180
+ t .Fatalf ("Expected block to have %d messages instead of %d" , messageCount , len (block .Messages ))
181
+ }
182
+ return
183
+ case <- time .After (testConf .General .BatchTimeout + timePadding ):
184
+ t .Fatal ("Should have received a block by now" )
134
185
}
135
186
}
136
187
}
@@ -177,7 +228,7 @@ func TestBroadcastBatchAndQuitEarly(t *testing.T) {
177
228
}
178
229
return
179
230
case <- time .After (500 * time .Millisecond ):
180
- t .Fatal ("Should have received the initialization block by now" )
231
+ t .Fatal ("Should have received a block by now" )
181
232
}
182
233
}
183
234
}
0 commit comments