Repository navigation
MOBILE-548: Send the age of an event as dateTimeOffset on its first attempt too - #854
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The tests check the constructed event instead of the queried result and set retryTimestamp to zero rather than leaving it unset, so the intended fetch path and returned retry state and offset remain unverified.
1 open issue
What changed in this PR
Updates Mindbox’s iOS event delivery to send an event’s age on its first attempt, preserving the original timing of events held in the database.
Changes:
- Calculate offsets regardless of retry status, retaining the nonnegative clamp.
- Add delayed-first-send and clock-rollback regression tests.
- Sort versioning test events by enqueue time instead of offset.
| File | Description |
|---|---|
| MindboxTests/Versioning/VersioningTestCase.swift | Orders events by enqueue timestamp. |
| MindboxTests/Mock/MockEvent.swift | Aligns mock offsets with first-attempt behavior. |
| MindboxTests/GuaranteedDelivery/GuaranteedDeliveryTestCase.swift | Adds offset cases and adjusts timing assertions. |
| MindboxTests/Database/DatabaseRepositoryTestCase.swift | Adds persisted-event offset regression cases. |
| Mindbox/Model/Event.swift | Removes the retry-only offset guard. |
Review effort: Balanced
|
justSmK
left a comment
There was a problem hiding this comment.
Изменение в Event.swift корректное. Во всех трёх сценариях из тикета offset считается при сборке запроса, в том числе после отложенной отправки из #846. Замечания касаются только тестов, они inline.
В описании PR написано «up to a month later», но события хранятся до 6 месяцев (MBDatabaseRepository.lifeLimitDate). Значит, offset может доходить примерно до 184 дней. В тикете та же неточность.

https://tracker.yandex.ru/MOBILE-548
An event that stayed in the database without a failed send attempt went out with
dateTimeOffset=0, so the backend dated it by the moment it arrived, not by the moment it happened. This is the case when the app is killed before the first attempt, when the queue is cancelled in the background, or when delivery is not enabled yet. On the next launch, up to six months later (MBDatabaseRepository.lifeLimitDate), an oldInapp.Showlooked like a show that had just happened, including for an in-app stopped weeks earlier.Event.dateTimeOffsetreturned 0 unless the event had aretryTimestamp. The zero comes from 6409b8e and ca43347 (2022), which stopped small negative offsets on the first attempt. #846 clamps the offset at 0, so the guard is no longer needed: the offset is now always the age of the event.Behaviour change. A fresh event is sent with an offset of a few milliseconds instead of 0.
Tests
DatabaseRepositoryTestCase: anInapp.Showstored three days ago with no send attempt is returned by the delivery query, and the request built from it carries a three-daydateTimeOffset(fails without the fix:0.0 is not equal to 259200000.0); the same event created before the clock was set back goes out withdateTimeOffset=0.retryTimestampis left unset, as for a real event that was never tried.GuaranteedDeliveryTestCase:testDateTimeOffset_WhenNotRetry_isZeropinned the old behaviour and now checks that a new event has an offset under a second.VersioningTestCasesorted events bydateTimeOffset, which was 0 for every event; it now sorts byenqueueTimeStamp.Checked
Mindboxtest plan passes on an iPhone 16 simulator;swiftlint --strictis clean.Event.dateTimeOffsetand of thedateTimeOffsetquery parameter inEventRoute(retry-only guard, inverted guard, no clamp,minformax, clamp at 1, constant 0, seconds for milliseconds, flipped sign, age fromretryTimestamp, constant 0 in the request, parameter omitted) are all killed byDatabaseRepositoryTestCaseandGuaranteedDeliveryTestCase.DeliveryOperation.main()and sent on the next launch carries its age indateTimeOffset.Stacked on #846 (base
feature/MOBILE-541): merge after it.