Bug 1246073 - Fix unique constraint errors in the H2 backend when resubscribing. r=dragana

MozReview-Commit-ID: DciQIx9T99U

--HG--
extra : rebase_source : 4d9c3a40626280bdada21e58c3112b70b3ac5b2d
This commit is contained in:
Kit Cambridge 2016-02-04 20:17:07 -08:00
Родитель ec4c382804
Коммит ff6fdbef17
4 изменённых файлов: 70 добавлений и 26 удалений

Просмотреть файл

@ -404,10 +404,20 @@ this.PushDB.prototype = {
aKeyID, newRecord); aKeyID, newRecord);
return; return;
} }
aStore.put(newRecord).onsuccess = aEvent => { function putRecord() {
console.debug("update: Update successful", aKeyID, newRecord); let req = aStore.put(newRecord);
aTxn.result = newRecord; req.onsuccess = aEvent => {
}; console.debug("update: Update successful", aKeyID, newRecord);
aTxn.result = newRecord;
};
}
if (aKeyID === newRecord.keyID) {
putRecord();
} else {
// If we changed the primary key, delete the old record to avoid
// unique constraint errors.
aStore.delete(aKeyID).onsuccess = putRecord;
}
}; };
}, },
resolve, resolve,

Просмотреть файл

@ -14,15 +14,18 @@ XPCOMUtils.defineLazyGetter(this, "serverPort", function() {
return httpServer.identity.primaryPort; return httpServer.identity.primaryPort;
}); });
var handlerDone;
var handlerPromise = new Promise(r => handlerDone = after(3, r));
function listen4xxCodeHandler(metadata, response) { function listen4xxCodeHandler(metadata, response) {
ok(true, "Listener point error") ok(true, "Listener point error")
do_test_finished(); handlerDone();
response.setStatusLine(metadata.httpVersion, 410, "GONE"); response.setStatusLine(metadata.httpVersion, 410, "GONE");
} }
function resubscribeHandler(metadata, response) { function resubscribeHandler(metadata, response) {
ok(true, "Ask for new subscription"); ok(true, "Ask for new subscription");
do_test_finished(); handlerDone();
response.setHeader("Location", response.setHeader("Location",
'http://localhost:' + serverPort + '/newSubscription') 'http://localhost:' + serverPort + '/newSubscription')
response.setHeader("Link", response.setHeader("Link",
@ -33,7 +36,7 @@ function resubscribeHandler(metadata, response) {
function listenSuccessHandler(metadata, response) { function listenSuccessHandler(metadata, response) {
do_check_true(true, "New listener point"); do_check_true(true, "New listener point");
httpServer.stop(do_test_finished); httpServer.stop(handlerDone);
response.setStatusLine(metadata.httpVersion, 204, "Try again"); response.setStatusLine(metadata.httpVersion, 204, "Try again");
} }
@ -61,10 +64,6 @@ add_task(function* test1() {
return db.drop().then(_ => db.close()); return db.drop().then(_ => db.close());
}); });
do_test_pending();
do_test_pending();
do_test_pending();
var serverURL = "http://localhost:" + httpServer.identity.primaryPort; var serverURL = "http://localhost:" + httpServer.identity.primaryPort;
let records = [{ let records = [{
@ -85,4 +84,17 @@ add_task(function* test1() {
db db
}); });
yield handlerPromise;
let record = yield db.getByIdentifiers({
scope: 'https://example.com/page',
originAttributes: '',
});
equal(record.keyID, serverURL + '/newSubscription',
'Should update subscription URL');
equal(record.pushEndpoint, serverURL + '/newPushEndpoint',
'Should update push endpoint');
equal(record.pushReceiptEndpoint, serverURL + '/newReceiptPushEndpoint',
'Should update push receipt endpoint');
}); });

Просмотреть файл

@ -14,11 +14,13 @@ XPCOMUtils.defineLazyGetter(this, "serverPort", function() {
return httpServer.identity.primaryPort; return httpServer.identity.primaryPort;
}); });
var retries = 0 var retries = 0;
var handlerDone;
var handlerPromise = new Promise(r => handlerDone = after(5, r));
function listen5xxCodeHandler(metadata, response) { function listen5xxCodeHandler(metadata, response) {
ok(true, "Listener 5xx code"); ok(true, "Listener 5xx code");
do_test_finished(); handlerDone();
retries++; retries++;
response.setHeader("Retry-After", '1'); response.setHeader("Retry-After", '1');
response.setStatusLine(metadata.httpVersion, 500, "Retry"); response.setStatusLine(metadata.httpVersion, 500, "Retry");
@ -27,7 +29,7 @@ function listen5xxCodeHandler(metadata, response) {
function resubscribeHandler(metadata, response) { function resubscribeHandler(metadata, response) {
ok(true, "Ask for new subscription"); ok(true, "Ask for new subscription");
ok(retries == 3, "Should retry 2 times."); ok(retries == 3, "Should retry 2 times.");
do_test_finished(); handlerDone();
response.setHeader("Location", response.setHeader("Location",
'http://localhost:' + serverPort + '/newSubscription') 'http://localhost:' + serverPort + '/newSubscription')
response.setHeader("Link", response.setHeader("Link",
@ -38,7 +40,7 @@ function resubscribeHandler(metadata, response) {
function listenSuccessHandler(metadata, response) { function listenSuccessHandler(metadata, response) {
do_check_true(true, "New listener point"); do_check_true(true, "New listener point");
httpServer.stop(do_test_finished); httpServer.stop(handlerDone);
response.setStatusLine(metadata.httpVersion, 204, "Try again"); response.setStatusLine(metadata.httpVersion, 204, "Try again");
} }
@ -67,12 +69,6 @@ add_task(function* test1() {
return db.drop().then(_ => db.close()); return db.drop().then(_ => db.close());
}); });
do_test_pending();
do_test_pending();
do_test_pending();
do_test_pending();
do_test_pending();
var serverURL = "http://localhost:" + httpServer.identity.primaryPort; var serverURL = "http://localhost:" + httpServer.identity.primaryPort;
let records = [{ let records = [{
@ -93,4 +89,17 @@ add_task(function* test1() {
db db
}); });
yield handlerPromise;
let record = yield db.getByIdentifiers({
scope: 'https://example.com/page',
originAttributes: '',
});
equal(record.keyID, serverURL + '/newSubscription',
'Should update subscription URL');
equal(record.pushEndpoint, serverURL + '/newPushEndpoint',
'Should update push endpoint');
equal(record.pushReceiptEndpoint, serverURL + '/newReceiptPushEndpoint',
'Should update push receipt endpoint');
}); });

Просмотреть файл

@ -14,9 +14,12 @@ XPCOMUtils.defineLazyGetter(this, "serverPort", function() {
return httpServer.identity.primaryPort; return httpServer.identity.primaryPort;
}); });
var handlerDone;
var handlerPromise = new Promise(r => handlerDone = after(2, r));
function resubscribeHandler(metadata, response) { function resubscribeHandler(metadata, response) {
ok(true, "Ask for new subscription"); ok(true, "Ask for new subscription");
do_test_finished(); handlerDone();
response.setHeader("Location", response.setHeader("Location",
'http://localhost:' + serverPort + '/newSubscription') 'http://localhost:' + serverPort + '/newSubscription')
response.setHeader("Link", response.setHeader("Link",
@ -27,7 +30,7 @@ function resubscribeHandler(metadata, response) {
function listenSuccessHandler(metadata, response) { function listenSuccessHandler(metadata, response) {
do_check_true(true, "New listener point"); do_check_true(true, "New listener point");
httpServer.stop(do_test_finished); httpServer.stop(handlerDone);
response.setStatusLine(metadata.httpVersion, 204, "Try again"); response.setStatusLine(metadata.httpVersion, 204, "Try again");
} }
@ -55,9 +58,6 @@ add_task(function* test1() {
return db.drop().then(_ => db.close()); return db.drop().then(_ => db.close());
}); });
do_test_pending();
do_test_pending();
var serverURL = "http://localhost:" + httpServer.identity.primaryPort; var serverURL = "http://localhost:" + httpServer.identity.primaryPort;
let records = [{ let records = [{
@ -88,4 +88,17 @@ add_task(function* test1() {
db db
}); });
yield handlerPromise;
let record = yield db.getByIdentifiers({
scope: 'https://example.com/page',
originAttributes: '',
});
equal(record.keyID, serverURL + '/newSubscription',
'Should update subscription URL');
equal(record.pushEndpoint, serverURL + '/newPushEndpoint',
'Should update push endpoint');
equal(record.pushReceiptEndpoint, serverURL + '/newReceiptPushEndpoint',
'Should update push receipt endpoint');
}); });