From 794b0c2a9e83ee098a294c1b7e67ce580ccc2fb2 Mon Sep 17 00:00:00 2001 From: Brennan Date: Mon, 20 May 2024 03:21:14 -0700 Subject: [PATCH] Fix flaky Json+Pipe test (#102412) --- .../Serialization/Pipe.WriteTests.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Pipe.WriteTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Pipe.WriteTests.cs index 6bd7a765e3829..7e2a9502df973 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Pipe.WriteTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Pipe.WriteTests.cs @@ -4,7 +4,6 @@ using System.Buffers; using System.Collections.Generic; using System.IO.Pipelines; -using System.Runtime.CompilerServices; using System.Text.Json.Serialization.Metadata; using System.Threading; using System.Threading.Tasks; @@ -56,6 +55,7 @@ public async Task CompletedPipeThrowsFromSerialize() [Fact] public async Task CancelPendingFlushDuringBackpressureThrows() { + int i = 0; Pipe pipe = new Pipe(new PipeOptions(pauseWriterThreshold: 10, resumeWriterThreshold: 5)); await pipe.Writer.WriteAsync("123456789"u8.ToArray()); Task serializeTask = JsonSerializer.SerializeAsync(pipe.Writer, GetNumbersAsync()); @@ -68,13 +68,12 @@ public async Task CancelPendingFlushDuringBackpressureThrows() ReadResult result = await pipe.Reader.ReadAsync(); // Technically this check is not needed, but helps confirm behavior, that Pipe had written but was waiting for flush to continue. - // result.Buffer: 123456789[0 - Assert.Equal(11, result.Buffer.Length); + // result.Buffer: 123456789[0... + Assert.Equal(10 + i - 1, result.Buffer.Length); pipe.Reader.AdvanceTo(result.Buffer.End); - static async IAsyncEnumerable GetNumbersAsync() + async IAsyncEnumerable GetNumbersAsync() { - int i = 0; while (true) { await Task.Delay(10);