public async Task ReadsAndWritesAfterReset() { var source = new byte[] { 1, 2, 3 }; await _pipe.Writer.WriteAsync(source); var result = await _pipe.Reader.ReadAsync(); Assert.Equal(source, result.Buffer.ToArray()); _pipe.Reader.Advance(result.Buffer.End); _pipe.Reader.Complete(); _pipe.Writer.Complete(); _pipe.Reset(); await _pipe.Writer.WriteAsync(source); result = await _pipe.Reader.ReadAsync(); Assert.Equal(source, result.Buffer.ToArray()); _pipe.Reader.Advance(result.Buffer.End); }
public void OnWriterCompletedIsDetachedDuringReset() { var callbackRan = false; var scheduler = new TestScheduler(); var pipe = new ResetablePipe(new PipeOptions(_pool, readerScheduler: scheduler)); pipe.Reader.OnWriterCompleted((exception, state) => { callbackRan = true; }, null); pipe.Reader.Complete(); pipe.Writer.Complete(); pipe.Reset(); Assert.True(callbackRan); callbackRan = false; pipe.Reader.Complete(); pipe.Writer.Complete(); Assert.Equal(1, scheduler.CallCount); Assert.False(callbackRan); }