-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7120324
commit 9f2eecb
Showing
61 changed files
with
1,316 additions
and
1,186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,6 +344,3 @@ $RECYCLE.BIN/ | |
.jupyter_ystore.db | ||
.jupyter_ystore.db-journal | ||
fps_cli_args.toml | ||
|
||
# pixi environments | ||
.pixi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import pytest | ||
from anyio import create_task_group, sleep | ||
|
||
from jupyverse_api import ResourceLock | ||
|
||
pytestmark = pytest.mark.anyio | ||
|
||
|
||
async def do_op(operation, resource_lock, operations): | ||
op, path = operation | ||
async with resource_lock(path): | ||
operations.append(operation + ["start"]) | ||
await sleep(0.1) | ||
operations.append(operation + ["done"]) | ||
|
||
|
||
async def test_resource_lock(): | ||
resource_lock = ResourceLock() | ||
|
||
# test concurrent accesses to the same resource | ||
idx = "idx" | ||
operations = [] | ||
async with create_task_group() as tg: | ||
tg.start_soon(do_op, [0, idx], resource_lock, operations) | ||
await sleep(0.01) | ||
tg.start_soon(do_op, [1, idx], resource_lock, operations) | ||
|
||
assert operations == [ | ||
[0, idx, "start"], | ||
[0, idx, "done"], | ||
[1, idx, "start"], | ||
[1, idx, "done"], | ||
] | ||
|
||
# test concurrent accesses to different files | ||
idx0 = "idx0" | ||
idx1 = "idx1" | ||
operations = [] | ||
async with create_task_group() as tg: | ||
tg.start_soon(do_op, [0, idx0], resource_lock, operations) | ||
await sleep(0.01) | ||
tg.start_soon(do_op, [1, idx1], resource_lock, operations) | ||
await sleep(0.01) | ||
tg.start_soon(do_op, [2, idx0], resource_lock, operations) | ||
await sleep(0.01) | ||
tg.start_soon(do_op, [3, idx1], resource_lock, operations) | ||
|
||
assert operations == [ | ||
[0, idx0, "start"], | ||
[1, idx1, "start"], | ||
[0, idx0, "done"], | ||
[2, idx0, "start"], | ||
[1, idx1, "done"], | ||
[3, idx1, "start"], | ||
[2, idx0, "done"], | ||
[3, idx1, "done"], | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.