@@ -351,20 +351,32 @@ TEST(LogTest, BadRecordType) {
351351 ASSERT_EQ (" OK" , MatchError (" unknown record type" ));
352352}
353353
354- TEST (LogTest, TruncatedTrailingRecord ) {
354+ TEST (LogTest, TruncatedTrailingRecordIsIgnored ) {
355355 Write (" foo" );
356356 ShrinkSize (4 ); // Drop all payload as well as a header byte
357357 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 ());
360361}
361362
362363TEST (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) {
363375 Write (" foo" );
364376 ShrinkSize (1 );
365377 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 ( ));
368380}
369381
370382TEST (LogTest, ChecksumMismatch) {
@@ -415,6 +427,24 @@ TEST(LogTest, UnexpectedFirstType) {
415427 ASSERT_EQ (" OK" , MatchError (" partial record without end" ));
416428}
417429
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+
418448TEST (LogTest, ErrorJoinsRecords) {
419449 // Consider two fragmented records:
420450 // first(R1) last(R1) first(R2) last(R2)
0 commit comments