Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: sql/connection_unittest.cc

Issue 18641004: [sql] Retry Open() if error handler fixed things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pointless tweaking, rebase. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sql/connection.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/connection_unittest.cc
diff --git a/sql/connection_unittest.cc b/sql/connection_unittest.cc
index fc430ac6294d9a80a1b2f479e5fb32f9c0dd1b2b..8cf32fb3f867f99c4e73e960decfe5822ff34240 100644
--- a/sql/connection_unittest.cc
+++ b/sql/connection_unittest.cc
@@ -491,7 +491,8 @@ TEST_F(SQLConnectionTest, RazeNOTADB2) {
// Test that a callback from Open() can raze the database. This is
// essential for cases where the Open() can fail entirely, so the
-// Raze() cannot happen later.
+// Raze() cannot happen later. Additionally test that when the
+// callback does this during Open(), the open is retried and succeeds.
//
// Most corruptions seen in the wild seem to happen when two pages in
// the database were not written transactionally (the transaction
@@ -499,7 +500,7 @@ TEST_F(SQLConnectionTest, RazeNOTADB2) {
// A special case of that is when the header indicates that the
// database contains more pages than are in the file. This breaks
// things at a very basic level, verify that Raze() can handle it.
-TEST_F(SQLConnectionTest, RazeOpenCallback) {
+TEST_F(SQLConnectionTest, RazeCallbackReopen) {
const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)";
ASSERT_TRUE(db().Execute(kCreateSql));
ASSERT_EQ(1, SqliteMasterCount(&db()));
@@ -519,19 +520,27 @@ TEST_F(SQLConnectionTest, RazeOpenCallback) {
ASSERT_TRUE(file_util::TruncateFile(file.get()));
}
+ // Open() will succeed, even though the PRAGMA calls within will
+ // fail with SQLITE_CORRUPT, as will this PRAGMA.
+ {
+ sql::ScopedErrorIgnorer ignore_errors;
+ ignore_errors.IgnoreError(SQLITE_CORRUPT);
+ ASSERT_TRUE(db().Open(db_path()));
+ ASSERT_FALSE(db().Execute("PRAGMA auto_vacuum"));
+ db().Close();
+ ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ }
+
db().set_error_callback(base::Bind(&SQLConnectionTest::RazeErrorCallback,
base::Unretained(this),
SQLITE_CORRUPT));
- // Open() will see SQLITE_CORRUPT due to size mismatch when
- // attempting to run a pragma, and the callback will RazeAndClose().
- // Later statements will fail, including the final secure_delete,
- // which will fail the Open() itself.
- ASSERT_FALSE(db().Open(db_path()));
- db().Close();
-
- // Now empty, the open should succeed with an empty database.
- EXPECT_TRUE(db().Open(db_path()));
+ // When the PRAGMA calls in Open() raise SQLITE_CORRUPT, the error
+ // callback will call RazeAndClose(). Open() will then fail and be
+ // retried. The second Open() on the empty database will succeed
+ // cleanly.
+ ASSERT_TRUE(db().Open(db_path()));
+ ASSERT_TRUE(db().Execute("PRAGMA auto_vacuum"));
EXPECT_EQ(0, SqliteMasterCount(&db()));
}
« no previous file with comments | « sql/connection.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698