public async Task TestServiceConnectionForMigratedIn()
        {
            var factory    = new TestClientConnectionFactory();
            var connection = MockServiceConnection(null, factory);

            // create a connection with migration header.
            await connection.OnClientConnectedAsyncForTest(new OpenConnectionMessage("foo", new Claim[0])
            {
                Headers = new Dictionary <string, StringValues> {
                    { Constants.AsrsMigrateFrom, "another-server" }
                }
            });

            Assert.Equal(1, factory.Connections.Count);
            var context = factory.Connections[0];

            Assert.True(context.IsMigrated);

            var message = new AspNetCore.SignalR.Protocol.HandshakeResponseMessage("");

            HandshakeProtocol.WriteResponseMessage(message, context.Transport.Output);
            await context.Transport.Output.FlushAsync();

            var task = context.Transport.Input.ReadAsync();
            await Task.Delay(100);

            // nothing should be written into the transport
            Assert.False(task.IsCompleted);
            Assert.True(context.IsMigrated);

            var feature = context.Features.Get <IConnectionMigrationFeature>();

            Assert.NotNull(feature);
            Assert.Equal("another-server", feature.MigrateFrom);
        }
Example #2
0
        public async void ServiceConnectionShouldIgnoreFirstHandshakeResponse()
        {
            var factory    = new TestClientConnectionFactory();
            var connection = MockServiceConnection(null, factory);

            // create a connection with migration header.
            await connection.OnClientConnectedAsyncForTest(new OpenConnectionMessage("foo", new Claim[0])
            {
                Headers = new Dictionary <string, StringValues> {
                    { Constants.AsrsMigrateIn, "another-server" }
                }
            });

            Assert.Equal(1, factory.Connections.Count);
            var context = factory.Connections[0];

            Assert.True(context.IsMigrated);

            var message = new AspNetCore.SignalR.Protocol.HandshakeResponseMessage("");

            HandshakeProtocol.WriteResponseMessage(message, context.Transport.Output);
            await context.Transport.Output.FlushAsync();

            var task = context.Transport.Input.ReadAsync();
            await Task.Delay(100);

            // nothing should be written into the transport
            Assert.False(task.IsCompleted);
            // but the `migrated` status should remain False (readonly)
            Assert.True(context.IsMigrated);
        }