Skip to content

FlushAsync doesn't update file contents #959

Closed

Description

@cryocz

Describe the bug
While Flush does update the contents of the file, allowing other streams to read it later, FlushAsync does not.

To Reproduce

var fs = new MockFileSystem();
var file = fs.FileInfo.New("/file");
await using var first = file.OpenWrite();
await first.WriteAsync(new byte[] { 42 });
await first.FlushAsync();

await using var second = file.OpenRead();
var buffer = new byte[1];
Assert.Equal(1, await second.ReadAsync(buffer));
Assert.Equal(42, buffer[0]);

Expected behavior
Behave identically to the synchronous version, which does successfully pass.

var fs = new MockFileSystem();
var file = fs.FileInfo.New("/file");
using var first = file.OpenWrite();
first.Write(new byte[] { 42 });
first.Flush();

using var second = file.OpenRead();
var buffer = new byte[1];
Assert.Equal(1, second.Read(buffer));
Assert.Equal(42, buffer[0]);

Activity

  1. changed the title [-]FlushAsync doesn't update file contents[/-] [+]`FlushAsync` doesn't update file contents[/+] on Mar 10, 2023
  2. fgreinacher commented on Mar 10, 2023

    @fgreinacher
    Contributor

    Thanks for reporting!

    Probably we need to override FlushAsync similar to how we override Flush.

  3. added
    state: ready to pickIssues that are ready for being worked on
    and removed on Mar 10, 2023
  4. cryocz commented on Mar 10, 2023

    @cryocz
    ContributorAuthor

    I'll be submitting a PR for this in just a bit. It should be noted that correctly implementing FlushAsync is more of a band-aid over the fundamental underlying issue: mocked file streams do not share their data buffer. This means that concurrent MockFileStreams, opened on the same file, do not behave like real streams at all.

  5. added a commit that references this issue on Mar 13, 2023
    2b6dba4
  6. github-actions commented on Apr 11, 2023

    @github-actions

    This is addressed in release v19.2.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testinghelpersIssues that address the testing helpersstate: ready to pickIssues that are ready for being worked onstate: releasedIssues that are releasedtype: bugIssues that describe misbehaving functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions