Skip to content

Commit bb8376b

Browse files
committed
Verify DBWrapper iterators are taking snapshots
The LevelDB docs seem to indicate that an iterator will not take snapshots (even providing instructions on how to do so yourself). In several of the places we use them, we assume snapshots to have been taken. In order to make sure LevelDB doesn't change out from under us (and to prevent the next person who reads the docs from having the same fright I did), verify that snapshots are taken in our tests.
1 parent ff4cd60 commit bb8376b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/test/dbwrapper_tests.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,31 @@ BOOST_AUTO_TEST_CASE(iterator_ordering)
204204
for (int x=0x00; x<256; ++x) {
205205
uint8_t key = x;
206206
uint32_t value = x*x;
207-
BOOST_CHECK(dbw.Write(key, value));
207+
if (!(x & 1)) BOOST_CHECK(dbw.Write(key, value));
208208
}
209209

210+
// Check that creating an iterator creates a snapshot
210211
std::unique_ptr<CDBIterator> it(const_cast<CDBWrapper&>(dbw).NewIterator());
212+
213+
for (int x=0x00; x<256; ++x) {
214+
uint8_t key = x;
215+
uint32_t value = x*x;
216+
if (x & 1) BOOST_CHECK(dbw.Write(key, value));
217+
}
218+
211219
for (int seek_start : {0x00, 0x80}) {
212220
it->Seek((uint8_t)seek_start);
213-
for (int x=seek_start; x<256; ++x) {
221+
for (int x=seek_start; x<255; ++x) {
214222
uint8_t key;
215223
uint32_t value;
216224
BOOST_CHECK(it->Valid());
217225
if (!it->Valid()) // Avoid spurious errors about invalid iterator's key and value in case of failure
218226
break;
219227
BOOST_CHECK(it->GetKey(key));
228+
if (x & 1) {
229+
BOOST_CHECK_EQUAL(key, x + 1);
230+
continue;
231+
}
220232
BOOST_CHECK(it->GetValue(value));
221233
BOOST_CHECK_EQUAL(key, x);
222234
BOOST_CHECK_EQUAL(value, x*x);

0 commit comments

Comments
 (0)