Skip to content

Commit

Permalink
Fix unit tests related to the Persistence DateTime bug (#7352)
Browse files Browse the repository at this point in the history
* Fix unit tests related to the Persistence DateTime bug

* Refactor additional method calls
  • Loading branch information
Arkatufus authored Oct 1, 2024
1 parent 5db9d86 commit f5c4e63
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected override void AfterAll()
public void LocalSnapshotStore_can_snapshot_actors_with_PersistenceId_containing_invalid_path_characters()
{
var pid = @"p\/:*?-1";
SnapshotStore.Tell(new SaveSnapshot(new SnapshotMetadata(pid, 1, Sys.Scheduler.Now.DateTime), "sample data"), TestActor);
SnapshotStore.Tell(new SaveSnapshot(new SnapshotMetadata(pid, 1, Sys.Scheduler.DateTimeNow), "sample data"), TestActor);
ExpectMsg<SaveSnapshotSuccess>();

SnapshotStore.Tell(new LoadSnapshot(pid, SnapshotSelectionCriteria.Latest, long.MaxValue), TestActor);
Expand Down
3 changes: 2 additions & 1 deletion src/core/Akka.Persistence.TCK/Query/PersistenceIdsSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ protected IActorRef WriteSnapshot(string persistenceId, int n)
ExpectMsg($"{persistenceId}-{i}-done");
}

var metadata = new SnapshotMetadata(persistenceId, n + 10, Sys.Scheduler.Now.DateTime);
var metadata = new SnapshotMetadata(persistenceId, n + 10, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
SnapshotStore.Tell(new SaveSnapshot(metadata, $"s-{n}"), _senderProbe.Ref);
_senderProbe.ExpectMsg<SaveSnapshotSuccess>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public virtual void SnapshotStore_should_serialize_Payload()

var snapshot = new Test.MySnapshot("a");

var metadata = new SnapshotMetadata(Pid, 1, Sys.Scheduler.Now.DateTime);
var metadata = new SnapshotMetadata(Pid, 1, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
SnapshotStore.Tell(new SaveSnapshot(metadata, snapshot), probe.Ref);
probe.ExpectMsg<SaveSnapshotSuccess>();

Expand All @@ -85,7 +86,8 @@ public virtual void SnapshotStore_should_serialize_Payload_with_string_manifest(

var snapshot = new Test.MySnapshot2("a");

var metadata = new SnapshotMetadata(Pid, 1, Sys.Scheduler.Now.DateTime);
var metadata = new SnapshotMetadata(Pid, 1, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
SnapshotStore.Tell(new SaveSnapshot(metadata, snapshot), probe.Ref);
probe.ExpectMsg<SaveSnapshotSuccess>();

Expand All @@ -107,7 +109,8 @@ public virtual void SnapshotStore_should_serialize_AtLeastOnceDeliverySnapshot()
};
var atLeastOnceDeliverySnapshot = new AtLeastOnceDeliverySnapshot(17, unconfirmed);

var metadata = new SnapshotMetadata(Pid, 2, Sys.Scheduler.Now.DateTime);
var metadata = new SnapshotMetadata(Pid, 2, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
SnapshotStore.Tell(new SaveSnapshot(metadata, atLeastOnceDeliverySnapshot), probe.Ref);
probe.ExpectMsg<SaveSnapshotSuccess>();

Expand All @@ -123,7 +126,8 @@ public virtual void SnapshotStore_should_serialize_AtLeastOnceDeliverySnapshot_w
var unconfirmed = Array.Empty<UnconfirmedDelivery>();
var atLeastOnceDeliverySnapshot = new AtLeastOnceDeliverySnapshot(13, unconfirmed);

var metadata = new SnapshotMetadata(Pid, 2, Sys.Scheduler.Now.DateTime);
var metadata = new SnapshotMetadata(Pid, 2, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
SnapshotStore.Tell(new SaveSnapshot(metadata, atLeastOnceDeliverySnapshot), probe.Ref);
probe.ExpectMsg<SaveSnapshotSuccess>();

Expand All @@ -138,7 +142,8 @@ public virtual void SnapshotStore_should_serialize_PersistentFSMSnapshot()

var persistentFSMSnapshot = new PersistentFSM.PersistentFSMSnapshot<string>("mystate", "mydata", TimeSpan.FromDays(4));

var metadata = new SnapshotMetadata(Pid, 2, Sys.Scheduler.Now.DateTime);
var metadata = new SnapshotMetadata(Pid, 2, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
SnapshotStore.Tell(new SaveSnapshot(metadata, persistentFSMSnapshot), probe.Ref);
probe.ExpectMsg<SaveSnapshotSuccess>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,16 @@ public async Task MultipleSnapshotsWithSameSeqNo()
var snapshotStore = persistence.SnapshotStoreFor(null);
var snap = new TestPayload(SenderProbe.Ref);

var metadata = new SnapshotMetadata(PersistenceId, 3, DateTime.Now);
var metadata = new SnapshotMetadata(PersistenceId, 3, DateTime.UtcNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
snapshotStore.Tell(new SaveSnapshot(metadata, snap), SenderProbe);
var success = await SenderProbe.ExpectMsgAsync<SaveSnapshotSuccess>(10.Minutes());
success.Metadata.PersistenceId.Should().Be(metadata.PersistenceId);
success.Metadata.Timestamp.Should().Be(metadata.Timestamp);
success.Metadata.SequenceNr.Should().Be(metadata.SequenceNr);

metadata = new SnapshotMetadata(PersistenceId, 3, DateTime.Now);
metadata = new SnapshotMetadata(PersistenceId, 3, DateTime.UtcNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
snapshotStore.Tell(new SaveSnapshot(metadata, 3), SenderProbe);
success = await SenderProbe.ExpectMsgAsync<SaveSnapshotSuccess>();
success.Metadata.PersistenceId.Should().Be(metadata.PersistenceId);
Expand Down
9 changes: 6 additions & 3 deletions src/core/Akka.Persistence.TCK/Snapshot/SnapshotStoreSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ private IEnumerable<SnapshotMetadata> WriteSnapshots()
{
for (int i = 1; i <= 5; i++)
{
var metadata = new SnapshotMetadata(Pid, i + 10, Sys.Scheduler.Now.DateTime);
var metadata = new SnapshotMetadata(Pid, i + 10, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
SnapshotStore.Tell(new SaveSnapshot(metadata, $"s-{i}"), _senderProbe.Ref);
yield return _senderProbe.ExpectMsg<SaveSnapshotSuccess>().Metadata;
}
Expand Down Expand Up @@ -312,7 +313,8 @@ public virtual void SnapshotStore_should_save_and_overwrite_snapshot_with_same_s
[Fact]
public virtual void SnapshotStore_should_save_bigger_size_snapshot()
{
var metadata = new SnapshotMetadata(Pid, 100, Sys.Scheduler.Now.DateTime);
var metadata = new SnapshotMetadata(Pid, 100, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
var bigSnapshot = new byte[SnapshotByteSizeLimit];
new Random().NextBytes(bigSnapshot);
SnapshotStore.Tell(new SaveSnapshot(metadata, bigSnapshot), _senderProbe.Ref);
Expand All @@ -326,7 +328,8 @@ public virtual void ShouldSerializeSnapshots()
if (!SupportsSerialization) return;

var probe = CreateTestProbe();
var metadata = new SnapshotMetadata(Pid, 100L, Sys.Scheduler.Now.DateTime);
var metadata = new SnapshotMetadata(Pid, 100L, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
var snap = new TestPayload(probe.Ref);

SnapshotStore.Tell(new SaveSnapshot(metadata, snap), _senderProbe.Ref);
Expand Down

0 comments on commit f5c4e63

Please sign in to comment.