Skip to content

Commit

Permalink
Refactored racy persistent spec to make failure more clear (no fix pr…
Browse files Browse the repository at this point in the history
…ovided)
  • Loading branch information
IgorFedchenko committed Feb 12, 2021
1 parent 3c194d7 commit 48b8477
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/core/Akka.Persistence.TCK/Query/EventsByTagSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Akka.Persistence.Query;
using Akka.Streams;
using Akka.Streams.TestKit;
using Akka.TestKit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
using static Akka.Persistence.Query.Offset;
Expand Down Expand Up @@ -49,18 +51,18 @@ public virtual void ReadJournal_live_query_EventsByTag_should_find_new_events()
var blackSrc = queries.EventsByTag("black", offset: NoOffset());
var probe = blackSrc.RunWith(this.SinkProbe<EventEnvelope>(), Materializer);
probe.Request(2);
probe.ExpectNext<EventEnvelope>(p => p.PersistenceId == "b" && p.SequenceNr == 1L && p.Event.Equals("a black car"));
ExpectEnvelope(probe, "b", 1L, "a black car");
probe.ExpectNoMsg(TimeSpan.FromMilliseconds(100));

d.Tell("a black dog");
ExpectMsg("a black dog-done");
d.Tell("a black night");
ExpectMsg("a black night-done");

probe.ExpectNext<EventEnvelope>(p => p.PersistenceId == "d" && p.SequenceNr == 1L && p.Event.Equals("a black dog"));
ExpectEnvelope(probe, "d", 1L, "a black dog");
probe.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
probe.Request(10);
probe.ExpectNext<EventEnvelope>(p => p.PersistenceId == "d" && p.SequenceNr == 2L && p.Event.Equals("a black night"));
ExpectEnvelope(probe, "d", 2L, "a black night");
probe.Cancel();
}

Expand Down Expand Up @@ -91,17 +93,26 @@ public virtual void ReadJournal_live_query_EventsByTag_should_find_events_from_o
var greenSrc1 = queries.EventsByTag("green", offset: NoOffset());
var probe1 = greenSrc1.RunWith(this.SinkProbe<EventEnvelope>(), Materializer);
probe1.Request(2);
probe1.ExpectNext<EventEnvelope>(p => p.PersistenceId == "a" && p.SequenceNr == 2L && p.Event.Equals("a green apple"));
var offs = probe1.ExpectNext<EventEnvelope>(p => p.PersistenceId == "a" && p.SequenceNr == 4L && p.Event.Equals("a green banana")).Offset;
ExpectEnvelope(probe1, "a", 2L, "a green apple");
var offs = ExpectEnvelope(probe1, "a", 4L, "a green banana").Offset;
probe1.Cancel();

var greenSrc2 = queries.EventsByTag("green", offset: offs);
var probe2 = greenSrc2.RunWith(this.SinkProbe<EventEnvelope>(), Materializer);
probe2.Request(10);
probe2.ExpectNext<EventEnvelope>(p => p.PersistenceId == "b" && p.SequenceNr == 2L && p.Event.Equals("a green leaf"));
probe2.ExpectNext<EventEnvelope>(p => p.PersistenceId == "c" && p.SequenceNr == 1L && p.Event.Equals("a green cucumber"));
ExpectEnvelope(probe2, "b", 2L, "a green leaf");
ExpectEnvelope(probe2, "c", 1L, "a green cucumber");
probe2.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
probe2.Cancel();
}

private EventEnvelope ExpectEnvelope(TestSubscriber.Probe<EventEnvelope> probe, string persistenceId, long sequenceNr, string @event)
{
var envelope = probe.ExpectNext<EventEnvelope>(e => true);
envelope.PersistenceId.Should().Be(persistenceId);
envelope.SequenceNr.Should().Be(sequenceNr);
envelope.Event.Should().Be(@event);
return envelope;
}
}
}

0 comments on commit 48b8477

Please sign in to comment.