Skip to content

Commit

Permalink
Fix flaky Json+Pipe test (#102412)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanConroy authored May 20, 2024
1 parent 8fcadc6 commit 794b0c2
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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<int> GetNumbersAsync()
async IAsyncEnumerable<int> GetNumbersAsync()
{
int i = 0;
while (true)
{
await Task.Delay(10);
Expand Down

0 comments on commit 794b0c2

Please sign in to comment.