fix tests for Bug 512854 - VACUUM places.sqlite database on daily idle once a month, r=sdwilsh

This commit is contained in:
Marco Bonardo 2009-09-29 12:44:12 +02:00
parent a7c0ff4d43
commit 98646fc82d
4 changed files with 66 additions and 163 deletions

View File

@ -37,23 +37,14 @@
*
* ***** END LICENSE BLOCK ***** */
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
let bh = hs.QueryInterface(Ci.nsIBrowserHistory);
let dbConn = hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
getBranch("places.");
const LAST_VACUUM_PREF = "last_vacuum";
const VACUUM_THRESHOLD = 0.1;
const PLACES_VACUUM_STARTING_TOPIC = "places-vacuum-starting";
function getDBVacuumRatio() {
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
let dbConn = hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
let freelistStmt = dbConn.createStatement("PRAGMA freelist_count");
freelistStmt.executeStep();
let freelistCount = freelistStmt.row.freelist_count;
@ -67,31 +58,7 @@ function getDBVacuumRatio() {
return ratio;
}
function generateSparseDB(aType) {
let limit = 0;
if (aType == "low")
limit = 10;
else if (aType == "high")
limit = 200;
let batch = {
runBatched: function batch_runBatched() {
for (let i = 0; i < limit; i++) {
hs.addVisit(uri("http://" + i + ".mozilla.com/"),
Date.now() * 1000 + i, null, hs.TRANSITION_TYPED, false, 0);
}
for (let i = 0; i < limit; i++) {
bs.insertBookmark(bs.unfiledBookmarksFolder,
uri("http://" + i + "." + i + ".mozilla.com/"),
bs.DEFAULT_INDEX, "bookmark " + i);
}
}
}
hs.runInBatchMode(batch, null);
bh.removeAllPages();
bs.removeFolderChildren(bs.unfiledBookmarksFolder);
}
/* Only low ratio tests. Stop at first vacuum. */
var gTests = [
{
desc: "Low ratio, last vacuum today",
@ -113,28 +80,24 @@ var gTests = [
elapsedDays: 61,
vacuum: true
},
{
desc: "High ratio, last vacuum today",
ratio: "high",
elapsedDays: 0,
vacuum: false
},
];
var observer = {
vacuum: false,
observe: function(aSubject, aTopic, aData) {
if (aTopic == PLACES_VACUUM_STARTING_TOPIC) {
this.vacuum = true;
function run_test() {
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let observer = {
vacuum: false,
observe: function(aSubject, aTopic, aData) {
if (aTopic == PLACES_VACUUM_STARTING_TOPIC) {
this.vacuum = true;
}
}
}
}
os.addObserver(observer, PLACES_VACUUM_STARTING_TOPIC, false);
os.addObserver(observer, PLACES_VACUUM_STARTING_TOPIC, false);
function run_test() {
// This test is disabled for now, generateSparseDB is randomly failing.
return;
let prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
getBranch("places.");
while (gTests.length) {
observer.vacuum = false;
@ -142,13 +105,9 @@ function run_test() {
print("PLACES TEST: " + test.desc);
let ratio = getDBVacuumRatio();
if (test.ratio == "high") {
if (ratio < VACUUM_THRESHOLD)
generateSparseDB("high");
do_check_true(getDBVacuumRatio() > VACUUM_THRESHOLD);
do_throw("This test only supports low ratio cases");
}
else if (test.ratio == "low") {
if (ratio == 0)
generateSparseDB("low");
do_check_true(getDBVacuumRatio() < VACUUM_THRESHOLD);
}
print("current ratio is " + getDBVacuumRatio());

View File

@ -37,23 +37,14 @@
*
* ***** END LICENSE BLOCK ***** */
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
let bh = hs.QueryInterface(Ci.nsIBrowserHistory);
let dbConn = hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
getBranch("places.");
const LAST_VACUUM_PREF = "last_vacuum";
const VACUUM_THRESHOLD = 0.1;
const PLACES_VACUUM_STARTING_TOPIC = "places-vacuum-starting";
function getDBVacuumRatio() {
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
let dbConn = hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
let freelistStmt = dbConn.createStatement("PRAGMA freelist_count");
freelistStmt.executeStep();
let freelistCount = freelistStmt.row.freelist_count;
@ -67,32 +58,14 @@ function getDBVacuumRatio() {
return ratio;
}
function generateSparseDB(aType) {
let limit = 0;
if (aType == "low")
limit = 10;
else if (aType == "high")
limit = 200;
let batch = {
runBatched: function batch_runBatched() {
for (let i = 0; i < limit; i++) {
hs.addVisit(uri("http://" + i + ".mozilla.com/"),
Date.now() * 1000 + i, null, hs.TRANSITION_TYPED, false, 0);
}
for (let i = 0; i < limit; i++) {
bs.insertBookmark(bs.unfiledBookmarksFolder,
uri("http://" + i + "." + i + ".mozilla.com/"),
bs.DEFAULT_INDEX, "bookmark " + i);
}
}
}
hs.runInBatchMode(batch, null);
bh.removeAllPages();
bs.removeFolderChildren(bs.unfiledBookmarksFolder);
}
/* Only high ratio tests. Stop at first vacuum. */
var gTests = [
{
desc: "High ratio, last vacuum today",
ratio: "high",
elapsedDays: 0,
vacuum: false
},
{
desc: "High ratio, last vacuum two months ago",
ratio: "high",
@ -101,19 +74,25 @@ var gTests = [
},
];
var observer = {
vacuum: false,
observe: function(aSubject, aTopic, aData) {
if (aTopic == PLACES_VACUUM_STARTING_TOPIC) {
this.vacuum = true;
function run_test() {
let sparseDB = do_get_file("places.sparse.sqlite");
sparseDB.copyTo(do_get_profile(), "places.sqlite");
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let observer = {
vacuum: false,
observe: function(aSubject, aTopic, aData) {
if (aTopic == PLACES_VACUUM_STARTING_TOPIC) {
this.vacuum = true;
}
}
}
}
os.addObserver(observer, PLACES_VACUUM_STARTING_TOPIC, false);
os.addObserver(observer, PLACES_VACUUM_STARTING_TOPIC, false);
function run_test() {
// This test is disabled for now, generateSparseDB is randomly failing.
return;
let prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
getBranch("places.");
while (gTests.length) {
observer.vacuum = false;
@ -121,14 +100,10 @@ function run_test() {
print("PLACES TEST: " + test.desc);
let ratio = getDBVacuumRatio();
if (test.ratio == "high") {
if (ratio < VACUUM_THRESHOLD)
generateSparseDB("high");
do_check_true(getDBVacuumRatio() > VACUUM_THRESHOLD);
}
else if (test.ratio == "low") {
if (ratio == 0)
generateSparseDB("low");
do_check_true(getDBVacuumRatio() < VACUUM_THRESHOLD);
do_throw("This test only supports high ratio cases");
}
print("current ratio is " + getDBVacuumRatio());
prefs.setIntPref(LAST_VACUUM_PREF, ((Date.now() / 1000) - (test.elapsedDays * 24 * 60 * 60)));

View File

@ -37,23 +37,14 @@
*
* ***** END LICENSE BLOCK ***** */
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
let bh = hs.QueryInterface(Ci.nsIBrowserHistory);
let dbConn = hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
getBranch("places.");
const LAST_VACUUM_PREF = "last_vacuum";
const VACUUM_THRESHOLD = 0.1;
const PLACES_VACUUM_STARTING_TOPIC = "places-vacuum-starting";
function getDBVacuumRatio() {
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
let dbConn = hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
let freelistStmt = dbConn.createStatement("PRAGMA freelist_count");
freelistStmt.executeStep();
let freelistCount = freelistStmt.row.freelist_count;
@ -67,31 +58,7 @@ function getDBVacuumRatio() {
return ratio;
}
function generateSparseDB(aType) {
let limit = 0;
if (aType == "low")
limit = 10;
else if (aType == "high")
limit = 200;
let batch = {
runBatched: function batch_runBatched() {
for (let i = 0; i < limit; i++) {
hs.addVisit(uri("http://" + i + ".mozilla.com/"),
Date.now() * 1000 + i, null, hs.TRANSITION_TYPED, false, 0);
}
for (let i = 0; i < limit; i++) {
bs.insertBookmark(bs.unfiledBookmarksFolder,
uri("http://" + i + "." + i + ".mozilla.com/"),
bs.DEFAULT_INDEX, "bookmark " + i);
}
}
}
hs.runInBatchMode(batch, null);
bh.removeAllPages();
bs.removeFolderChildren(bs.unfiledBookmarksFolder);
}
/* Only high ratio tests. Stop at first vacuum. */
var gTests = [
{
desc: "High ratio, last vacuum two months ago",
@ -101,19 +68,25 @@ var gTests = [
},
];
var observer = {
vacuum: false,
observe: function(aSubject, aTopic, aData) {
if (aTopic == PLACES_VACUUM_STARTING_TOPIC) {
this.vacuum = true;
function run_test() {
let sparseDB = do_get_file("places.sparse.sqlite");
sparseDB.copyTo(do_get_profile(), "places.sqlite");
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let observer = {
vacuum: false,
observe: function(aSubject, aTopic, aData) {
if (aTopic == PLACES_VACUUM_STARTING_TOPIC) {
this.vacuum = true;
}
}
}
}
os.addObserver(observer, PLACES_VACUUM_STARTING_TOPIC, false);
os.addObserver(observer, PLACES_VACUUM_STARTING_TOPIC, false);
function run_test() {
// This test is disabled for now, generateSparseDB is randomly failing.
return;
let prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
getBranch("places.");
while (gTests.length) {
observer.vacuum = false;
@ -121,14 +94,10 @@ function run_test() {
print("PLACES TEST: " + test.desc);
let ratio = getDBVacuumRatio();
if (test.ratio == "high") {
if (ratio < VACUUM_THRESHOLD)
generateSparseDB("high");
do_check_true(getDBVacuumRatio() > VACUUM_THRESHOLD);
}
else if (test.ratio == "low") {
if (ratio == 0)
generateSparseDB("low");
do_check_true(getDBVacuumRatio() < VACUUM_THRESHOLD);
do_throw("This test only supports high ratio cases");
}
print("current ratio is " + getDBVacuumRatio());
prefs.setIntPref(LAST_VACUUM_PREF, ((Date.now() / 1000) - (test.elapsedDays * 24 * 60 * 60)));