Skip to content

Commit

Permalink
revert(repeater): get rid if same repeater re-deployment
Browse files Browse the repository at this point in the history
This reverts commit 0db1321.
  • Loading branch information
ostridm committed Jun 19, 2024
1 parent ebc050c commit 9d2577c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/SecTester.Repeater/Bus/IRepeaterBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public interface IRepeaterBus : IAsyncDisposable
event Action<Version> UpgradeAvailable;

Task Connect();
Task<string> Deploy(CancellationToken? cancellationToken = null);
Task<string> Deploy(string? repeaterId, CancellationToken? cancellationToken = null);
}
6 changes: 4 additions & 2 deletions src/SecTester.Repeater/Bus/SocketIoRepeaterBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,18 @@ public async ValueTask DisposeAsync()
GC.SuppressFinalize(this);
}

public async Task<string> Deploy(CancellationToken? cancellationToken = null)
public async Task<string> Deploy(string? repeaterId, CancellationToken? cancellationToken = null)
{
try
{
var tcs = new TaskCompletionSource<RepeaterInfo>();

_connection.On("deployed", response => tcs.TrySetResult(response.GetValue<RepeaterInfo>()));

var args = string.IsNullOrWhiteSpace(repeaterId) ? Array.Empty<object>() : new object[] { new RepeaterInfo(repeaterId!) };

await _connection
.EmitAsync("deploy", Array.Empty<object>())
.EmitAsync("deploy", args)
.ConfigureAwait(false);

using var _ = cancellationToken?.Register(() => tcs.TrySetCanceled());
Expand Down
2 changes: 1 addition & 1 deletion src/SecTester.Repeater/Repeater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task Start(CancellationToken cancellationToken = default)
SubscribeToEvents();

await _bus.Connect().ConfigureAwait(false);
RepeaterId = await _bus.Deploy(cancellationToken).ConfigureAwait(false);
RepeaterId = await _bus.Deploy(RepeaterId, cancellationToken).ConfigureAwait(false);

Status = RunningStatus.Running;
}
Expand Down
16 changes: 15 additions & 1 deletion test/SecTester.Repeater.Tests/Bus/SocketIoRepeaterBusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ public async Task Deploy_Success()
await _connection.Received().EmitAsync("deploy", Arg.Is<object[]>(x => x.Length == 0));
}

[Fact]
public async Task Deploy_GivenRepeaterId_Success()
{
// arrange
_socketIoMessage.GetValue<RepeaterInfo>().Returns(new RepeaterInfo(RepeaterId));
_connection.On("deployed", Arg.Invoke(_socketIoMessage));

// act
await _sut.Deploy(RepeaterId);

// assert
await _connection.Received().EmitAsync("deploy", Arg.Is<object[]>(x => x.Length == 1 && ((x[0] as RepeaterInfo)!).RepeaterId == RepeaterId));
}

[Fact]
public async Task Deploy_NotReceivingRepeaterId_ThrowsError()
{
Expand All @@ -182,7 +196,7 @@ public async Task Deploy_GivenCancellationToken_ThrowsError()
cancellationTokenSource.Cancel();

// act
var act = () => _sut.Deploy(cancellationTokenSource.Token);
var act = () => _sut.Deploy(null, cancellationTokenSource.Token);

// assert
await act.Should().ThrowAsync<OperationCanceledException>();
Expand Down
2 changes: 1 addition & 1 deletion test/SecTester.Repeater.Tests/RepeaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Dispose()
public async Task Start_DeploysItself()
{
// arrange
_bus.Deploy(Arg.Any<CancellationToken?>()).Returns(Task.FromResult<string>(Id));
_bus.Deploy(Arg.Any<string?>(), Arg.Any<CancellationToken?>()).Returns(Task.FromResult<string>(Id));

// act
await _sut.Start();
Expand Down

0 comments on commit 9d2577c

Please sign in to comment.