Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public abstract class GroupManager : IGroupManager
public abstract Task AddToGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default);

public abstract Task RemoveFromGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default);

public abstract Task RemoveFromAllGroupsAsync(string connectionId, CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ namespace Microsoft.Azure.SignalR.Management
{
internal class GroupManagerAdapter : GroupManager
{
private readonly IGroupManager _groupManager;
private readonly IHubLifetimeManager _lifetimeManager;

public GroupManagerAdapter(IGroupManager groupManager)
public GroupManagerAdapter(IHubLifetimeManager lifetimeManager)
{
_groupManager = groupManager;
_lifetimeManager = lifetimeManager;
}

public override Task AddToGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default) => _groupManager.AddToGroupAsync(connectionId, groupName, cancellationToken);
public override Task AddToGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default) => _lifetimeManager.AddToGroupAsync(connectionId, groupName, cancellationToken);

public override Task RemoveFromGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default) => _groupManager.RemoveFromGroupAsync(connectionId, groupName, cancellationToken);
public override Task RemoveFromGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default) => _lifetimeManager.RemoveFromGroupAsync(connectionId, groupName, cancellationToken);

public override Task RemoveFromAllGroupsAsync(string connectionId, CancellationToken cancellationToken = default) => _lifetimeManager.RemoveFromAllGroupsAsync(connectionId, cancellationToken);
}
}
2 changes: 2 additions & 0 deletions src/Microsoft.Azure.SignalR.Management/IHubLifetimeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ internal interface IHubLifetimeManager

Task RemoveFromGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default);

Task RemoveFromAllGroupsAsync(string connectionId, CancellationToken cancellationToken = default);

Task SendAllAsync(string methodName, object[] args, CancellationToken cancellationToken = default);

Task SendAllExceptAsync(string methodName, object[] args, IReadOnlyList<string> excludedConnectionIds, CancellationToken cancellationToken = default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ public override async Task RemoveFromGroupAsync(string connectionId, string grou
await _restClient.SendAsync(api, HttpMethod.Delete, _productInfo, handleExpectedResponseAsync: null, cancellationToken: cancellationToken);
}

public async Task ConnectionRemoveFromAllGroupsAsync(string connectionId, CancellationToken cancellationToken = default)
public async Task RemoveFromAllGroupsAsync(string connectionId, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(connectionId))
{
throw new ArgumentException(NullOrEmptyStringErrorMessage, nameof(connectionId));
}

var api = await _restApiProvider.GetRemoveConnectionFromAllGroupsAsync(_appName, _hubName, connectionId);
await _restClient.SendAsync(api, HttpMethod.Delete, _productInfo, handleExpectedResponseAsync: null, cancellationToken: cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ServiceHubContextImpl(string hubName, IHubContext<Hub> hubContext, IServi
{
_hubName = hubName;
_hubContext = hubContext;
Groups = new GroupManagerAdapter(_hubContext.Groups);
Groups = new GroupManagerAdapter(lifetimeManager);
UserGroups = new UserGroupsManagerAdapter(lifetimeManager);
ClientManager = new ClientManagerAdapter(lifetimeManager);
ServiceProvider = serviceProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ServiceHubContextImpl(string hubName, IHubContext<Hub<T>, T> typedHubCont
_negotiateProcessor = negotiateProcessor;
ServiceProvider = serviceProvider;
Clients = typedHubContext.Clients;
Groups = new GroupManagerAdapter(typedHubContext.Groups);
Groups = new GroupManagerAdapter(lifetimeManager);
UserGroups = new UserGroupsManagerAdapter(lifetimeManager);
ClientManager = new ClientManagerAdapter(lifetimeManager);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public WebSocketsHubLifetimeManager(IServiceConnectionManager<THub> serviceConne
_serviceManagerOptions = serviceManagerOptions ?? throw new ArgumentNullException(nameof(serviceManagerOptions));
}

public override Task RemoveFromGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default)
public Task RemoveFromAllGroupsAsync(string connectionId, CancellationToken cancellationToken = default)
{
if (IsInvalidArgument(connectionId))
{
throw new ArgumentException(NullOrEmptyStringErrorMessage, nameof(connectionId));
}

var message = AppendMessageTracingId(new LeaveGroupWithAckMessage(connectionId, groupName));
var message = AppendMessageTracingId(new LeaveGroupWithAckMessage(connectionId, null));
if (message.TracingId != null)
{
MessageLog.StartToRemoveConnectionFromGroup(Logger, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ await RunTestCore(clientEndpoint, clientAccessTokens,
}
}

[ConditionalTheory(Skip = "wait for fixing bug")]
[ConditionalTheory(Skip = "wait for fixing bug of JWT token")]
[SkipIfConnectionStringNotPresent]
[MemberData(nameof(TestData))]
internal async Task RemoveConnectionFromAllGroupsTest(ServiceTransportType serviceTransportType, string appName)
Expand Down Expand Up @@ -354,7 +354,7 @@ internal async Task RemoveConnectionFromAllGroupsTest(ServiceTransportType servi
await Task.Delay(_timeout);
await sendTaskFunc();
await Task.Delay(_timeout);
await ConnectionRemoveFromAllGroupsAsync(serviceHubContext, connectionGroupDict);
await ConnectionRemoveFromAllGroupsAsync((ServiceHubContext)serviceHubContext, connectionGroupDict);
await Task.Delay(_timeout);
await sendTaskFunc();
await Task.Delay(_timeout);
Expand Down Expand Up @@ -383,10 +383,10 @@ await Task.WhenAll(from connection in connections
}
}

private static Task ConnectionRemoveFromAllGroupsAsync(IServiceHubContext serviceHubContext, IDictionary<string, List<string>> connectionGroupDict)
private static Task ConnectionRemoveFromAllGroupsAsync(ServiceHubContext serviceHubContext, IDictionary<string, List<string>> connectionGroupDict)
{
return Task.WhenAll(from connection in connectionGroupDict.Keys
select serviceHubContext.Groups.RemoveFromGroupAsync(connection, null));
select serviceHubContext.Groups.RemoveFromAllGroupsAsync(connection, default));
}

private static Task AddConnectionToGroupAsync(IServiceHubContext serviceHubContext, IDictionary<string, List<string>> connectionGroupDict)
Expand Down