BrighterCommand/Brighter

[Bug] Sqlite Queries don't support millisecond time comparisons

SteveBush opened this issue · 1 comments

Describe the bug

In the SQLite queries for PageDispatchedCommand and PagedOutstandingCommand, strftime is called with '%s' which returns seconds since 1970-01-01. This value is then multiplied by 1000 to get milliseconds and compared to OutstandingSince.

To Reproduce

Running the SQLite When_there_are_multiple_messages_and_some_are_received_and_Dispatched_bulk_Async test on a fast machine will fail unless you add a one-second delay between MarkDispatchedAsync and OutstandingMessagesAsync. I have verified waiting one second solves the comparison resolution issue.

In other words, the resolution of OutstandingSince is in milliseconds and the comparison is in seconds converted to milliseconds.

The fix is to change the SQL below to compare now - Dispatched to @OutstandingSince with millisecond resolution.

         public string PagedDispatchedCommand { get; } = "SELECT * FROM {0} WHERE DISPATCHED IS NOT NULL AND (strftime('%s', 'now') - strftime('%s', Dispatched)) * 1000 < @OutstandingSince ORDER BY Timestamp ASC LIMIT @PageSize OFFSET (@PageNumber-1) * @PageSize";
        public string PagedOutstandingCommand { get; } = "SELECT * FROM {0} WHERE DISPATCHED IS NULL AND (strftime('%s', 'now') - strftime('%s', TimeStamp)) * 1000 > @OutstandingSince ORDER BY Timestamp ASC LIMIT @PageSize OFFSET (@PageNumber-1) * @PageSize";

Exceptions (if any)

Further technical details

  • Brighter version
  • Include the output of dotnet --info
  • The OS (Window, Linux, MacOs, etc)

Verified code in 9.7.6. What are the plans to release 10.0.0-preview.2 with 9.7.6 merged fixes?