diff --git a/src/EventStore.Core.Tests/Services/Storage/Chaser/when_chaser_reads_commit_event.cs b/src/EventStore.Core.Tests/Services/Storage/Chaser/when_chaser_reads_commit_event.cs index b4c48160fc..1316067b13 100644 --- a/src/EventStore.Core.Tests/Services/Storage/Chaser/when_chaser_reads_commit_event.cs +++ b/src/EventStore.Core.Tests/Services/Storage/Chaser/when_chaser_reads_commit_event.cs @@ -31,7 +31,7 @@ public override async ValueTask When(CancellationToken token) transactionOffset: 0xBEEF, eventStreamId: streamId, expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.Data, eventType: eventTypeId, data: new byte[] { 1, 2, 3, 4, 5 }, diff --git a/src/EventStore.Core.Tests/Services/Storage/Chaser/when_chaser_reads_committed_prepare_event.cs b/src/EventStore.Core.Tests/Services/Storage/Chaser/when_chaser_reads_committed_prepare_event.cs index 36a787ed34..472f506cb8 100644 --- a/src/EventStore.Core.Tests/Services/Storage/Chaser/when_chaser_reads_committed_prepare_event.cs +++ b/src/EventStore.Core.Tests/Services/Storage/Chaser/when_chaser_reads_committed_prepare_event.cs @@ -30,7 +30,7 @@ public override async ValueTask When(CancellationToken token) transactionOffset: 0xBEEF, eventStreamId: streamId, expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.IsCommitted | PrepareFlags.TransactionEnd, eventType: eventTypeId, data: new byte[] { 1, 2, 3, 4, 5 }, diff --git a/src/EventStore.Core.Tests/Services/Storage/Chaser/when_chaser_reads_prepare_event.cs b/src/EventStore.Core.Tests/Services/Storage/Chaser/when_chaser_reads_prepare_event.cs index 695fc9d0e5..db223a6b69 100644 --- a/src/EventStore.Core.Tests/Services/Storage/Chaser/when_chaser_reads_prepare_event.cs +++ b/src/EventStore.Core.Tests/Services/Storage/Chaser/when_chaser_reads_prepare_event.cs @@ -30,7 +30,7 @@ public override async ValueTask When(CancellationToken token) transactionOffset: 0xBEEF, eventStreamId: streamId, expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.SingleWrite, eventType: eventTypeId, data: new byte[] { 1, 2, 3, 4, 5 }, diff --git a/src/EventStore.Core.Tests/TransactionLog/Scavenging/Helpers/TFChunkDbCreationHelper.cs b/src/EventStore.Core.Tests/TransactionLog/Scavenging/Helpers/TFChunkDbCreationHelper.cs index 74ab6efd9b..49ce0e5d2c 100644 --- a/src/EventStore.Core.Tests/TransactionLog/Scavenging/Helpers/TFChunkDbCreationHelper.cs +++ b/src/EventStore.Core.Tests/TransactionLog/Scavenging/Helpers/TFChunkDbCreationHelper.cs @@ -581,6 +581,11 @@ public Rec(RecType type, int transaction, string streamId, string eventType, Dat Transaction = transaction; StreamId = streamId; EventType = eventType ?? string.Empty; + if (timestamp.HasValue && timestamp.Value.Kind != DateTimeKind.Utc) + { + throw new ArgumentException("Scavenge fixture prepare timestamps must be UTC.", nameof(timestamp)); + } + TimeStamp = timestamp ?? DateTime.UtcNow; Version = version; EventNumber = eventNumber; diff --git a/src/EventStore.Core.Tests/TransactionLog/tfchunk_get_actual_raw_position_should.cs b/src/EventStore.Core.Tests/TransactionLog/tfchunk_get_actual_raw_position_should.cs index 98dbd61831..6a11bb29e7 100644 --- a/src/EventStore.Core.Tests/TransactionLog/tfchunk_get_actual_raw_position_should.cs +++ b/src/EventStore.Core.Tests/TransactionLog/tfchunk_get_actual_raw_position_should.cs @@ -27,7 +27,7 @@ private IPrepareLogRecord CreateRecord(long logPosition, int dataSize { return LogRecord.Prepare(_recordFactory, logPosition, Guid.NewGuid(), Guid.NewGuid(), 0, 0, _streamId, 1, PrepareFlags.None, _eventTypeId, new byte[dataSize], Array.Empty(), - new DateTime(2000, 1, 1, 12, 0, 0)); + new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)); } private async ValueTask CreateChunk(int numEvents, bool completed, bool scavenged, diff --git a/src/EventStore.Core.Tests/TransactionLog/when_appending_past_end_of_a_tfchunk.cs b/src/EventStore.Core.Tests/TransactionLog/when_appending_past_end_of_a_tfchunk.cs index eb1bdd8098..4532b9d62b 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_appending_past_end_of_a_tfchunk.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_appending_past_end_of_a_tfchunk.cs @@ -25,7 +25,8 @@ public override async Task SetUp() var eventTypeId = LogFormatHelper.EventTypeId; var record = LogRecord.Prepare(recordFactory, 15556, _corrId, _eventId, 15556, 0, streamId, 1, - PrepareFlags.None, eventTypeId, new byte[12], new byte[15], new DateTime(2000, 1, 1, 12, 0, 0)); + PrepareFlags.None, eventTypeId, new byte[12], new byte[15], + new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)); _chunk = await TFChunkHelper.CreateNewChunk(Filename, 20); _written = (await _chunk.TryAppend(record, CancellationToken.None)).Success; } diff --git a/src/EventStore.Core.Tests/TransactionLog/when_appending_to_a_tfchunk_and_flushing.cs b/src/EventStore.Core.Tests/TransactionLog/when_appending_to_a_tfchunk_and_flushing.cs index 04138d82f4..69de3bbb52 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_appending_to_a_tfchunk_and_flushing.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_appending_to_a_tfchunk_and_flushing.cs @@ -26,7 +26,8 @@ public override async Task TestFixtureSetUp() var streamId = LogFormatHelper.StreamId; var eventTypeId = LogFormatHelper.EventTypeId; _record = LogRecord.Prepare(recordFactory, 0, _corrId, _eventId, 0, 0, streamId, 1, - PrepareFlags.None, eventTypeId, new byte[12], new byte[15], new DateTime(2000, 1, 1, 12, 0, 0)); + PrepareFlags.None, eventTypeId, new byte[12], new byte[15], + new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)); _chunk = await TFChunkHelper.CreateNewChunk(Filename); _result = await _chunk.TryAppend(_record, CancellationToken.None); await _chunk.Flush(CancellationToken.None); diff --git a/src/EventStore.Core.Tests/TransactionLog/when_appending_to_a_tfchunk_without_flush.cs b/src/EventStore.Core.Tests/TransactionLog/when_appending_to_a_tfchunk_without_flush.cs index d983bfa99b..9f4f7a4a32 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_appending_to_a_tfchunk_without_flush.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_appending_to_a_tfchunk_without_flush.cs @@ -27,7 +27,8 @@ public override async Task TestFixtureSetUp() var eventTypeId = LogFormatHelper.EventTypeId; _record = LogRecord.Prepare(recordFactory, 0, _corrId, _eventId, 0, 0, streamId, 1, - PrepareFlags.None, eventTypeId, new byte[12], new byte[15], new DateTime(2000, 1, 1, 12, 0, 0)); + PrepareFlags.None, eventTypeId, new byte[12], new byte[15], + new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)); _chunk = await TFChunkHelper.CreateNewChunk(Filename); _result = await _chunk.TryAppend(_record, CancellationToken.None); } diff --git a/src/EventStore.Core.Tests/TransactionLog/when_chasing_a_chunked_transaction_log.cs b/src/EventStore.Core.Tests/TransactionLog/when_chasing_a_chunked_transaction_log.cs index c96e03889b..8072518882 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_chasing_a_chunked_transaction_log.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_chasing_a_chunked_transaction_log.cs @@ -98,7 +98,7 @@ public async Task open_starts_from_the_latest_chaser_checkpoint() transactionOffset: 0, eventStreamId: streamId, expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: eventTypeId, data: new byte[] { 1, 2, 3, 4, 5 }, @@ -138,7 +138,7 @@ public async Task try_read_returns_record_when_writerchecksum_ahead() transactionOffset: 0, eventStreamId: streamId, expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: eventTypeId, data: new byte[] { 1, 2, 3, 4, 5 }, @@ -195,7 +195,7 @@ public async Task try_read_returns_record_when_record_bigger_than_internal_buffe transactionOffset: 0, eventStreamId: streamId, expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: eventTypeId, data: new byte[9000], @@ -239,7 +239,7 @@ public async Task try_read_returns_record_when_writerchecksum_equal() transactionOffset: 0, eventStreamId: streamId, expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: eventTypeId, data: new byte[] { 1, 2, 3, 4, 5 }, @@ -274,7 +274,7 @@ public void try_read_returns_false_when_writer_checksum_is_ahead_but_not_enough_ transactionPosition: 0, eventStreamId: "WorldEnding", expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: "type", data: new byte[] { 1, 2, 3, 4, 5 }, @@ -309,7 +309,7 @@ public void try_read_returns_false_when_writer_checksum_is_ahead_but_not_enough_ transactionPosition: 0, eventStreamId: "WorldEnding", expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: "type", data: new byte[] { 1, 2, 3, 4, 5 }, @@ -352,7 +352,7 @@ public void try_read_returns_properly_when_writer_is_written_to_while_chasing() transactionPosition: 0, eventStreamId: "WorldEnding", expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: "type", data: new byte[] { 1, 2, 3, 4, 5 }, @@ -377,7 +377,7 @@ public void try_read_returns_properly_when_writer_is_written_to_while_chasing() transactionPosition: 0, eventStreamId: "WorldEnding", expectedVersion: 4321, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: "type", data: new byte[] { 3, 2, 1 }, diff --git a/src/EventStore.Core.Tests/TransactionLog/when_closing_the_database.cs b/src/EventStore.Core.Tests/TransactionLog/when_closing_the_database.cs index 9c2110dfd3..2749205770 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_closing_the_database.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_closing_the_database.cs @@ -41,7 +41,7 @@ private static IPrepareLogRecord CreateRecord() transactionOffset: 0, eventStreamId: streamId, expectedVersion: -1, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.SingleWrite, eventType: eventTypeId, data: new byte[123], diff --git a/src/EventStore.Core.Tests/TransactionLog/when_reading_from_a_cached_tfchunk.cs b/src/EventStore.Core.Tests/TransactionLog/when_reading_from_a_cached_tfchunk.cs index caf7d1e7d7..a41c5b188b 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_reading_from_a_cached_tfchunk.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_reading_from_a_cached_tfchunk.cs @@ -31,7 +31,8 @@ public override async Task TestFixtureSetUp() var eventTypeId = LogFormatHelper.EventTypeId; _record = LogRecord.Prepare(recordFactory, 0, _corrId, _eventId, 0, 0, streamId, 1, - PrepareFlags.None, eventTypeId, new byte[12], new byte[15], new DateTime(2000, 1, 1, 12, 0, 0)); + PrepareFlags.None, eventTypeId, new byte[12], new byte[15], + new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)); _chunk = await TFChunkHelper.CreateNewChunk(Filename); _result = await _chunk.TryAppend(_record, CancellationToken.None); await _chunk.Flush(CancellationToken.None); diff --git a/src/EventStore.Core.Tests/TransactionLog/when_uncaching_a_tfchunk.cs b/src/EventStore.Core.Tests/TransactionLog/when_uncaching_a_tfchunk.cs index 90881f7429..966642375d 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_uncaching_a_tfchunk.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_uncaching_a_tfchunk.cs @@ -31,7 +31,8 @@ public override async Task TestFixtureSetUp() var eventTypeId = LogFormatHelper.EventTypeId; _record = LogRecord.Prepare(recordFactory, 0, _corrId, _eventId, 0, 0, streamId, 1, - PrepareFlags.None, eventTypeId, new byte[12], new byte[15], new DateTime(2000, 1, 1, 12, 0, 0)); + PrepareFlags.None, eventTypeId, new byte[12], new byte[15], + new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)); _chunk = await TFChunkHelper.CreateNewChunk(Filename); _result = await _chunk.TryAppend(_record, CancellationToken.None); await _chunk.Flush(CancellationToken.None); diff --git a/src/EventStore.Core.Tests/TransactionLog/when_writing_a_new_chunked_transaction_file.cs b/src/EventStore.Core.Tests/TransactionLog/when_writing_a_new_chunked_transaction_file.cs index d9085265a7..6541ddb9bc 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_writing_a_new_chunked_transaction_file.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_writing_a_new_chunked_transaction_file.cs @@ -41,7 +41,7 @@ public async Task a_record_can_be_written() transactionOffset: 0, eventStreamId: streamId, expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: eventTypeId, data: new byte[] { 1, 2, 3, 4, 5 }, diff --git a/src/EventStore.Core.Tests/TransactionLog/when_writing_an_existing_chunked_transaction_file_with_checksum.cs b/src/EventStore.Core.Tests/TransactionLog/when_writing_an_existing_chunked_transaction_file_with_checksum.cs index bb6d2e25ca..57d296fad7 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_writing_an_existing_chunked_transaction_file_with_checksum.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_writing_an_existing_chunked_transaction_file_with_checksum.cs @@ -52,7 +52,7 @@ public async Task a_record_can_be_written() transactionPos: 0, transactionOffset: 0, eventStreamId: streamId, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: eventTypeId, data: new byte[] { 1, 2, 3, 4, 5 }, diff --git a/src/EventStore.Core.Tests/TransactionLog/when_writing_an_existing_chunked_transaction_file_with_checksum_and_data_bigger_than_buffer.cs b/src/EventStore.Core.Tests/TransactionLog/when_writing_an_existing_chunked_transaction_file_with_checksum_and_data_bigger_than_buffer.cs index f72aceb76f..a71d359c8f 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_writing_an_existing_chunked_transaction_file_with_checksum_and_data_bigger_than_buffer.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_writing_an_existing_chunked_transaction_file_with_checksum_and_data_bigger_than_buffer.cs @@ -58,7 +58,7 @@ public async Task a_record_can_be_written() transactionOffset: 543, eventStreamId: streamId, expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.SingleWrite, eventType: eventTypeId, data: bytes, diff --git a/src/EventStore.Core.Tests/TransactionLog/when_writing_an_existing_chunked_transaction_file_with_not_enough_space_in_chunk.cs b/src/EventStore.Core.Tests/TransactionLog/when_writing_an_existing_chunked_transaction_file_with_not_enough_space_in_chunk.cs index 85ba79a142..549c135c02 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_writing_an_existing_chunked_transaction_file_with_not_enough_space_in_chunk.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_writing_an_existing_chunked_transaction_file_with_not_enough_space_in_chunk.cs @@ -55,7 +55,7 @@ public async Task a_record_is_not_written_at_first_but_written_on_second_try() transactionPos: 0, transactionOffset: 0, eventStreamId: streamId, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: eventTypeId, data: new byte[] { 1, 2, 3, 4, 5 }, @@ -72,7 +72,7 @@ public async Task a_record_is_not_written_at_first_but_written_on_second_try() transactionPos: pos, transactionOffset: 0, eventStreamId: streamId, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: eventTypeId, data: new byte[] { 1, 2, 3, 4, 5 }, @@ -89,7 +89,7 @@ public async Task a_record_is_not_written_at_first_but_written_on_second_try() transactionPos: pos, transactionOffset: 0, eventStreamId: streamId, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.None, eventType: eventTypeId, data: new byte[] { 1, 2, 3, 4, 5 }, diff --git a/src/EventStore.Core.Tests/TransactionLog/when_writing_multiple_records_to_a_tfchunk.cs b/src/EventStore.Core.Tests/TransactionLog/when_writing_multiple_records_to_a_tfchunk.cs index 10091d4754..2ab86b8316 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_writing_multiple_records_to_a_tfchunk.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_writing_multiple_records_to_a_tfchunk.cs @@ -34,13 +34,15 @@ public override async Task TestFixtureSetUp() var eventTypeId2 = LogFormatHelper.EventTypeId2; _prepare1 = LogRecord.Prepare(recordFactory, 0, _corrId, _eventId, 0, 0, streamId1, 1, - PrepareFlags.None, eventTypeId1, new byte[12], new byte[15], new DateTime(2000, 1, 1, 12, 0, 0)); + PrepareFlags.None, eventTypeId1, new byte[12], new byte[15], + new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)); var r1 = await _chunk.TryAppend(_prepare1, CancellationToken.None); _written1 = r1.Success; _position1 = r1.OldPosition; _prepare2 = LogRecord.Prepare(recordFactory, r1.NewPosition, _corrId, _eventId, 0, 0, streamId2, 2, - PrepareFlags.None, eventTypeId2, new byte[12], new byte[15], new DateTime(2000, 1, 1, 12, 0, 0)); + PrepareFlags.None, eventTypeId2, new byte[12], new byte[15], + new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)); var r2 = await _chunk.TryAppend(_prepare2, CancellationToken.None); _written2 = r2.Success; _position2 = r2.OldPosition; diff --git a/src/EventStore.Core.Tests/TransactionLog/when_writing_prepare_record_to_file.cs b/src/EventStore.Core.Tests/TransactionLog/when_writing_prepare_record_to_file.cs index 3959eb5d0d..47db7f34ef 100644 --- a/src/EventStore.Core.Tests/TransactionLog/when_writing_prepare_record_to_file.cs +++ b/src/EventStore.Core.Tests/TransactionLog/when_writing_prepare_record_to_file.cs @@ -45,7 +45,7 @@ public async Task SetUp() transactionOffset: 0xBEEF, eventStreamId: streamId, expectedVersion: 1234, - timeStamp: new DateTime(2012, 12, 21), + timeStamp: new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc), flags: PrepareFlags.SingleWrite, eventType: eventTypeId, data: new byte[] { 1, 2, 3, 4, 5 }, @@ -86,7 +86,7 @@ public async Task the_data_is_written() Assert.AreEqual(p.EventId, _eventId); Assert.AreEqual(p.EventStreamId, streamId); Assert.AreEqual(p.ExpectedVersion, 1234); - Assert.That(p.TimeStamp, Is.EqualTo(new DateTime(2012, 12, 21)).Within(7).Milliseconds); + Assert.That(p.TimeStamp, Is.EqualTo(new DateTime(2012, 12, 21, 0, 0, 0, DateTimeKind.Utc)).Within(7).Milliseconds); Assert.AreEqual(p.Flags, PrepareFlags.SingleWrite); Assert.AreEqual(p.EventType, eventTypeId); Assert.AreEqual(p.Data.Length, 5); diff --git a/src/EventStore.Core.XUnit.Tests/Scavenge/Infrastructure/StreamMetadatas.cs b/src/EventStore.Core.XUnit.Tests/Scavenge/Infrastructure/StreamMetadatas.cs index 9c8b02cab1..e11489a532 100644 --- a/src/EventStore.Core.XUnit.Tests/Scavenge/Infrastructure/StreamMetadatas.cs +++ b/src/EventStore.Core.XUnit.Tests/Scavenge/Infrastructure/StreamMetadatas.cs @@ -27,15 +27,16 @@ public class StreamMetadatas new StreamMetadata(truncateBefore: EventNumber.DeletedStream); public static DateTime EffectiveNow { get; } = new DateTime(2022, 1, 5, 00, 00, 00); - public static DateTime Expired { get; } = EffectiveNow - TimeSpan.FromDays(3); - public static DateTime Cutoff { get; } = EffectiveNow - MaxAgeTimeSpan; - public static DateTime Active { get; } = EffectiveNow - TimeSpan.FromDays(1); + private static DateTime EffectiveNowRecordTimestamp { get; } = new DateTime(2022, 1, 5, 00, 00, 00, DateTimeKind.Utc); + public static DateTime Expired { get; } = EffectiveNowRecordTimestamp - TimeSpan.FromDays(3); + public static DateTime Cutoff { get; } = EffectiveNowRecordTimestamp - MaxAgeTimeSpan; + public static DateTime Active { get; } = EffectiveNowRecordTimestamp - TimeSpan.FromDays(1); public static Rec ScavengePointRec(int transaction, int threshold = 0, DateTime? timeStamp = null) => Rec.Write( transaction: transaction, stream: SystemStreams.ScavengePointsStream, eventType: SystemEventTypes.ScavengePoint, - timestamp: timeStamp ?? EffectiveNow, + timestamp: timeStamp ?? EffectiveNowRecordTimestamp, data: new ScavengePointPayload { Threshold = threshold, diff --git a/src/EventStore.Core.XUnit.Tests/TransactionLog/LogRecords/PrepareLogRecordViewTests.cs b/src/EventStore.Core.XUnit.Tests/TransactionLog/LogRecords/PrepareLogRecordViewTests.cs index 9d4ecbfee4..e9a3260655 100644 --- a/src/EventStore.Core.XUnit.Tests/TransactionLog/LogRecords/PrepareLogRecordViewTests.cs +++ b/src/EventStore.Core.XUnit.Tests/TransactionLog/LogRecords/PrepareLogRecordViewTests.cs @@ -71,6 +71,27 @@ public void should_have_correct_properties() Assert.Equal(Version, _prepare.Version); } + [Fact] + public void constructor_should_reject_non_utc_timestamp() + { + Assert.Throws(() => new PrepareLogRecord( + LogPosition, + _correlationId, + _eventId, + TransactionPosition, + TransactionOffset, + EventStreamId, + null, + ExpectedVersion, + DateTime.Now, + Flags, + EventType, + null, + _data, + _metadata, + Version)); + } + [Fact] public void parsed_record_should_preserve_utc_timestamp_kind() { diff --git a/src/EventStore.Core/Services/Storage/InMemory/SingleEventInMemoryStream.cs b/src/EventStore.Core/Services/Storage/InMemory/SingleEventInMemoryStream.cs index cff43e2bfa..6ebf58ae3f 100644 --- a/src/EventStore.Core/Services/Storage/InMemory/SingleEventInMemoryStream.cs +++ b/src/EventStore.Core/Services/Storage/InMemory/SingleEventInMemoryStream.cs @@ -149,7 +149,7 @@ public void Write(string eventType, ReadOnlyMemory data) eventStreamId: _streamName, eventStreamIdSize: null, expectedVersion: _eventNumber - 1, - timeStamp: DateTime.Now, + timeStamp: DateTime.UtcNow, flags: Flags, eventType: eventType, eventTypeSize: null, diff --git a/src/EventStore.Core/TransactionLog/LogRecords/PrepareLogRecord.cs b/src/EventStore.Core/TransactionLog/LogRecords/PrepareLogRecord.cs index dadb5e77a2..85b30052f2 100644 --- a/src/EventStore.Core/TransactionLog/LogRecords/PrepareLogRecord.cs +++ b/src/EventStore.Core/TransactionLog/LogRecords/PrepareLogRecord.cs @@ -156,6 +156,11 @@ public PrepareLogRecord(long logPosition, throw new ArgumentOutOfRangeException("expectedVersion"); } + if (timeStamp.Kind != DateTimeKind.Utc) + { + throw new ArgumentException("Prepare log record timestamps must be UTC.", nameof(timeStamp)); + } + Flags = flags; TransactionPosition = transactionPosition; TransactionOffset = transactionOffset;