Skip to content

Commit

Permalink
Merge branch 'ConnectionInterface' into Baseline4R2
Browse files Browse the repository at this point in the history
  • Loading branch information
Scretch9 committed Nov 30, 2023
2 parents 8652b66 + 09a429c commit bd54513
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/FieldElementSubsystems.Test/Point/PointTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace FieldElementSubsystems.Test;
public class PointTest
{
private EulynxLive.Point.Point CreateDefaultPoint(IPointToInterlockingConnection? connection = null) =>
new EulynxLive.Point.Point(_logger, _configuration, connection ?? Mock.Of<IPointToInterlockingConnection>());
new EulynxLive.Point.Point(_logger, _configuration, connection ?? Mock.Of<IPointToInterlockingConnection>(), async () => {});

private Mock<IPointToInterlockingConnection> CreateDefaultMockConnection() {
var mockConnection = new Mock<IPointToInterlockingConnection>();
Expand Down
6 changes: 4 additions & 2 deletions src/Point/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Point : BackgroundService
public bool AllPointMachinesCrucial { get; }

private readonly ILogger<Point> _logger;
private readonly Func<Task> _simulateTimeout;
private readonly List<WebSocket> _webSockets;
private IPointToInterlockingConnection _connection;
private readonly Random _random;
Expand All @@ -23,9 +24,10 @@ public class Point : BackgroundService
private readonly PointState _pointState;
public PointState PointState { get { return _pointState; } }

public Point(ILogger<Point> logger, IConfiguration configuration, IPointToInterlockingConnection connection)
public Point(ILogger<Point> logger, IConfiguration configuration, IPointToInterlockingConnection connection, Func<Task> simulateTimeout)
{
_logger = logger;
_simulateTimeout = simulateTimeout;

var config = configuration.GetSection("PointSettings").Get<PointConfiguration>() ?? throw new Exception("No configuration provided");
if (config.AllPointMachinesCrucial == null)
Expand Down Expand Up @@ -239,7 +241,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
}
else
{
await transitioningTask;
await _simulateTimeout();
UpdatePointState(commandedPointPosition.Value);

await UpdateConnectedWebClients();
Expand Down
6 changes: 5 additions & 1 deletion src/Point/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public void ConfigureServices(IServiceCollection services)

try
{
services.AddSingleton<Point>();
services.AddSingleton<Point>(x =>
{
Func<Task> simulateTimout = async () => await Task.Delay(new Random().Next(1, 5) * 1000);
return new Point(x.GetRequiredService<ILogger<Point>>(), x.GetRequiredService<IConfiguration>(), x.GetRequiredService<IPointToInterlockingConnection>(), simulateTimout);
});
}
catch (Exception e)
{
Expand Down

0 comments on commit bd54513

Please sign in to comment.