Check if bounce sync is scheduled within 42 hours for all emails when sending

[MAILPOET-2705]
This commit is contained in:
Jan Jakeš
2020-02-19 11:35:25 +01:00
committed by Jack Kitterhing
parent 024ac52fb9
commit ecc1d68b5b
5 changed files with 69 additions and 32 deletions

View File

@ -830,6 +830,55 @@ class SendingQueueTest extends \MailPoetTest {
$wp->removeFilter('mailpoet_cron_worker_sending_queue_batch_size', $filter);
}
public function testItReschedulesBounceTaskWhenPlannedInFarFuture() {
$task = ScheduledTask::createOrUpdate([
'type' => 'bounce',
'status' => ScheduledTask::STATUS_SCHEDULED,
'scheduled_at' => Carbon::createFromTimestamp(WPFunctions::get()->currentTime('timestamp'))->addMonths(1),
]);
$sendingQueueWorker = new SendingQueueWorker(
$this->sendingErrorHandler,
$this->statsNotificationsWorker,
$this->loggerFactory,
Stub::makeEmpty(NewslettersRepository::class, ['findOneById' => new NewsletterEntity()]),
$this->cronHelper,
$this->make(new MailerTask(), [
'send' => $this->mailerTaskDummyResponse,
])
);
$sendingQueueWorker->process();
$refetchedTask = ScheduledTask::where('id', $task->id)->findOne();
assert($refetchedTask instanceof ScheduledTask); // PHPStan
expect($refetchedTask->scheduledAt)->lessThan(Carbon::createFromTimestamp(WPFunctions::get()->currentTime('timestamp'))->addHours(42));
}
public function testDoesNoRescheduleBounceTaskWhenPlannedInNearFuture() {
$inOneHour = Carbon::createFromTimestamp(WPFunctions::get()->currentTime('timestamp'))->addHours(1);
$task = ScheduledTask::createOrUpdate([
'type' => 'bounce',
'status' => ScheduledTask::STATUS_SCHEDULED,
'scheduled_at' => $inOneHour,
]);
$sendingQueueWorker = new SendingQueueWorker(
$this->sendingErrorHandler,
$this->statsNotificationsWorker,
$this->loggerFactory,
Stub::makeEmpty(NewslettersRepository::class, ['findOneById' => new NewsletterEntity()]),
$this->cronHelper,
$this->make(new MailerTask(), [
'send' => $this->mailerTaskDummyResponse,
])
);
$sendingQueueWorker->process();
$refetchedTask = ScheduledTask::where('id', $task->id)->findOne();
assert($refetchedTask instanceof ScheduledTask); // PHPStan
expect($refetchedTask->scheduledAt)->equals($inOneHour);
}
public function _after() {
ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
ORM::raw_execute('TRUNCATE ' . SubscriberSegment::$_table);