Skip to content

Commit

Permalink
Fixed unstable unit tests (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdoomen authored Jun 15, 2018
1 parent 85b8b7f commit cbf9308
Showing 1 changed file with 19 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,7 @@ public class
IPassiveEventStore eventStore = A.Fake<IPassiveEventStore>();
A.CallTo(() => eventStore.GetFrom(A<long?>.Ignored)).ReturnsLazily(call =>
{
string checkpointString = call.GetArgument<string>(0);
long checkpoint = string.IsNullOrEmpty(checkpointString)
? 0
: long.Parse(checkpointString, CultureInfo.InvariantCulture);
long checkpoint = call.GetArgument<long?>(0) ?? 0;
aSubscriptionStartedLoading.Set();
Expand All @@ -377,31 +373,24 @@ public class

When(() =>
{
Subject(
0,
new Subscriber
{
HandleTransactions = (transactions, info) => Task.FromResult(0)
},
"firstId");
Subject(0, new Subscriber
{
HandleTransactions = (transactions, info) => Task.FromResult(0)
}, "firstId");
if (!aSubscriptionStartedLoading.Wait(TimeSpan.FromSeconds(10)))
{
throw new InvalidOperationException("The first subscription has not started loading in 10 seconds.");
}
Subject(
null,
new Subscriber
Subject(null, new Subscriber
{
HandleTransactions = (transactions, info) =>
{
HandleTransactions = (transactions, info) =>
{
secondSubscriptionReceivedTheTransaction.Set();
return Task.FromResult(0);
}
},
"secondId"
);
secondSubscriptionReceivedTheTransaction.Set();
return Task.FromResult(0);
}
}, "secondId");
secondSubscriptionCreated.Set();
});
Expand All @@ -420,24 +409,23 @@ public void Then_the_second_subscription_should_not_hang()
public class When_the_subscriber_cancels_the_subscription_from_inside_its_transaction_handler :
GivenSubject<PollingEventStoreAdapter>
{
private readonly TimeSpan pollingInterval = 500.Milliseconds();
private readonly DateTime utcNow = DateTime.UtcNow;
private readonly ManualResetEventSlim disposed = new ManualResetEventSlim();

public When_the_subscriber_cancels_the_subscription_from_inside_its_transaction_handler()
{
Given(() =>
{
UseThe(new TransactionBuilder().WithCheckpoint(123).Build());
UseThe(A.Fake<IPassiveEventStore>());
A.CallTo(() => The<IPassiveEventStore>().GetFrom(A<long?>.Ignored)).Returns(new[] { The<Transaction>() });
A.CallTo(() => The<IPassiveEventStore>().GetFrom(A<long?>.Ignored)).Returns(new[]
{
new TransactionBuilder().WithCheckpoint(123).Build()
});
WithSubject(_ => new PollingEventStoreAdapter(The<IPassiveEventStore>(), 11, pollingInterval, 100,
() => utcNow));
WithSubject(_ => new PollingEventStoreAdapter(The<IPassiveEventStore>(), 11, 500.Milliseconds(), 100,
() => DateTime.UtcNow));
});

When(() => Subject.Subscribe(null,
When(() => Subject.Subscribe(0,
new Subscriber
{
HandleTransactions = (transactions, info) =>
Expand Down

0 comments on commit cbf9308

Please sign in to comment.