Skip to content

MemMapFS: missing files after write multi files in concurrency #361

@sko00o

Description

@sko00o

I have used afero.MemMapFs for filesystem mock test in my projects.
But I got some unexpected test results.

I want to list all files in target directory that I have wrote multi files in concurrency before.
Occasionally some files are not returned by Readdir function. Also I had the same problem calling Walk function on this directory.

Here is a test to reproduce my problem. https://github.com/sko00o/afero-test/blob/main/memmap/memmap_test.go#L42

failure result:

❯ go test -race -run ^TestListFilesAfterConcurrencyFileWrite$ ./... -test.count 1
--- FAIL: TestListFilesAfterConcurrencyFileWrite (4.39s)
    memmap_test.go:99: 
                Error Trace:    memmap_test.go:99
                Error:          Not equal: 
                                expected: 10000
                                actual  : 9995
                Test:           TestListFilesAfterConcurrencyFileWrite
                Messages:       missing files
FAIL
FAIL    github.com/sko00o/afero-test/memmap     4.677s
FAIL

I notice another issue #298 that found MemMapFs.Mkdir have problem when call in concurrency.
In my opinion, we need a double check here before we create new directory.


So I send a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions