@@ -351,20 +351,32 @@ TEST(LogTest, BadRecordType) {
351
351
ASSERT_EQ (" OK" , MatchError (" unknown record type" ));
352
352
}
353
353
354
- TEST (LogTest, TruncatedTrailingRecord ) {
354
+ TEST (LogTest, TruncatedTrailingRecordIsIgnored ) {
355
355
Write (" foo" );
356
356
ShrinkSize (4 ); // Drop all payload as well as a header byte
357
357
ASSERT_EQ (" EOF" , Read ());
358
- ASSERT_EQ (kHeaderSize - 1 , DroppedBytes ());
359
- ASSERT_EQ (" OK" , MatchError (" truncated record at end of file" ));
358
+ // Truncated last record is ignored, not treated as an error.
359
+ ASSERT_EQ (0 , DroppedBytes ());
360
+ ASSERT_EQ (" " , ReportMessage ());
360
361
}
361
362
362
363
TEST (LogTest, BadLength) {
364
+ const int kPayloadSize = kBlockSize - kHeaderSize ;
365
+ Write (BigString (" bar" , kPayloadSize ));
366
+ Write (" foo" );
367
+ // Least significant size byte is stored in header[4].
368
+ IncrementByte (4 , 1 );
369
+ ASSERT_EQ (" foo" , Read ());
370
+ ASSERT_EQ (kBlockSize , DroppedBytes ());
371
+ ASSERT_EQ (" OK" , MatchError (" bad record length" ));
372
+ }
373
+
374
+ TEST (LogTest, BadLengthAtEndIsIgnored) {
363
375
Write (" foo" );
364
376
ShrinkSize (1 );
365
377
ASSERT_EQ (" EOF" , Read ());
366
- ASSERT_EQ (kHeaderSize + 2 , DroppedBytes ());
367
- ASSERT_EQ (" OK " , MatchError ( " bad record length " ));
378
+ ASSERT_EQ (0 , DroppedBytes ());
379
+ ASSERT_EQ (" " , ReportMessage ( ));
368
380
}
369
381
370
382
TEST (LogTest, ChecksumMismatch) {
@@ -415,6 +427,24 @@ TEST(LogTest, UnexpectedFirstType) {
415
427
ASSERT_EQ (" OK" , MatchError (" partial record without end" ));
416
428
}
417
429
430
+ TEST (LogTest, MissingLastIsIgnored) {
431
+ Write (BigString (" bar" , kBlockSize ));
432
+ // Remove the LAST block, including header.
433
+ ShrinkSize (14 );
434
+ ASSERT_EQ (" EOF" , Read ());
435
+ ASSERT_EQ (" " , ReportMessage ());
436
+ ASSERT_EQ (0 , DroppedBytes ());
437
+ }
438
+
439
+ TEST (LogTest, PartialLastIsIgnored) {
440
+ Write (BigString (" bar" , kBlockSize ));
441
+ // Cause a bad record length in the LAST block.
442
+ ShrinkSize (1 );
443
+ ASSERT_EQ (" EOF" , Read ());
444
+ ASSERT_EQ (" " , ReportMessage ());
445
+ ASSERT_EQ (0 , DroppedBytes ());
446
+ }
447
+
418
448
TEST (LogTest, ErrorJoinsRecords) {
419
449
// Consider two fragmented records:
420
450
// first(R1) last(R1) first(R2) last(R2)
0 commit comments