Chromium Code Reviews| Index: sql/connection_unittest.cc |
| diff --git a/sql/connection_unittest.cc b/sql/connection_unittest.cc |
| index 6ac4f8bc12d3d2739c865abf5edb59fb0167c0c0..fb3a386d7eb47839ac0b7c44a45730f54a207dd9 100644 |
| --- a/sql/connection_unittest.cc |
| +++ b/sql/connection_unittest.cc |
| @@ -6,6 +6,7 @@ |
| #include <stdint.h> |
| #include "base/bind.h" |
| +#include "base/feature_list.h" |
| #include "base/files/file_util.h" |
| #include "base/files/scoped_file.h" |
| #include "base/files/scoped_temp_dir.h" |
| @@ -13,6 +14,7 @@ |
| #include "base/macros.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/test/histogram_tester.h" |
| +#include "base/test/scoped_feature_list.h" |
| #include "base/trace_event/process_memory_dump.h" |
| #include "sql/connection.h" |
| #include "sql/connection_memory_dump_provider.h" |
| @@ -1632,4 +1634,64 @@ TEST_F(SQLConnectionTest, CompileError) { |
| #endif |
| } |
| +#if !defined(USE_SYSTEM_SQLITE) |
| +// Test that smart-autovacuum is enabled appropriately. |
| +// http://crbug.com/698010 |
| +TEST_F(SQLConnectionTest, SmartAutoVacuumChunks) { |
| + // Explicitly turn on auto_vacuum so that this works the same on all |
| + // platforms, and set the page size low to make results obvious. These |
| + // settings require re-writing the database, which VACUUM does. |
| + ASSERT_TRUE(db().Execute("PRAGMA auto_vacuum = FULL")); |
| + ASSERT_TRUE(db().Execute("PRAGMA page_size = 1024")); |
| + ASSERT_TRUE(db().Execute("VACUUM")); |
| + |
| + // With page_size=1024, the following will insert rows which take up an |
| + // overflow page, plus a small header in a b-tree node. An empty table takes |
| + // a single page, so for small row counts each insert will add one page. |
| + const char kCreateSql[] = "CREATE TABLE t (id INTEGER PRIMARY KEY, value)"; |
| + const char kInsertSql[] = "INSERT INTO t (value) VALUES (randomblob(980))"; |
| + |
| + // This database will be 34 overflow pages plus the table's root page plus the |
| + // SQLite header page plus the freelist page. |
| + ASSERT_TRUE(db().Execute(kCreateSql)); |
| + { |
| + sql::Statement s(db().GetUniqueStatement(kInsertSql)); |
| + for (int i = 0; i < 34; ++i) { |
| + s.Reset(true); |
| + ASSERT_TRUE(s.Run()); |
| + } |
| + } |
| + ASSERT_EQ("37", sql::test::ExecuteWithResult(&db(), "PRAGMA page_count")); |
| + |
| + // Matches connection.cc. |
| + // TODO(shess): Should this be shared? |
| + const base::Feature kFeature{"SqliteSmartAutoVacuum", |
| + base::FEATURE_DISABLED_BY_DEFAULT}; |
|
Maria
2017/03/28 22:14:59
This line in test should not do anything -- e.g. i
Scott Hess - ex-Googler
2017/03/29 03:28:46
This line doesn't do anything, but it's used in th
Maria
2017/03/29 04:23:50
Um, sorry about this comment. I somehow completely
|
| + |
| + const char kPragma[] = "PRAGMA auto_vacuum_slack_pages"; |
| + |
| + // Give Open() a chance to set the pragma with the feature disabled. |
| + { |
| + base::test::ScopedFeatureList fl; |
| + fl.InitAndDisableFeature(kFeature); |
| + db().Close(); |
| + db().set_page_size(1024); |
| + ASSERT_TRUE(db().Open(db_path())); |
| + |
| + ASSERT_EQ("0", sql::test::ExecuteWithResult(&db(), kPragma)); |
| + } |
| + |
| + // Give Open() a chance to set the pragma with the feature enabled. |
| + { |
| + base::test::ScopedFeatureList fl; |
| + fl.InitAndEnableFeature(kFeature); |
| + db().Close(); |
| + db().set_page_size(1024); |
| + ASSERT_TRUE(db().Open(db_path())); |
| + |
| + ASSERT_EQ("4", sql::test::ExecuteWithResult(&db(), kPragma)); |
| + } |
| +} |
| +#endif // !defined(USE_SYSTEM_SQLITE) |
| + |
| } // namespace sql |