Fix issue _PushStatus stuck sending (#3808)
* Adds test for not set device tokens * Properly filter the installations without a deviceToken * nit for slower PG test * nit
This commit is contained in:
@@ -657,4 +657,80 @@ describe('PushController', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not enqueue push when device token is not set', (done) => {
|
||||||
|
var auth = {
|
||||||
|
isMaster: true
|
||||||
|
}
|
||||||
|
var pushAdapter = {
|
||||||
|
send: function(body, installations) {
|
||||||
|
const promises = installations.map((device) => {
|
||||||
|
if (!device.deviceToken) {
|
||||||
|
// Simulate error when device token is not set
|
||||||
|
return Promise.reject();
|
||||||
|
}
|
||||||
|
return Promise.resolve({
|
||||||
|
transmitted: true,
|
||||||
|
device: device,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
return Promise.all(promises);
|
||||||
|
},
|
||||||
|
getValidPushTypes: function() {
|
||||||
|
return ["ios"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var pushController = new PushController();
|
||||||
|
const payload = {
|
||||||
|
data: {
|
||||||
|
alert: 'hello',
|
||||||
|
},
|
||||||
|
push_time: new Date().getTime() / 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
var installations = [];
|
||||||
|
while(installations.length != 5) {
|
||||||
|
const installation = new Parse.Object("_Installation");
|
||||||
|
installation.set("installationId", "installation_" + installations.length);
|
||||||
|
installation.set("deviceToken","device_token_" + installations.length)
|
||||||
|
installation.set("badge", installations.length);
|
||||||
|
installation.set("originalBadge", installations.length);
|
||||||
|
installation.set("deviceType", "ios");
|
||||||
|
installations.push(installation);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(installations.length != 15) {
|
||||||
|
const installation = new Parse.Object("_Installation");
|
||||||
|
installation.set("installationId", "installation_" + installations.length);
|
||||||
|
installation.set("badge", installations.length);
|
||||||
|
installation.set("originalBadge", installations.length);
|
||||||
|
installation.set("deviceType", "ios");
|
||||||
|
installations.push(installation);
|
||||||
|
}
|
||||||
|
|
||||||
|
reconfigureServer({
|
||||||
|
push: { adapter: pushAdapter }
|
||||||
|
}).then(() => {
|
||||||
|
var config = new Config(Parse.applicationId);
|
||||||
|
return Parse.Object.saveAll(installations).then(() => {
|
||||||
|
return pushController.sendPush(payload, {}, config, auth);
|
||||||
|
}).then(() => new Promise(resolve => setTimeout(resolve, 100)));
|
||||||
|
}).then(() => {
|
||||||
|
const query = new Parse.Query('_PushStatus');
|
||||||
|
return query.find({useMasterKey: true}).then((results) => {
|
||||||
|
expect(results.length).toBe(1);
|
||||||
|
const pushStatus = results[0];
|
||||||
|
expect(pushStatus.get('numSent')).toBe(5);
|
||||||
|
expect(pushStatus.get('status')).toBe('succeeded');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
fail('should not fail');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ParseMessageQueue } from '../ParseMessageQueue';
|
import { ParseMessageQueue } from '../ParseMessageQueue';
|
||||||
import rest from '../rest';
|
import rest from '../rest';
|
||||||
import { isPushIncrementing } from './utils';
|
import { isPushIncrementing } from './utils';
|
||||||
|
import deepcopy from 'deepcopy';
|
||||||
|
|
||||||
const PUSH_CHANNEL = 'parse-server-push';
|
const PUSH_CHANNEL = 'parse-server-push';
|
||||||
const DEFAULT_BATCH_SIZE = 100;
|
const DEFAULT_BATCH_SIZE = 100;
|
||||||
@@ -27,7 +28,10 @@ export class PushQueue {
|
|||||||
// Order by badge (because the payload is badge dependant)
|
// Order by badge (because the payload is badge dependant)
|
||||||
// and createdAt to fix the order
|
// and createdAt to fix the order
|
||||||
const order = isPushIncrementing(body) ? 'badge,createdAt' : 'createdAt';
|
const order = isPushIncrementing(body) ? 'badge,createdAt' : 'createdAt';
|
||||||
|
where = deepcopy(where);
|
||||||
|
if (!where.hasOwnProperty('deviceToken')) {
|
||||||
|
where['deviceToken'] = {'$exists': true};
|
||||||
|
}
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
return rest.find(config,
|
return rest.find(config,
|
||||||
auth,
|
auth,
|
||||||
|
|||||||
Reference in New Issue
Block a user