jonhoo / left-right

A lock-free, read-optimized, concurrency primitive.
Apache License 2.0
1.94k stars 94 forks source link

Added test case for the wait function of write handler. #90

Closed grv07 closed 3 years ago

grv07 commented 3 years ago

This change is Reviewable

grv07 commented 3 years ago

Hello, I have added a test case for the wait function of the write handler.

This test checks a case where one of the readers is still reading and the hander calls the wait fn. I try to simulate the read handle behaviour by creating a new thread that will increase the epoch by one when scheduled. Thanks.

jonhoo commented 3 years ago

Hmm, I don't think this test does quite what you want it to. In particular, the thread that increments may end up running before wait is even called, in which case wait won't wait at all. There isn't really a good way to fix that problem except by creating a loom test to test both interleavings, which I know is something @mlodato517 was looking at a little while back.

grv07 commented 3 years ago

Yes, I understand your point. Apart from loom, do you think park_timeout will be good fit for this problem ?

jonhoo commented 3 years ago

park_timeout could work too! You'd probably want to first park_timeout without the reader allowing the writer to make progress, check that the writer did in fact not make progress, then park, then progress the reader, and then check that the writer was then unblocked.

jonhoo commented 3 years ago

I think we're almost there now!

jonhoo commented 3 years ago

Oh, and if you can merge from master, we should get CI testing and coverage analysis for this PR too!

codecov[bot] commented 3 years ago

Codecov Report

Merging #90 (c15ac06) into master (89d973a) will increase coverage by 5.86%. The diff coverage is 100.00%.

Impacted Files Coverage Δ
src/write.rs 86.25% <100.00%> (+6.86%) :arrow_up:
jonhoo commented 3 years ago

Awesome, thank you for sticking with it!