1
1
use crate :: quorum:: { AckIndexer , AckedIndexer , Index } ;
2
2
use crate :: { default_logger, HashMap , HashSet , JointConfig , MajorityConfig } ;
3
3
use datadriven:: { run_test, TestData } ;
4
+ use std:: fmt:: Write ;
4
5
5
6
fn test_quorum ( data : & TestData ) -> String {
6
7
// Two majority configs. The first one is always used (though it may
@@ -177,7 +178,7 @@ fn test_quorum(data: &TestData) -> String {
177
178
let a_idx = JointConfig :: new_joint_from_majorities ( cj, c)
178
179
. committed_index ( use_group_commit, & l) ;
179
180
if a_idx != idx {
180
- buf . push_str ( & format ! ( "{} <-- via symmetry\n " , a_idx. 0 ) ) ;
181
+ writeln ! ( buf , "{} <-- via symmetry" , a_idx. 0 ) . unwrap ( ) ;
181
182
}
182
183
} else {
183
184
idx = c. committed_index ( use_group_commit, & l) ;
@@ -188,14 +189,14 @@ fn test_quorum(data: &TestData) -> String {
188
189
JointConfig :: new_joint_from_majorities ( c. clone ( ) , MajorityConfig :: default ( ) )
189
190
. committed_index ( use_group_commit, & l) ;
190
191
if a_idx != idx {
191
- buf . push_str ( & format ! ( "{} <-- via zero-joint quorum\n " , a_idx. 0 ) ) ;
192
+ writeln ! ( buf , "{} <-- via zero-joint quorum" , a_idx. 0 ) . unwrap ( ) ;
192
193
}
193
194
194
195
// Joining a majority with itself should give same result.
195
196
let a_idx = JointConfig :: new_joint_from_majorities ( c. clone ( ) , c. clone ( ) )
196
197
. committed_index ( use_group_commit, & l) ;
197
198
if a_idx != idx {
198
- buf . push_str ( & format ! ( "{} <-- via self-joint quorum\n " , a_idx. 0 ) ) ;
199
+ writeln ! ( buf , "{} <-- via self-joint quorum" , a_idx. 0 ) . unwrap ( ) ;
199
200
}
200
201
201
202
// test overlaying
@@ -215,12 +216,14 @@ fn test_quorum(data: &TestData) -> String {
215
216
216
217
let a_idx = c. committed_index ( use_group_commit, & l) ;
217
218
if a_idx != idx {
218
- buf. push_str ( & format ! (
219
- "{} <-- overlaying {}->{}\n " ,
219
+ writeln ! (
220
+ buf,
221
+ "{} <-- overlaying {}->{}" ,
220
222
a_idx. 0 ,
221
223
id,
222
224
iidx. index - 1
223
- ) ) ;
225
+ )
226
+ . unwrap ( ) ;
224
227
}
225
228
// try 0
226
229
l. insert (
@@ -233,24 +236,23 @@ fn test_quorum(data: &TestData) -> String {
233
236
234
237
let a_idx = c. committed_index ( use_group_commit, & l) ;
235
238
if a_idx != idx {
236
- buf. push_str ( & format ! (
237
- "{} <-- overlaying {}->{}\n " ,
238
- a_idx. 0 , id, 0
239
- ) ) ;
239
+ writeln ! ( buf, "{} <-- overlaying {}->{}" , a_idx. 0 , id, 0 ) . unwrap ( ) ;
240
240
}
241
241
// recovery
242
242
l. insert ( id, iidx) ;
243
243
}
244
244
}
245
245
}
246
246
}
247
- buf. push_str ( & format ! (
248
- "{}\n " ,
247
+ writeln ! (
248
+ buf,
249
+ "{}" ,
249
250
Index {
250
251
index: idx. 0 ,
251
252
group_id: 0
252
253
}
253
- ) ) ;
254
+ )
255
+ . unwrap ( ) ;
254
256
}
255
257
"group_committed" => {
256
258
let use_group_commit = true ;
@@ -268,18 +270,20 @@ fn test_quorum(data: &TestData) -> String {
268
270
let a_idx = JointConfig :: new_joint_from_majorities ( cj, c)
269
271
. committed_index ( use_group_commit, & l) ;
270
272
if a_idx != idx {
271
- buf . push_str ( & format ! ( "{} <-- via symmetry\n " , a_idx. 0 ) ) ;
273
+ writeln ! ( buf , "{} <-- via symmetry" , a_idx. 0 ) . unwrap ( ) ;
272
274
}
273
275
} else {
274
276
// TODO: majority group commit
275
277
}
276
- buf. push_str ( & format ! (
277
- "{}\n " ,
278
+ writeln ! (
279
+ buf,
280
+ "{}" ,
278
281
Index {
279
282
index: idx. 0 ,
280
283
group_id: 0
281
284
}
282
- ) ) ;
285
+ )
286
+ . unwrap ( ) ;
283
287
}
284
288
"vote" => {
285
289
let ll = make_lookuper ( & votes, & ids, & idsj) ;
@@ -297,12 +301,12 @@ fn test_quorum(data: &TestData) -> String {
297
301
let ar = JointConfig :: new_joint_from_majorities ( cj, c)
298
302
. vote_result ( |id| l. get ( & id) . cloned ( ) ) ;
299
303
if ar != r {
300
- buf . push_str ( & format ! ( "{} <-- via symmetry\n " , ar) ) ;
304
+ writeln ! ( buf , "{} <-- via symmetry" , ar) . unwrap ( ) ;
301
305
}
302
306
} else {
303
307
r = c. vote_result ( |id| l. get ( & id) . cloned ( ) ) ;
304
308
}
305
- buf . push_str ( & format ! ( "{}\n " , r) ) ;
309
+ writeln ! ( buf , "{}" , r) . unwrap ( ) ;
306
310
}
307
311
_ => {
308
312
panic ! ( "unknown command: {}" , data. cmd) ;
0 commit comments