public async Task TestContainerWithOneEndpointWithAllDisconnectedAndWriteMessageSucceedWithWarning() { using (StartVerifiableLog(out var loggerFactory, LogLevel.Warning, logChecker: logs => { var warns = logs.Where(s => s.Write.LogLevel == LogLevel.Warning).ToList(); Assert.Single(warns); Assert.Contains(warns, s => s.Write.Message.Contains(string.Format(MultiEndpointServiceConnectionContainer.Log.FailedWritingMessageToEndpointTemplate, "JoinGroupWithAckMessage", "(null)", "(Primary)http://url1"))); return(true); })) { var sem = new TestServiceEndpointManager(new ServiceEndpoint(ConnectionString1)); var router = new DefaultEndpointRouter(); var container = new TestMultiEndpointServiceConnectionContainer("hub", e => new TestBaseServiceConnectionContainer(new List <IServiceConnection> { new TestServiceConnection(ServiceConnectionStatus.Disconnected), new TestServiceConnection(ServiceConnectionStatus.Disconnected), new TestServiceConnection(ServiceConnectionStatus.Disconnected), new TestServiceConnection(ServiceConnectionStatus.Disconnected), new TestServiceConnection(ServiceConnectionStatus.Disconnected), new TestServiceConnection(ServiceConnectionStatus.Disconnected), new TestServiceConnection(ServiceConnectionStatus.Disconnected), }, e), sem, router, loggerFactory); _ = container.StartAsync(); await container.ConnectionInitializedTask.OrTimeout(); await container.WriteAsync(DefaultGroupMessage); } }
public async Task TestRunAzureSignalRWithDefaultRouterNegotiateWithFallback() { using (StartVerifiableLog(out var loggerFactory, LogLevel.Warning, expectedErrors: e => true, logChecker: s => { Assert.Equal(4, s.Count); Assert.True(s.All(ss => ss.Write.EventId.Name == "EndpointOffline")); Assert.Contains("Hub 'AzureSignalRTest' is now disconnected from '[tt3](Primary)http://localhost3'. Please check log for detailed info.", s.Select(ss => ss.Write.Message)); Assert.Contains("Hub 'AzureSignalRTest' is now disconnected from '[tt4](Secondary)http://localhost4'. Please check log for detailed info.", s.Select(ss => ss.Write.Message)); Assert.Contains("Hub 'chat' is now disconnected from '[tt3](Primary)http://localhost3'. Please check log for detailed info.", s.Select(ss => ss.Write.Message)); Assert.Contains("Hub 'chat' is now disconnected from '[tt4](Secondary)http://localhost4'. Please check log for detailed info.", s.Select(ss => ss.Write.Message)); return(true); })) { // Prepare the configuration var hubConfig = Utility.GetTestHubConfig(loggerFactory, "chat"); hubConfig.Resolver.Register(typeof(ILoggerFactory), () => loggerFactory); var router = new DefaultEndpointRouter(); hubConfig.Resolver.Register(typeof(IEndpointRouter), () => router); var scf = new TestServiceConnectionFactory(endpoint => { var status = endpoint.Name == "es" ? ServiceConnectionStatus.Connected : ServiceConnectionStatus.Disconnected; return(new TestServiceConnection(status)); }); hubConfig.Resolver.Register(typeof(IServiceConnectionFactory), () => scf); using (WebApp.Start(ServiceUrl, app => app.RunAzureSignalR(AppName, hubConfig, options => { options.Endpoints = new ServiceEndpoint[] { new ServiceEndpoint(ConnectionString2, EndpointType.Secondary, "es"), new ServiceEndpoint(ConnectionString3, name: "tt3"), new ServiceEndpoint(ConnectionString4, name: "tt4", type: EndpointType.Secondary), }; }))) { var connection = hubConfig.Resolver.GetService(typeof(IServiceConnectionManager)) as ServiceConnectionManager; Assert.NotNull(connection); // wait for service connections to connect or disconnect await connection.ConnectionInitializedTask.OrTimeout(); var client = new HttpClient { BaseAddress = new Uri(ServiceUrl) }; var response = await client.GetAsync("/negotiate"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); var message = await response.Content.ReadAsStringAsync(); var responseObject = JsonConvert.DeserializeObject <ResponseMessage>(message); Assert.Equal("2.0", responseObject.ProtocolVersion); // The default router fallbacks to the secondary Assert.Equal("http://localhost2/aspnetclient", responseObject.RedirectUrl); } } }
public async Task TestRunAzureSignalRWithDefaultRouterNegotiateWithFallback() { using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug)) { // Prepare the configuration var hubConfig = Utility.GetTestHubConfig(loggerFactory); hubConfig.Resolver.Register(typeof(ILoggerFactory), () => loggerFactory); var router = new DefaultEndpointRouter(); hubConfig.Resolver.Register(typeof(IEndpointRouter), () => router); using (WebApp.Start(ServiceUrl, app => app.RunAzureSignalR(AppName, hubConfig, options => { options.Endpoints = new ServiceEndpoint[] { new ServiceEndpoint(ConnectionString2, EndpointType.Secondary), new ServiceEndpoint(ConnectionString3) { Connection = new TestServiceConnectionContainer(ServiceConnectionStatus.Disconnected) }, new ServiceEndpoint(ConnectionString4) { Connection = new TestServiceConnectionContainer(ServiceConnectionStatus.Disconnected) }, }; }))) { var client = new HttpClient { BaseAddress = new Uri(ServiceUrl) }; var response = await client.GetAsync("/negotiate"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); var message = await response.Content.ReadAsStringAsync(); var responseObject = JsonConvert.DeserializeObject <ResponseMessage>(message); Assert.Equal("2.0", responseObject.ProtocolVersion); // The default router fallbacks to the secondary Assert.Equal("http://localhost2/aspnetclient", responseObject.RedirectUrl); } } }
public async Task TestContainerWithOneEndpointWithAllConnectedSucceeeds() { var sem = new TestServiceEndpointManager(new ServiceEndpoint(ConnectionString1)); var router = new DefaultEndpointRouter(); var container = new TestMultiEndpointServiceConnectionContainer("hub", e => new TestBaseServiceConnectionContainer(new List <IServiceConnection> { new TestServiceConnection(), new TestServiceConnection(), new TestServiceConnection(), new TestServiceConnection(), new TestServiceConnection(), new TestServiceConnection(), new TestServiceConnection(), }, e), sem, router, NullLoggerFactory.Instance); _ = container.StartAsync(); await container.ConnectionInitializedTask.OrTimeout(); await container.WriteAsync(DefaultGroupMessage); }