Skip to content

Commit 48bd44f

Browse files
committed
connection reroute test cases
1 parent 3cbbbcb commit 48bd44f

File tree

46 files changed

+1105
-1697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1105
-1697
lines changed

.editorconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ csharp_new_line_before_members_in_object_initializers = true
5151
csharp_new_line_before_members_in_anonymous_types = true
5252

5353
# Namespace settings
54-
csharp_style_namespace_declarations = file_scoped:silent
54+
csharp_style_namespace_declarations = file_scoped:error
5555

5656
# Brace settings
5757
csharp_prefer_braces = true:silent# Prefer curly braces even for one line of code
@@ -102,6 +102,7 @@ csharp_prefer_simple_default_expression = true:suggestion
102102
csharp_style_prefer_local_over_anonymous_function = true:suggestion
103103
csharp_style_prefer_index_operator = true:suggestion
104104
csharp_style_prefer_range_operator = true:suggestion
105+
csharp_space_around_binary_operators = before_and_after
105106

106107
[*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}]
107108
indent_size = 2

samples/ChatSample/ChatSample.Net70/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
14
using ClientResultSample;
5+
26
using Microsoft.AspNetCore.SignalR;
37

48
var builder = WebApplication.CreateBuilder(args);

src/Microsoft.Azure.SignalR.AspNet/ServerConnections/ServiceConnection.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
@@ -10,6 +10,7 @@
1010
using System.Text;
1111
using System.Threading;
1212
using System.Threading.Tasks;
13+
1314
using Microsoft.AspNetCore.Connections;
1415
using Microsoft.Azure.SignalR.Protocol;
1516
using Microsoft.Extensions.Logging;
@@ -21,13 +22,13 @@ internal partial class ServiceConnection : ServiceConnectionBase
2122
{
2223
private const string ReconnectMessage = "asrs:reconnect";
2324

24-
private static readonly Dictionary<string, string> CustomHeader = new Dictionary<string, string>
25-
{{Constants.AsrsUserAgent, ProductInfo.GetProductInfo()}};
25+
private static readonly Dictionary<string, string> CustomHeader = new() {
26+
{Constants.AsrsUserAgent, ProductInfo.GetProductInfo()}
27+
};
2628

2729
private static readonly TimeSpan CloseApplicationTimeout = TimeSpan.FromSeconds(5);
2830

29-
private readonly ConcurrentDictionary<string, ClientConnectionContext> _clientConnections =
30-
new ConcurrentDictionary<string, ClientConnectionContext>(StringComparer.Ordinal);
31+
private readonly ConcurrentDictionary<string, ClientConnectionContext> _clientConnections = new(StringComparer.Ordinal);
3132

3233
private readonly IConnectionFactory _connectionFactory;
3334

@@ -75,6 +76,11 @@ public override bool TryRemoveClientConnection(string connectionId, out IClientC
7576
return r;
7677
}
7778

79+
public override Task CloseClientConnections(CancellationToken token)
80+
{
81+
throw new NotSupportedException();
82+
}
83+
7884
protected override Task<ConnectionContext> CreateConnection(string target = null)
7985
{
8086
return _connectionFactory.ConnectAsync(HubEndpoint, TransferFormat.Binary, ConnectionId, target,
@@ -97,11 +103,6 @@ protected override Task CleanupClientConnections(string fromInstanceId = null)
97103
return Task.CompletedTask;
98104
}
99105

100-
public override Task CloseClientConnections(CancellationToken token)
101-
{
102-
throw new NotSupportedException();
103-
}
104-
105106
protected override Task OnClientConnectedAsync(OpenConnectionMessage openConnectionMessage)
106107
{
107108
// Create empty transport with only channel for async processing messages

src/Microsoft.Azure.SignalR.Common/ClientInvocation/DummyClientInvocationManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
@@ -8,13 +8,14 @@ namespace Microsoft.Azure.SignalR
88
internal sealed class DummyClientInvocationManager : IClientInvocationManager
99
{
1010
public ICallerClientResultsManager Caller => throw new NotSupportedException();
11+
1112
public IRoutedClientResultsManager Router => throw new NotSupportedException();
1213

1314
public DummyClientInvocationManager()
1415
{
1516
}
1617

17-
public void CleanupInvocationsByConnection(string connectionId) => throw new NotSupportedException();
18+
public void CleanupInvocationsByConnection(string connectionId) { }
1819

1920
public bool TryGetInvocationReturnType(string invocationId, out Type type) => throw new NotSupportedException();
2021
}

src/Microsoft.Azure.SignalR.Common/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@ public static class HttpClientNames
167167

168168
public const string InternalDefault = "InternalDefault";
169169
}
170-
}
170+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Collections.Generic;
5+
6+
namespace Microsoft.Azure.SignalR;
7+
8+
internal class DefaultHeaderProvider : ICustomHeaderProvider
9+
{
10+
public IEnumerable<(string key, string val)> Headers => [];
11+
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
55

6-
namespace Microsoft.Azure.SignalR
6+
namespace Microsoft.Azure.SignalR;
7+
8+
internal class DefaultServerNameProvider : IServerNameProvider
79
{
8-
internal class DefaultServerNameProvider : IServerNameProvider
10+
private readonly string _name = $"{Environment.MachineName}_{Guid.NewGuid():N}";
11+
12+
public string GetName()
913
{
10-
private readonly string _name = $"{Environment.MachineName}_{Guid.NewGuid():N}";
11-
public string GetName()
12-
{
13-
return _name;
14-
}
14+
return _name;
1515
}
1616
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Collections.Generic;
5+
6+
namespace Microsoft.Azure.SignalR;
7+
8+
internal interface ICustomHeaderProvider
9+
{
10+
IEnumerable<(string key, string val)> Headers { get; }
11+
}

src/Microsoft.Azure.SignalR.Common/Microsoft.Azure.SignalR.Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<IsPackable>false</IsPackable>
5-
<LangVersion>11</LangVersion>
5+
<LangVersion>12.0</LangVersion>
66
</PropertyGroup>
77

88
<PropertyGroup>

src/Microsoft.Azure.SignalR.Common/ServiceConnections/ConnectionFactory.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
55
using System.Collections.Generic;
66
using System.Net;
77
using System.Threading;
88
using System.Threading.Tasks;
9+
910
using Microsoft.AspNetCore.Connections;
1011
using Microsoft.Extensions.Logging;
1112

1213
namespace Microsoft.Azure.SignalR;
1314

14-
internal class ConnectionFactory : IConnectionFactory
15+
internal class ConnectionFactory(IServerNameProvider nameProvider,
16+
ILoggerFactory loggerFactory) : IConnectionFactory
1517
{
16-
private readonly ILoggerFactory _loggerFactory;
17-
18-
private readonly string _serverId;
18+
private readonly ILoggerFactory _loggerFactory = loggerFactory != null ? new GracefulLoggerFactory(loggerFactory) : throw new ArgumentNullException(nameof(loggerFactory));
1919

20-
public ConnectionFactory(IServerNameProvider nameProvider, ILoggerFactory loggerFactory)
21-
{
22-
_loggerFactory = loggerFactory != null ? new GracefulLoggerFactory(loggerFactory) : throw new ArgumentNullException(nameof(loggerFactory));
23-
_serverId = nameProvider?.GetName();
24-
}
20+
private readonly string _serverId = nameProvider?.GetName();
2521

2622
public async Task<ConnectionContext> ConnectAsync(HubServiceEndpoint hubServiceEndpoint,
2723
TransferFormat transferFormat,

0 commit comments

Comments
 (0)