Merge #11422: qa: Verify DBWrapper iterators are taking snapshots

bb8376b Verify DBWrapper iterators are taking snapshots (Matt Corallo)

Pull request description:

  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.

Tree-SHA512: 54f24dabc294962e9c20882f61809604421a661208d1568bb107102248603e8e7c12e929ccb0812a73d4e4f23fea61f1b48e7cc24da5a7260f1d14d89ba88cd6
This commit is contained in:
Wladimir J. van der Laan 2017-10-02 14:39:59 +02:00
commit c641ccac5b
No known key found for this signature in database
GPG key ID: 1E4AED62986CD25D

View file

@ -204,19 +204,31 @@ BOOST_AUTO_TEST_CASE(iterator_ordering)
for (int x=0x00; x<256; ++x) {
uint8_t key = x;
uint32_t value = x*x;
BOOST_CHECK(dbw.Write(key, value));
if (!(x & 1)) BOOST_CHECK(dbw.Write(key, value));
}
// Check that creating an iterator creates a snapshot
std::unique_ptr<CDBIterator> it(const_cast<CDBWrapper&>(dbw).NewIterator());
for (int x=0x00; x<256; ++x) {
uint8_t key = x;
uint32_t value = x*x;
if (x & 1) BOOST_CHECK(dbw.Write(key, value));
}
for (int seek_start : {0x00, 0x80}) {
it->Seek((uint8_t)seek_start);
for (int x=seek_start; x<256; ++x) {
for (int x=seek_start; x<255; ++x) {
uint8_t key;
uint32_t value;
BOOST_CHECK(it->Valid());
if (!it->Valid()) // Avoid spurious errors about invalid iterator's key and value in case of failure
break;
BOOST_CHECK(it->GetKey(key));
if (x & 1) {
BOOST_CHECK_EQUAL(key, x + 1);
continue;
}
BOOST_CHECK(it->GetValue(value));
BOOST_CHECK_EQUAL(key, x);
BOOST_CHECK_EQUAL(value, x*x);