mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-25 20:01:50 +00:00
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:
parent
ec4c382804
commit
ff6fdbef17
@ -404,10 +404,20 @@ this.PushDB.prototype = {
|
||||
aKeyID, newRecord);
|
||||
return;
|
||||
}
|
||||
aStore.put(newRecord).onsuccess = aEvent => {
|
||||
console.debug("update: Update successful", aKeyID, newRecord);
|
||||
aTxn.result = newRecord;
|
||||
};
|
||||
function putRecord() {
|
||||
let req = aStore.put(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,
|
||||
|
@ -14,15 +14,18 @@ XPCOMUtils.defineLazyGetter(this, "serverPort", function() {
|
||||
return httpServer.identity.primaryPort;
|
||||
});
|
||||
|
||||
var handlerDone;
|
||||
var handlerPromise = new Promise(r => handlerDone = after(3, r));
|
||||
|
||||
function listen4xxCodeHandler(metadata, response) {
|
||||
ok(true, "Listener point error")
|
||||
do_test_finished();
|
||||
handlerDone();
|
||||
response.setStatusLine(metadata.httpVersion, 410, "GONE");
|
||||
}
|
||||
|
||||
function resubscribeHandler(metadata, response) {
|
||||
ok(true, "Ask for new subscription");
|
||||
do_test_finished();
|
||||
handlerDone();
|
||||
response.setHeader("Location",
|
||||
'http://localhost:' + serverPort + '/newSubscription')
|
||||
response.setHeader("Link",
|
||||
@ -33,7 +36,7 @@ function resubscribeHandler(metadata, response) {
|
||||
|
||||
function listenSuccessHandler(metadata, response) {
|
||||
do_check_true(true, "New listener point");
|
||||
httpServer.stop(do_test_finished);
|
||||
httpServer.stop(handlerDone);
|
||||
response.setStatusLine(metadata.httpVersion, 204, "Try again");
|
||||
}
|
||||
|
||||
@ -61,10 +64,6 @@ add_task(function* test1() {
|
||||
return db.drop().then(_ => db.close());
|
||||
});
|
||||
|
||||
do_test_pending();
|
||||
do_test_pending();
|
||||
do_test_pending();
|
||||
|
||||
var serverURL = "http://localhost:" + httpServer.identity.primaryPort;
|
||||
|
||||
let records = [{
|
||||
@ -85,4 +84,17 @@ add_task(function* test1() {
|
||||
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;
|
||||
});
|
||||
|
||||
var retries = 0
|
||||
var retries = 0;
|
||||
var handlerDone;
|
||||
var handlerPromise = new Promise(r => handlerDone = after(5, r));
|
||||
|
||||
function listen5xxCodeHandler(metadata, response) {
|
||||
ok(true, "Listener 5xx code");
|
||||
do_test_finished();
|
||||
handlerDone();
|
||||
retries++;
|
||||
response.setHeader("Retry-After", '1');
|
||||
response.setStatusLine(metadata.httpVersion, 500, "Retry");
|
||||
@ -27,7 +29,7 @@ function listen5xxCodeHandler(metadata, response) {
|
||||
function resubscribeHandler(metadata, response) {
|
||||
ok(true, "Ask for new subscription");
|
||||
ok(retries == 3, "Should retry 2 times.");
|
||||
do_test_finished();
|
||||
handlerDone();
|
||||
response.setHeader("Location",
|
||||
'http://localhost:' + serverPort + '/newSubscription')
|
||||
response.setHeader("Link",
|
||||
@ -38,7 +40,7 @@ function resubscribeHandler(metadata, response) {
|
||||
|
||||
function listenSuccessHandler(metadata, response) {
|
||||
do_check_true(true, "New listener point");
|
||||
httpServer.stop(do_test_finished);
|
||||
httpServer.stop(handlerDone);
|
||||
response.setStatusLine(metadata.httpVersion, 204, "Try again");
|
||||
}
|
||||
|
||||
@ -67,12 +69,6 @@ add_task(function* test1() {
|
||||
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;
|
||||
|
||||
let records = [{
|
||||
@ -93,4 +89,17 @@ add_task(function* test1() {
|
||||
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;
|
||||
});
|
||||
|
||||
var handlerDone;
|
||||
var handlerPromise = new Promise(r => handlerDone = after(2, r));
|
||||
|
||||
function resubscribeHandler(metadata, response) {
|
||||
ok(true, "Ask for new subscription");
|
||||
do_test_finished();
|
||||
handlerDone();
|
||||
response.setHeader("Location",
|
||||
'http://localhost:' + serverPort + '/newSubscription')
|
||||
response.setHeader("Link",
|
||||
@ -27,7 +30,7 @@ function resubscribeHandler(metadata, response) {
|
||||
|
||||
function listenSuccessHandler(metadata, response) {
|
||||
do_check_true(true, "New listener point");
|
||||
httpServer.stop(do_test_finished);
|
||||
httpServer.stop(handlerDone);
|
||||
response.setStatusLine(metadata.httpVersion, 204, "Try again");
|
||||
}
|
||||
|
||||
@ -55,9 +58,6 @@ add_task(function* test1() {
|
||||
return db.drop().then(_ => db.close());
|
||||
});
|
||||
|
||||
do_test_pending();
|
||||
do_test_pending();
|
||||
|
||||
var serverURL = "http://localhost:" + httpServer.identity.primaryPort;
|
||||
|
||||
let records = [{
|
||||
@ -88,4 +88,17 @@ add_task(function* test1() {
|
||||
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');
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user