Skip to content

Commit cbf9308

Browse files
authored
Fixed unstable unit tests (#15)
1 parent 85b8b7f commit cbf9308

1 file changed

Lines changed: 19 additions & 31 deletions

File tree

Tests/LiquidProjections.PollingEventStore.Specs/PollingEventStoreAdapterSpecs.cs

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,7 @@ public class
350350
IPassiveEventStore eventStore = A.Fake<IPassiveEventStore>();
351351
A.CallTo(() => eventStore.GetFrom(A<long?>.Ignored)).ReturnsLazily(call =>
352352
{
353-
string checkpointString = call.GetArgument<string>(0);
354-
355-
long checkpoint = string.IsNullOrEmpty(checkpointString)
356-
? 0
357-
: long.Parse(checkpointString, CultureInfo.InvariantCulture);
353+
long checkpoint = call.GetArgument<long?>(0) ?? 0;
358354

359355
aSubscriptionStartedLoading.Set();
360356

@@ -377,31 +373,24 @@ public class
377373

378374
When(() =>
379375
{
380-
Subject(
381-
0,
382-
new Subscriber
383-
{
384-
HandleTransactions = (transactions, info) => Task.FromResult(0)
385-
},
386-
"firstId");
376+
Subject(0, new Subscriber
377+
{
378+
HandleTransactions = (transactions, info) => Task.FromResult(0)
379+
}, "firstId");
387380

388381
if (!aSubscriptionStartedLoading.Wait(TimeSpan.FromSeconds(10)))
389382
{
390383
throw new InvalidOperationException("The first subscription has not started loading in 10 seconds.");
391384
}
392385

393-
Subject(
394-
null,
395-
new Subscriber
386+
Subject(null, new Subscriber
387+
{
388+
HandleTransactions = (transactions, info) =>
396389
{
397-
HandleTransactions = (transactions, info) =>
398-
{
399-
secondSubscriptionReceivedTheTransaction.Set();
400-
return Task.FromResult(0);
401-
}
402-
},
403-
"secondId"
404-
);
390+
secondSubscriptionReceivedTheTransaction.Set();
391+
return Task.FromResult(0);
392+
}
393+
}, "secondId");
405394

406395
secondSubscriptionCreated.Set();
407396
});
@@ -420,24 +409,23 @@ public void Then_the_second_subscription_should_not_hang()
420409
public class When_the_subscriber_cancels_the_subscription_from_inside_its_transaction_handler :
421410
GivenSubject<PollingEventStoreAdapter>
422411
{
423-
private readonly TimeSpan pollingInterval = 500.Milliseconds();
424-
private readonly DateTime utcNow = DateTime.UtcNow;
425412
private readonly ManualResetEventSlim disposed = new ManualResetEventSlim();
426413

427414
public When_the_subscriber_cancels_the_subscription_from_inside_its_transaction_handler()
428415
{
429416
Given(() =>
430417
{
431-
UseThe(new TransactionBuilder().WithCheckpoint(123).Build());
432-
433418
UseThe(A.Fake<IPassiveEventStore>());
434-
A.CallTo(() => The<IPassiveEventStore>().GetFrom(A<long?>.Ignored)).Returns(new[] { The<Transaction>() });
419+
A.CallTo(() => The<IPassiveEventStore>().GetFrom(A<long?>.Ignored)).Returns(new[]
420+
{
421+
new TransactionBuilder().WithCheckpoint(123).Build()
422+
});
435423

436-
WithSubject(_ => new PollingEventStoreAdapter(The<IPassiveEventStore>(), 11, pollingInterval, 100,
437-
() => utcNow));
424+
WithSubject(_ => new PollingEventStoreAdapter(The<IPassiveEventStore>(), 11, 500.Milliseconds(), 100,
425+
() => DateTime.UtcNow));
438426
});
439427

440-
When(() => Subject.Subscribe(null,
428+
When(() => Subject.Subscribe(0,
441429
new Subscriber
442430
{
443431
HandleTransactions = (transactions, info) =>

0 commit comments

Comments
 (0)