Skip to content

Commit

Permalink
Added sleep to make sure projections have time to run
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasJakobsson committed May 9, 2024
1 parent 773046d commit 9ae3d0b
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using Akka.Persistence.TCK.Query;
using Akka.Streams;
using Akka.Streams.Dsl;
using Akka.Streams.TestKit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Akka.Persistence.EventStore.Tests.Query;

Expand All @@ -19,6 +21,34 @@ public EventStoreCurrentEventsByTagSpec(DatabaseFixture databaseFixture, ITestOu
ReadJournal = Sys.ReadJournalFor<EventStoreReadJournal>(EventStorePersistence.QueryConfigPath);
}

[Fact]
public override void ReadJournal_query_CurrentEventsByTag_should_see_all_150_events()
{
if (ReadJournal is not ICurrentEventsByTagQuery queries)
throw IsTypeException.ForMismatchedType(nameof(ICurrentEventsByTagQuery), ReadJournal?.GetType().Name ?? "null");

var a = Sys.ActorOf(Query.TestActor.Props("a"));

foreach (var _ in Enumerable.Range(1, 150))
{
a.Tell("a green apple");
ExpectMsg("a green apple-done");
}

Thread.Sleep(TimeSpan.FromMilliseconds(300));

var greenSrc = queries.CurrentEventsByTag("green", offset: Offset.NoOffset());
var probe = greenSrc.RunWith(this.SinkProbe<EventEnvelope>(), Materializer);
probe.Request(150);
foreach (var i in Enumerable.Range(1, 150))
{
ExpectEnvelope(probe, "a", i, "a green apple", "green");
}

probe.ExpectComplete();
probe.ExpectNoMsg(TimeSpan.FromMilliseconds(500));
}

[Fact]
public async Task ReadJournal_query_offset_exclusivity_should_be_correct()
{
Expand Down Expand Up @@ -50,4 +80,25 @@ public async Task ReadJournal_query_offset_exclusivity_should_be_correct()

round3.Should().HaveCount(1);
}

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

if (SupportsTagsInEventEnvelope)
{
envelope.Tags.Should().NotBeNull();
envelope.Tags.Should().Contain(tag);
}

return envelope;
}
}

0 comments on commit 9ae3d0b

Please sign in to comment.