mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
* notices: Ensure that two notices don't have the same lastDateTime When a client wants to receive the notices using the /v2/notices interface, it usually will first receive all the old notifications, store the date and time of the last notification, and in the next calls use that date and time plus 1 nanosecond to avoid geting the same notices over and over again. Unfortunately, if, due to chance, two notifications have the same date and time, this scheme will fail, because after receiving the first one, the call will return it, and when the client asks for the next, it will filter from the date/time plus one microsecond, so the second notice won't be sent. This patch fixes this by ensuring that no notice has the same date/time value for lastReceived, by adding one or more nanoseconds when required. * Implement time.Time.Compare() time.Time.Compare() was added in Go 1.20, but snapd uses Go 1.18 so this method isn't available. * Added tests for CompareDate() * Simplified time.Time.Compare() function * Update overlord/state/notices.go Co-authored-by: Zeyad Yasser <zeyady98@gmail.com> * Changes requested by Zeyad * Fix tests * Remove unneeded MockGetTimeNow * Changed timestamp name, and fixed test * Replace all notice-last-date with notice-last-timestamp * fix typo * Remove unneeded GetLastOccurred function * Change noticeLastTimestamp with lastNoticeTimestamp * Fix tests * Add a comment explaining why this is important * Add missing space --------- Co-authored-by: Zeyad Yasser <zeyady98@gmail.com>