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

Fix bugs in get() and co + property based tests #88

Merged
merged 5 commits into from
Oct 4, 2023
Merged

Conversation

loyd
Copy link
Contributor

@loyd loyd commented Oct 2, 2023

I've written some fuzzing property based tests for public API. Fortunately (or not), it's found only simple bugs with boundary checks (caught in staging, the reason why I've decided to check the slab in such a way).

P.S. "fuzzing" is not an entirely valid name here. Initially, It checked only the absence of panics, so naming was more appropriate. Then, more properties were added. Would you happen to have any ideas on how to call it now?

@loyd
Copy link
Contributor Author

loyd commented Oct 2, 2023

Oops, it seems that the hashbrown crate moved to newer rustc. Should I downgrade the indexmap or allow CI to build tests with newer rustc?

@loyd loyd changed the title Fix bugs in get() and co + fuzzing tests Fix bugs in get() and co + property based tests Oct 2, 2023
@hawkw
Copy link
Owner

hawkw commented Oct 2, 2023

Thanks for the PR, this is really cool! I have a few minor suggestions, but overall, it's really nice to have this additional testing, so thanks for all your work on this!

In re: your questions:

P.S. "fuzzing" is not an entirely valid name here. Initially, It checked only the absence of panics, so naming was more appropriate. Then, more properties were added. Would you happen to have any ideas on how to call it now?

Honestly, I would probably name it "properties" or something, instead of "fuzzing"...but I'm fine with "fuzzing", too...

Oops, it seems that the hashbrown crate moved to newer rustc. Should I downgrade the indexmap or allow CI to build tests with newer rustc?

It seems pretty unfortunate to bump our MSRV just for a test-only dependency. I'm fine with a dev-dependency on indexmap v1.0, but I'm also okay with changing the CI configuration so that we just build the actual library on MSRV, rather than actually running tests. I wouldn't expect the tested behavior to change based on the Rust version, unless we're deeply unlucky, so just checking that the lib itself compiles for our MSRV is probably fine...

One small, procedural point: we use the Git history to generate this crate's changelog. If you don't mind, it would be really nice if the two bugfixes (the one for UniqueIter and get for random keys) could be pulled out into separate commits from the commit that actually adds the property tests (and ideally, the clippy fix would be a separate commit as well). That way, they will generate separate changelog entries. If you don't have time to do an admittedly kind of annoying rebase, that's fine, but it would be nicer IMO.

Thanks again for working on this!

tests/fuzzing.rs Outdated Show resolved Hide resolved
src/iter.rs Outdated Show resolved Hide resolved
@loyd
Copy link
Contributor Author

loyd commented Oct 3, 2023

If you don't have time to do an admittedly kind of annoying rebase, that's fine, but it would be nicer IMO.

No problem, I'll do it. A good changelog is important.

Fixes several clippy's lints:
* non_canonical_clone_impl
* needless_borrow
Prevents public methods from panicking if received keys that haven't been
produced by the slab.
Fixes panics in `Slab::unique_iter()` in case of an empty slab.

Fixes hawkw#73
@loyd
Copy link
Contributor Author

loyd commented Oct 3, 2023

It seems pretty unfortunate to bump our MSRV just for a test-only dependency.

indexmap is downgraded to the version which supports the current MSRV. However, it seems memory-stats violates MSRV already (failing CI in master).

Also, I updated the commits. Are they good enough for the CHANGELOG generation? Text from my previous PR was added to CHANGELOG. Does it still work the same way (should I also edit my first comment)?

@loyd loyd force-pushed the main branch 2 times, most recently from b1d9126 to 26111f8 Compare October 3, 2023 19:59
Copy link
Owner

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

this looks great, thank you!

i guess we'll have to change the MSRV CI job to be build only, rather than running the tests, because of the memory_stats thing. so, i'm fine with an indexmap v2 dep if you prefer.

Adds property-based tests that check the following properties:
* API never panics.
* Active entries cannot be overridden until removed.
* The slab doesn't produce overlapping keys.
* The slab doesn't leave "lost" keys.
* `get()`, `get_owned`, and `contains()` are consistent.
* `RESERVED_BITS` are actually not used.
@loyd loyd force-pushed the main branch 5 times, most recently from c4701db to 7a70384 Compare October 4, 2023 07:08
* Add `msrv` job
* Add `RUST_BACKTRACE=1`
* Add `-Dwarnings`
* Fix clippy warnings in benches
* Make job naming more consistent
@loyd
Copy link
Contributor Author

loyd commented Oct 4, 2023

@hawkw, I've fixed CI (see the latest commit's message + changes).

Oh, it seems because of renaming the "required checks" logic doesn't work. Should I rename it back?
Also, why is clippy not required?

@hawkw
Copy link
Owner

hawkw commented Oct 4, 2023

Oh, it seems because of renaming the "required checks" logic doesn't work. Should I rename it back?
Also, why is clippy not required?

I'll just fix those in the GitHub settings. Thanks for taking care of it!

@hawkw hawkw merged commit 5495def into hawkw:main Oct 4, 2023
8 checks passed
hawkw pushed a commit that referenced this pull request Oct 4, 2023
Fixes several clippy's lints:
* non_canonical_clone_impl
* needless_borrow
hawkw pushed a commit that referenced this pull request Oct 4, 2023
Prevents public methods from panicking if received keys that haven't been
produced by the slab.
hawkw pushed a commit that referenced this pull request Oct 4, 2023
Fixes panics in `Slab::unique_iter()` in case of an empty slab.

Fixes #73
hawkw pushed a commit that referenced this pull request Oct 4, 2023
Adds property-based tests that check the following properties:
* API never panics.
* Active entries cannot be overridden until removed.
* The slab doesn't produce overlapping keys.
* The slab doesn't leave "lost" keys.
* `get()`, `get_owned`, and `contains()` are consistent.
* `RESERVED_BITS` are actually not used.
hawkw pushed a commit that referenced this pull request Oct 4, 2023
* Add `msrv` job
* Add `RUST_BACKTRACE=1`
* Add `-Dwarnings`
* Fix clippy warnings in benches
* Make job naming more consistent
hawkw added a commit that referenced this pull request Oct 4, 2023
### v0.1.7 (2023-10-04)

#### Bug Fixes

*   index out of bounds in `get()` and `get_owned()` (#88) (fdbc930)
* **unique_iter:**  prevent panics if a slab is empty (#88) (bd599e0,
  closes #73)
@hawkw
Copy link
Owner

hawkw commented Oct 4, 2023

Okay, I just published v0.1.7, which includes the bugfixes. Thank you so much for working on this!

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.

Slab::unique_iter panics when the slab is empty
2 participants