Skip to content

Commit

Permalink
Typos, unused fields, spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-m committed Jun 27, 2024
1 parent 2790b2d commit cb4a738
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Diagnostics;
using Xunit.Abstractions;
using static M.EventBrokerSlim.Tests.LoadTests;
using Xunit.Abstractions;

namespace M.EventBrokerSlim.Tests.DelegateHandlerTests;

Expand Down Expand Up @@ -35,7 +33,7 @@ public async Task Event_Injected_In_Handler()
using var scope = _serviceProvider.CreateScope();
var eventBroker = scope.ServiceProvider.GetRequiredService<IEventBroker>();
_tracker.ExpectedItemsCount = 2;
Event1 event1 = new Event1(1);
var event1 = new Event1(1);

// Act
await eventBroker.Publish(event1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ public async Task Multiple_Builders_Registered()
Assert.Equal(new[] { "handler1", "handler2", "handler3" }, _eventsTracker.Items.Select(x => x.Item).Cast<string>().Order().ToArray());
}

private Delegate GetHandler(int parametersCount, EventsTracker _eventsTracker)
#pragma warning disable RCS1163 // Unused parameter
private static Delegate GetHandler(int parametersCount, EventsTracker _eventsTracker)
=> parametersCount switch
{
0 => async () => await _eventsTracker.TrackAsync(1),
Expand All @@ -247,6 +248,7 @@ private Delegate GetHandler(int parametersCount, EventsTracker _eventsTracker)
17 => async (A1 a1, A2 a2, A3 a3, A4 a4, A4 a5, A4 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11, A12 a12, A13 a13, A14 a14, A15 a15, A16 a16, A17 a17) => await _eventsTracker.TrackAsync(1),
_ => throw new NotImplementedException(),
};
#pragma warning restore RCS1163 // Unused parameter

class Handler1(EventsTracker tracker) : IEventHandler<Event1>
{
Expand Down
8 changes: 4 additions & 4 deletions test/M.EventBrokerSlim.Tests/EventRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ public class EventsRecorder<T> where T : notnull
{
private readonly ConcurrentDictionary<T, object?> _expected = new();
private readonly TimeSpan _waitForItemsTimeout = TimeSpan.FromMilliseconds(20);
private readonly ConcurrentBag<Exception> _exceptions = new();
private readonly ConcurrentBag<(T id, long tick)> _events = new();
private readonly ConcurrentBag<(int id, long tick)> _handlerInstances = new();
private readonly ConcurrentBag<(int id, long tick)> _scopeInstances = new();
private readonly ConcurrentBag<Exception> _exceptions = [];
private readonly ConcurrentBag<(T id, long tick)> _events = [];
private readonly ConcurrentBag<(int id, long tick)> _handlerInstances = [];
private readonly ConcurrentBag<(int id, long tick)> _scopeInstances = [];

public Exception[] Exceptions => _exceptions.ToArray();

Expand Down
4 changes: 2 additions & 2 deletions test/M.EventBrokerSlim.Tests/EventsTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace M.EventBrokerSlim.Tests;

public class EventsTracker
{
private readonly Stopwatch _stopwatch = new Stopwatch();
private readonly Stopwatch _stopwatch = new ();
private CancellationTokenSource? _cancellationTokenSource;

public int ExpectedItemsCount { get; set; } = int.MaxValue;
Expand All @@ -28,7 +28,7 @@ public Task TrackAsync(object item)
return Task.CompletedTask;
}

public ConcurrentBag<(object Item, DateTime Timestamp)> Items { get; } = new();
public ConcurrentBag<(object Item, DateTime Timestamp)> Items { get; } = [];

public async Task Wait(TimeSpan timeout)
{
Expand Down
2 changes: 1 addition & 1 deletion test/M.EventBrokerSlim.Tests/ExceptionHandlingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public TestEventHandler1(string input)
_input = input;
}

public Task Handle(TestEvent @even, IRetryPolicy retryPolicyt, CancellationToken cancellationToken) => throw new NotImplementedException();
public Task Handle(TestEvent @even, IRetryPolicy retryPolicy, CancellationToken cancellationToken) => throw new NotImplementedException();

public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) => throw new NotImplementedException();
}
Expand Down
10 changes: 5 additions & 5 deletions test/M.EventBrokerSlim.Tests/HandlerExecutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,26 @@ public record TestEvent(int CorrelationId, TimeSpan TimeToRun = default) : ITrac

