Files
wekan/server/lib/tests/activityNotificationExpiry.tests.js
T
Lauri Ojansivu e0317a9ff3 Drain the activity notification recovery list; index synced-cron's lookup.
#6768: the recovery scan retried every pending activity notification each
round, and one whose delivery fails for good - its activity deleted or
changed since, a recipient who lost access, a plan with nothing or too much
to send - failed the same way every round, forever, so the list only grew.
Such an error is terminal now: after a ten-minute grace (an activity being
written is never touched) the scan cancels that notification through the
same cancellation an administrator uses, as the system, which compacts it
to a cancelled receipt. A pending notification older than
ACTIVITY_NOTIFICATION_MAX_AGE_DAYS (7) is cancelled as expired instead of
being delivered a week late. Network and other transient failures are still
retried. Admin Panel -> Problems gets "Retry all" and "Cancel older..." for
the whole list at once, site administrators only.

#6769: before each run synced-cron asks whether a job of that name is still
running - { name, finishedAt: { $exists: false } } - every minute for every
job on every instance, and only { intendedAt, name } and the TTL on
startedAt were indexed, so it scanned the job history. { name, finishedAt }
is created at startup with WeKan's ensureIndex.

The new strings are translated in every locale.

Thanks to Raymond-Voogt and xet7 !

Fixes #6768,
Fixes #6769.
2026-10-14 14:00:21 +03:00

42 lines
2.6 KiB
JavaScript

import assert from 'node:assert/strict';
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { ActivityNotificationIntents, captureActivityNotificationIntent } from '/server/notifications/activityIntents';
import { ActivityNotificationControls, ActivityNotificationLeases, resumeActivityNotifications, giveUpActivityNotification } from '/server/notifications/activityPlans';
const { createActivityNotificationRecovery } = require('/server/lib/activityNotificationRecovery');
// #6768 on a running server: a pending notification whose activity no longer
// exists can never be delivered; once past the grace period the recovery scan
// cancels it - the same cancellation an administrator makes - instead of
// retrying it forever. A recent one is left alone.
describe('Activity notification expiry (#6768)', function () {
this.timeout(30000);
before(function () { if (!Meteor.isAppTest) this.skip(); });
it('cancels an undeliverable notification past the grace period, keeps a recent one', async function () {
const old = { _id: Random.id(), activityType: 'createCard', boardId: Random.id(), userId: Random.id(),
createdAt: new Date(Date.now() - 30 * 60 * 1000), modifiedAt: new Date(Date.now() - 30 * 60 * 1000) };
const fresh = { ...old, _id: Random.id(), createdAt: new Date(), modifiedAt: new Date() };
// Intents captured, activities never stored: their delivery can not succeed.
const oldIntent = await captureActivityNotificationIntent(old, old.userId);
const freshIntent = await captureActivityNotificationIntent(fresh, fresh.userId);
try {
const recover = createActivityNotificationRecovery({
intents: { find: (selector, options) => ActivityNotificationIntents.rawCollection()
.find({ ...selector, _id: { ...selector._id, $in: [oldIntent._id, freshIntent._id] } }, options) },
run: id => resumeActivityNotifications(id), giveUp: giveUpActivityNotification,
});
const result = await recover();
assert.equal(result.cancelled, 1, JSON.stringify(result));
assert.equal((await ActivityNotificationIntents.findOneAsync(oldIntent._id)).state, 'cancelled');
assert.equal((await ActivityNotificationIntents.findOneAsync(freshIntent._id)).state, 'pending', 'a recent one is retried, not cancelled');
} finally {
const ids = [oldIntent._id, freshIntent._id];
await ActivityNotificationIntents.rawCollection().deleteMany({ _id: { $in: ids } });
await ActivityNotificationControls.rawCollection().deleteMany({ _id: { $in: ids } });
await ActivityNotificationLeases.rawCollection().deleteMany({ _id: { $in: ids } });
}
});
});