Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulate file locks in blockio-sim #415

Merged
merged 2 commits into from
Oct 7, 2024
Merged

Conversation

jorisdral
Copy link
Collaborator

@jorisdral jorisdral commented Oct 3, 2024

What's neat is that we can now find out in our StateMachine tests whether our implementation is leaking file descriptors!

@jorisdral jorisdral self-assigned this Oct 3, 2024
@jorisdral jorisdral force-pushed the jdral/blockio-sim-filelock branch 3 times, most recently from 3e19457 to 63d7868 Compare October 4, 2024 12:43
Copy link
Collaborator Author

@jorisdral jorisdral left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcoutts looks great

blockio-sim/src/System/FS/BlockIO/Sim.hs Outdated Show resolved Hide resolved
blockio-sim/src/System/FS/BlockIO/Sim.hs Outdated Show resolved Hide resolved
Comment on lines 44 to 50
-- Warning: This implementation is not robust under concurrent use (because
-- operations on files are not atomic) but should be ok for casual use. A
-- proper implementation would need to be part of the underlying 'HasFs'
-- implementations.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

blockio-sim/src/System/FS/BlockIO/Sim.hs Outdated Show resolved Hide resolved
blockio-sim/src/System/FS/BlockIO/Sim.hs Outdated Show resolved Hide resolved
blockio-sim/src/System/FS/BlockIO/Sim.hs Outdated Show resolved Hide resolved
@jorisdral jorisdral marked this pull request as ready for review October 4, 2024 15:09
jorisdral and others added 2 commits October 7, 2024 11:16
It's an adequate implementation, but not perfect. It passes the test, but would
fail if there were genuine concurrency. Doing it properly would need an
implementation in fs-api and fs-sim. Fortunately we do not need a concurrency
safe implementation (for now).

Co-authored-by: Duncan Coutts <duncan@well-typed.com>
Co-authored-by: Joris Dral <joris@welltyped.com>
With the nice addition that we now assert that there are no open file handles at
the end of each iteration of the tests!

We also tweak the state machine tests. We now follow a more normal convention,
and allow running individual tests more easily in GHCi via `quickCheck $
theProperty`.

Co-authored-by: Duncan Coutts <duncan@well-typed.com>
Co-authored-by: Joris Dral <joris@welltyped.com>
Copy link
Collaborator

@dcoutts dcoutts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

-- Warning: regular file operations on the "locked" file, like 'hOpen' or
-- 'removeFile', will still work. 'simTryLockFile' only defines how multiple
-- lock acquisitions on the same file interact, not how lock acquisition
-- interacts with other file operations.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same is true for the normal API too.

@dcoutts dcoutts added this pull request to the merge queue Oct 7, 2024
Merged via the queue into main with commit f48a126 Oct 7, 2024
24 checks passed
@dcoutts dcoutts deleted the jdral/blockio-sim-filelock branch October 7, 2024 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants