aboutsummaryrefslogtreecommitdiff
path: root/src/leveldb/db/log_test.cc
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-05-09 18:23:34 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-05-12 11:30:33 +0200
commit26ceac4acf070ab589d25d05cd5e90e8fd721a69 (patch)
tree6f0dd31ef9faef74a5a9f1b286f5831e1ae8efcb /src/leveldb/db/log_test.cc
parenta39d4e3771dca644e891876db80e7821a2563a0f (diff)
downloadbitcoin-26ceac4acf070ab589d25d05cd5e90e8fd721a69.tar.xz
Squashed 'src/leveldb/' changes from 9094c7f..7924331
42dcc7e Merge upstream LevelDB 1.17. e353fbc Release LevelDB 1.17 269fc6c Release LevelDB 1.16 REVERT: 9094c7f Temporarily revert to writing .sst files instead of .ldb git-subtree-dir: src/leveldb git-subtree-split: 79243314e40ac31d79c68e5658a1d6a64800d50b Rebased-By: Wladimir J. van der Laan <laanwj@gmail.com> Rebased-From: 938b689
Diffstat (limited to 'src/leveldb/db/log_test.cc')
-rw-r--r--src/leveldb/db/log_test.cc40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/leveldb/db/log_test.cc b/src/leveldb/db/log_test.cc
index 4c5cf87573..91d3caafc3 100644
--- a/src/leveldb/db/log_test.cc
+++ b/src/leveldb/db/log_test.cc
@@ -351,20 +351,32 @@ TEST(LogTest, BadRecordType) {
ASSERT_EQ("OK", MatchError("unknown record type"));
}
-TEST(LogTest, TruncatedTrailingRecord) {
+TEST(LogTest, TruncatedTrailingRecordIsIgnored) {
Write("foo");
ShrinkSize(4); // Drop all payload as well as a header byte
ASSERT_EQ("EOF", Read());
- ASSERT_EQ(kHeaderSize - 1, DroppedBytes());
- ASSERT_EQ("OK", MatchError("truncated record at end of file"));
+ // Truncated last record is ignored, not treated as an error.
+ ASSERT_EQ(0, DroppedBytes());
+ ASSERT_EQ("", ReportMessage());
}
TEST(LogTest, BadLength) {
+ const int kPayloadSize = kBlockSize - kHeaderSize;
+ Write(BigString("bar", kPayloadSize));
+ Write("foo");
+ // Least significant size byte is stored in header[4].
+ IncrementByte(4, 1);
+ ASSERT_EQ("foo", Read());
+ ASSERT_EQ(kBlockSize, DroppedBytes());
+ ASSERT_EQ("OK", MatchError("bad record length"));
+}
+
+TEST(LogTest, BadLengthAtEndIsIgnored) {
Write("foo");
ShrinkSize(1);
ASSERT_EQ("EOF", Read());
- ASSERT_EQ(kHeaderSize + 2, DroppedBytes());
- ASSERT_EQ("OK", MatchError("bad record length"));
+ ASSERT_EQ(0, DroppedBytes());
+ ASSERT_EQ("", ReportMessage());
}
TEST(LogTest, ChecksumMismatch) {
@@ -415,6 +427,24 @@ TEST(LogTest, UnexpectedFirstType) {
ASSERT_EQ("OK", MatchError("partial record without end"));
}
+TEST(LogTest, MissingLastIsIgnored) {
+ Write(BigString("bar", kBlockSize));
+ // Remove the LAST block, including header.
+ ShrinkSize(14);
+ ASSERT_EQ("EOF", Read());
+ ASSERT_EQ("", ReportMessage());
+ ASSERT_EQ(0, DroppedBytes());
+}
+
+TEST(LogTest, PartialLastIsIgnored) {
+ Write(BigString("bar", kBlockSize));
+ // Cause a bad record length in the LAST block.
+ ShrinkSize(1);
+ ASSERT_EQ("EOF", Read());
+ ASSERT_EQ("", ReportMessage());
+ ASSERT_EQ(0, DroppedBytes());
+}
+
TEST(LogTest, ErrorJoinsRecords) {
// Consider two fragmented records:
// first(R1) last(R1) first(R2) last(R2)