public class TestEventHandler : IEventHandler<TestEvent>
{
private readonly EventsRecorder<int> _eventsRecoder;
private readonly EventsRecorder<int> _eventsRecorder;

public TestEventHandler(EventsRecorder<int> eventsRecorder)
{
_eventsRecoder = eventsRecorder;
_eventsRecorder = eventsRecorder;
}

public async Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken)
{
if(@event.TimeToRun != default)
{
await Task.Delay(@event.TimeToRun);
await Task.Delay(@event.TimeToRun, cancellationToken);
}

_eventsRecoder.Notify(@event);
_eventsRecorder.Notify(@event);
}

public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken)
{
_eventsRecoder.Notify(exception, @event);
_eventsRecorder.Notify(exception, @event);
return Task.CompletedTask;
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/M.EventBrokerSlim.Tests/LoadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public Task Handle(T @event, IRetryPolicy retryPolicy, CancellationToken cancell
{
throw new NotImplementedException();
}

return Task.CompletedTask;
}

Expand All @@ -98,6 +99,7 @@ public Task OnError(Exception exception, T @event, IRetryPolicy retryPolicy, Can
{
retryPolicy.RetryAfter(_settings.Delay);
}

return Task.CompletedTask;
}
}
Expand All @@ -120,6 +122,7 @@ public Task Handle(T @event, IRetryPolicy retryPolicy, CancellationToken cancell
{
retryPolicy.RetryAfter(_settings.Delay);
}

return Task.CompletedTask;
}

Expand Down
2 changes: 2 additions & 0 deletions test/M.EventBrokerSlim.Tests/OrderOfRetriesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public Task Handle(TestEvent1 @event, IRetryPolicy retryPolicy, CancellationToke
{
retryPolicy.RetryAfter(TimeSpan.FromMilliseconds(800));
}

throw new NotImplementedException();
}

Expand All @@ -93,6 +94,7 @@ public Task Handle(TestEvent2 @event, IRetryPolicy retryPolicy, CancellationToke
{
retryPolicy.RetryAfter(TimeSpan.FromMilliseconds(100));
}

throw new NotImplementedException();
}

Expand Down
1 change: 0 additions & 1 deletion test/M.EventBrokerSlim.Tests/RetryFromHandleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public record HandlerSettings(int RetryAttempts, TimeSpan Delay);

public class TestEventHandler : IEventHandler<TestEvent>
{
private readonly Random _random = new();
private readonly EventsTracker _tracker;
private readonly HandlerSettings _settings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public record HandlerSettings(int RetryAttempts, TimeSpan Delay);

public class TestEventHandler : IEventHandler<TestEvent>
{
private readonly Random _random = new();
private readonly EventsTracker _tracker;
private readonly HandlerSettings _settings;

Expand Down
1 change: 0 additions & 1 deletion test/M.EventBrokerSlim.Tests/RetryFromOnErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public record HandlerSettings(int RetryAttempts, TimeSpan Delay);

public class TestEventHandler : IEventHandler<TestEvent>
{
private readonly Random _random = new();
private readonly EventsTracker _tracker;
private readonly HandlerSettings _settings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public record HandlerSettings(int RetryAttempts, TimeSpan Delay);

public class TestEventHandler : IEventHandler<TestEvent>
{
private readonly Random _random = new();
private readonly EventsTracker _tracker;
private readonly HandlerSettings _settings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public record HandlerSettings(int RetryAttempts, TimeSpan Delay);

public class TestEventHandler : IEventHandler<TestEvent>
{
private readonly Random _random = new();
private readonly EventsTracker _tracker;
private readonly HandlerSettings _settings;

Expand Down
1 change: 1 addition & 0 deletions test/M.EventBrokerSlim.Tests/RetryPolicyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken
{
retryPolicy.RetryAfter(_settings.Delay);
}

throw new NotImplementedException();
}

Expand Down

0 comments on commit cb4a738

Please sign in to comment.