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

Unified Diff: sql/recovery_unittest.cc

Issue 2274883003: [sql] Track SQLite error codes from sql::Recovery ATTACH. (Closed)
Patch Set: Created 4 years, 4 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/recovery.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/recovery_unittest.cc
diff --git a/sql/recovery_unittest.cc b/sql/recovery_unittest.cc
index e946bdee023b0fabd8d5505d3055872c9b6b9477..d9f589042b2e0c4e3155b466fa397f02639f4231 100644
--- a/sql/recovery_unittest.cc
+++ b/sql/recovery_unittest.cc
@@ -16,6 +16,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
+#include "base/test/histogram_tester.h"
#include "sql/connection.h"
#include "sql/meta_table.h"
#include "sql/statement.h"
@@ -832,4 +833,38 @@ TEST_F(SQLRecoveryTest, RecoverDatabase) {
EXPECT_EQ("trailer", ExecuteWithResults(&db(), kVSql, "|", "\n"));
}
+// Test histograms recorded when the invalid database cannot be attached.
+TEST_F(SQLRecoveryTest, AttachFailure) {
+ // Create a valid database, then write junk over the header. This should lead
+ // to SQLITE_NOTADB, which will cause ATTACH to fail.
+ ASSERT_TRUE(db().Execute("CREATE TABLE x (t TEXT)"));
+ ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('This is a test')"));
+ db().Close();
+ WriteJunkToDatabase(SQLTestBase::TYPE_OVERWRITE);
+
+ const char kEventHistogramName[] = "Sqlite.RecoveryEvents";
+ const int kEventEnum = 5; // RECOVERY_FAILED_ATTACH
+ const char kErrorHistogramName[] = "Sqlite.RecoveryAttachError";
+ base::HistogramTester tester;
+
+ {
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_NOTADB);
+
+ // Reopen() here because it will see SQLITE_NOTADB.
+ ASSERT_TRUE(Reopen());
+
+ // Begin() should fail.
+ std::unique_ptr<sql::Recovery>
+ recovery = sql::Recovery::Begin(&db(), db_path());
+ ASSERT_FALSE(recovery.get());
+
+ ASSERT_TRUE(expecter.SawExpectedErrors());
+ }
+
+ // Verify that the failure was in the right place with the expected code.
+ tester.ExpectBucketCount(kEventHistogramName, kEventEnum, 1);
+ tester.ExpectBucketCount(kErrorHistogramName, SQLITE_NOTADB, 1);
+}
+
} // namespace
« no previous file with comments | « sql/recovery.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698