Repository: dotnet/aspnetcore
File: src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs (C#)

Code before:
        await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);

        AssertConnectionNoError();
    }

    [Fact]
    public async Task RST_STREAM_IncompleteRequest_AdditionalWindowUpdateFrame_ConnectionAborted()
    {
        var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

        var headers = new[]
        {
            new KeyValuePair<string, string>(InternalHeaderNames.Method, "POST"),
            new KeyValuePair<string, string>(InternalHeaderNames.Path, "/"),
            new KeyValuePair<string, string>(InternalHeaderNames.Scheme, "http"),
        };
        await InitializeConnectionAsync(context => tcs.Task);

        await StartStreamAsync(1, headers, endStream: false);
        await SendDataAsync(1, new byte[1], endStream: false);
        await SendRstStreamAsync(1);
        await SendWindowUpdateAsync(1, 1024);

        await WaitForStreamErrorAsync(expectedStreamId: 1, Http2ErrorCode.STREAM_CLOSED, CoreStrings.Http2StreamAborted);

        tcs.TrySetResult(); // Don't let the response start until after the abort
    }

    [Fact]
    public async Task SETTINGS_KestrelDefaults_Sent()
    {
        CreateConnection();

        _connectionTask = _connection.ProcessRequestsAsync(new DummyApplication(_noopApplication));

        await SendPreambleAsync().ConfigureAwait(false);
        await SendSettingsAsync();

        var frame = await ExpectAsync(Http2FrameType.SETTINGS,
            withLength: Http2FrameReader.SettingSize * 4,
            withFlags: 0,
            withStreamId: 0);

        // Only non protocol defaults are sent
        var settings = Http2FrameReader.ReadSettings(frame.PayloadSequence);
        Assert.Equal(4, settings.Count);

        var setting = settings[0];
        Assert.Equal(Http2SettingsParameter.SETTINGS_MAX_CONCURRENT_STREAMS, setting.Parameter);
        Assert.Equal(100u, setting.Value);


Review comment (suggestion):
Nice that we already had a test for this. Now that this isn't a connection error, I think we should assert we can close the connection gracefully.


```suggestion
        tcs.TrySetResult(); // Don't let the response start until after the abort

        await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);

        AssertConnectionNoError();
```

Code after:
        await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);

        AssertConnectionNoError();
    }

    [Fact]
    public async Task RST_STREAM_IncompleteRequest_AdditionalWindowUpdateFrame_ConnectionAborted()
    {
        var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

        var headers = new[]
        {
            new KeyValuePair<string, string>(InternalHeaderNames.Method, "POST"),
            new KeyValuePair<string, string>(InternalHeaderNames.Path, "/"),
            new KeyValuePair<string, string>(InternalHeaderNames.Scheme, "http"),
        };
        await InitializeConnectionAsync(context => tcs.Task);

        await StartStreamAsync(1, headers, endStream: false);
        await SendDataAsync(1, new byte[1], endStream: false);
        await SendRstStreamAsync(1);
        await SendWindowUpdateAsync(1, 1024);

        await WaitForStreamErrorAsync(expectedStreamId: 1, Http2ErrorCode.STREAM_CLOSED, CoreStrings.Http2StreamAborted);

        tcs.TrySetResult(); // Don't let the response start until after the abort

        await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);
        AssertConnectionNoError();
    }

    [Fact]
    public async Task SETTINGS_KestrelDefaults_Sent()
    {
        CreateConnection();

        _connectionTask = _connection.ProcessRequestsAsync(new DummyApplication(_noopApplication));

        await SendPreambleAsync().ConfigureAwait(false);
        await SendSettingsAsync();

        var frame = await ExpectAsync(Http2FrameType.SETTINGS,
            withLength: Http2FrameReader.SettingSize * 4,
            withFlags: 0,
            withStreamId: 0);

        // Only non protocol defaults are sent
        var settings = Http2FrameReader.ReadSettings(frame.PayloadSequence);
        Assert.Equal(4, settings.Count);

        var setting = settings[0];