Bug 706420 - intermittent failure in test_annos_expire_session.js

r=dietrich
This commit is contained in:
Marco Bonardo 2012-02-17 14:24:54 +01:00
parent 4cf0c2397d
commit b60bc7d88e
4 changed files with 54 additions and 68 deletions

View File

@ -2037,31 +2037,17 @@ nsAnnotationService::Observe(nsISupports *aSubject,
"DELETE FROM moz_annos WHERE expiration = :expire_session"
);
NS_ENSURE_STATE(pageAnnoStmt);
nsresult rv = pageAnnoStmt->BindInt32ByName(NS_LITERAL_CSTRING("expire_session"),
EXPIRE_SESSION);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<mozIStorageAsyncStatement> itemAnnoStmt = mDB->GetAsyncStatement(
"DELETE FROM moz_items_annos WHERE expiration = :expire_session"
);
NS_ENSURE_STATE(itemAnnoStmt);
# define ASYNC_BIND(_stmt) \
PR_BEGIN_MACRO \
nsCOMPtr<mozIStorageBindingParamsArray> paramsArray; \
nsresult rv = _stmt->NewBindingParamsArray(getter_AddRefs(paramsArray)); \
NS_ENSURE_SUCCESS(rv, rv); \
nsCOMPtr<mozIStorageBindingParams> params; \
rv = paramsArray->NewBindingParams(getter_AddRefs(params)); \
NS_ENSURE_SUCCESS(rv, rv); \
rv = params->BindInt32ByName(NS_LITERAL_CSTRING("expire_session"), EXPIRE_SESSION); \
NS_ENSURE_SUCCESS(rv, rv); \
rv = paramsArray->AddParams(params); \
NS_ENSURE_SUCCESS(rv, rv); \
rv = _stmt->BindParameters(paramsArray); \
NS_ENSURE_SUCCESS(rv, rv); \
PR_END_MACRO
ASYNC_BIND(pageAnnoStmt);
ASYNC_BIND(itemAnnoStmt);
# undef ASYNC_BIND
rv = itemAnnoStmt->BindInt32ByName(NS_LITERAL_CSTRING("expire_session"),
EXPIRE_SESSION);
NS_ENSURE_SUCCESS(rv, rv);
mozIStorageBaseStatement *stmts[] = {
pageAnnoStmt.get()
@ -2069,8 +2055,8 @@ nsAnnotationService::Observe(nsISupports *aSubject,
};
nsCOMPtr<mozIStoragePendingStatement> ps;
nsresult rv = mDB->MainConn()->ExecuteAsync(stmts, ArrayLength(stmts),
nsnull, getter_AddRefs(ps));
rv = mDB->MainConn()->ExecuteAsync(stmts, ArrayLength(stmts), nsnull,
getter_AddRefs(ps));
NS_ENSURE_SUCCESS(rv, rv);
}
}

View File

@ -5328,31 +5328,18 @@ nsNavHistory::UpdateFrecency(PRInt64 aPlaceId)
"WHERE id = :page_id"
);
NS_ENSURE_STATE(updateFrecencyStmt);
nsresult rv = updateFrecencyStmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"),
aPlaceId);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<mozIStorageAsyncStatement> updateHiddenStmt = mDB->GetAsyncStatement(
"UPDATE moz_places "
"SET hidden = 0 "
"WHERE id = :page_id AND frecency <> 0"
);
NS_ENSURE_STATE(updateHiddenStmt);
#define ASYNC_BIND(_stmt) \
PR_BEGIN_MACRO \
nsCOMPtr<mozIStorageBindingParamsArray> paramsArray; \
nsresult rv = _stmt->NewBindingParamsArray(getter_AddRefs(paramsArray)); \
NS_ENSURE_SUCCESS(rv, rv); \
nsCOMPtr<mozIStorageBindingParams> params; \
rv = paramsArray->NewBindingParams(getter_AddRefs(params)); \
NS_ENSURE_SUCCESS(rv, rv); \
rv = params->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPlaceId); \
NS_ENSURE_SUCCESS(rv, rv); \
rv = paramsArray->AddParams(params); \
NS_ENSURE_SUCCESS(rv, rv); \
rv = _stmt->BindParameters(paramsArray); \
NS_ENSURE_SUCCESS(rv, rv); \
PR_END_MACRO
ASYNC_BIND(updateFrecencyStmt);
ASYNC_BIND(updateHiddenStmt);
rv = updateHiddenStmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"),
aPlaceId);
NS_ENSURE_SUCCESS(rv, rv);
mozIStorageBaseStatement *stmts[] = {
updateFrecencyStmt.get()
@ -5362,12 +5349,11 @@ nsNavHistory::UpdateFrecency(PRInt64 aPlaceId)
nsRefPtr<AsyncStatementCallbackNotifier> cb =
new AsyncStatementCallbackNotifier(TOPIC_FRECENCY_UPDATED);
nsCOMPtr<mozIStoragePendingStatement> ps;
nsresult rv = mDB->MainConn()->ExecuteAsync(stmts, ArrayLength(stmts), cb,
getter_AddRefs(ps));
rv = mDB->MainConn()->ExecuteAsync(stmts, ArrayLength(stmts), cb,
getter_AddRefs(ps));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
#undef ASYNC_BIND
}

View File

@ -86,28 +86,27 @@ function run_test() {
items = as.getItemsWithAnnotation("test2");
do_check_eq(items.length, 10);
shutdownPlaces();
let stmt = DBConn(true).createAsyncStatement(
"SELECT id FROM moz_annos "
+ "UNION "
+ "SELECT id FROM moz_items_annos "
);
stmt.executeAsync({
handleResult: function(aResultSet)
{
do_throw("Should not find any leftover session annotations");
},
handleError: function(aError)
{
do_throw("Error code " + aError.result + " with message '" +
aError.message + "' returned.");
},
handleCompletion: function(aReason)
{
do_check_eq(aReason, Ci.mozIStorageStatementCallback.REASON_FINISHED);
do_test_finished();
}
waitForConnectionClosed(function() {
let stmt = DBConn(true).createAsyncStatement(
"SELECT id FROM moz_annos "
+ "UNION ALL "
+ "SELECT id FROM moz_items_annos "
);
stmt.executeAsync({
handleResult: function(aResultSet) {
dump_table("moz_annos");
dump_table("moz_items_annos");
do_throw("Should not find any leftover session annotations");
},
handleError: function(aError) {
do_throw("Error code " + aError.result + " with message '" +
aError.message + "' returned.");
},
handleCompletion: function(aReason) {
do_check_eq(aReason, Ci.mozIStorageStatementCallback.REASON_FINISHED);
do_test_finished();
}
});
stmt.finalize();
});
stmt.finalize();
}

View File

@ -644,6 +644,21 @@ function waitForAsyncUpdates(aCallback, aScope, aArguments)
commit.finalize();
}
/**
* Shutdowns Places, invoking the callback when the connection has been closed.
*
* @param aCallback
* Function to be called when done.
*/
function waitForConnectionClosed(aCallback)
{
Services.obs.addObserver(function WFCCCallback() {
Services.obs.removeObserver(WFCCCallback, "places-connection-closed");
aCallback();
}, "places-connection-closed", false);
shutdownPlaces();
}
/**
* Tests if a given guid is valid for use in Places or not.
*