Skip to content

Commit

Permalink
test: improved test_SQE
Browse files Browse the repository at this point in the history
  • Loading branch information
YoSTEALTH committed Jun 2, 2024
1 parent dfdd19f commit 36fd0f7
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions test/event/sqe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,45 @@


def test_SQE():
print()
shakti.run(
zero_sqe(),
zero_sqes(2),
# zero_sqes(1024), # TODO: segfault, look into it.
with_statement(),
single_sqe(),
multiple_sqes(1000),
with_statement()
)


async def zero_sqe():
async def single_sqe():
sqe = shakti.SQE()
liburing.io_uring_prep_openat(sqe, b'/dev/zero')
await sqe
assert sqe.result > 0
await shakti.close(fd := sqe.result) # fd
assert fd > 0

with pytest.raises(ValueError):
shakti.SQE(1025)


async def zero_sqes(loop):
sqes = shakti.SQE(loop)
async def multiple_sqes(loop):
sqes = shakti.SQE(loop, True)
for i in range(loop):
liburing.io_uring_prep_openat(sqes[i], b'/dev/zero')
await sqes
for i in range(loop):
assert sqes[i].result > 0
await shakti.close(fd := sqes[i].result)
assert fd > 0


async def with_statement():
# single
async with shakti.SQE(error=False) as sqe:
liburing.io_uring_prep_openat(sqe, b'/dev/zero')
assert sqe.result > 0
await shakti.close(fd := sqe.result) # fd
assert fd > 0

# multiple
async with shakti.SQE(2, error=False) as sqe:
liburing.io_uring_prep_openat(sqe, b'/bad-link')
liburing.io_uring_prep_openat(sqe[1], b'/dev/zero')
assert sqe.result == -errno.ENOENT
assert sqe[1].result > 0
await shakti.close(fd := sqe[1].result) # fd
assert fd > 0

0 comments on commit 36fd0f7

Please sign in to comment.