-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
implement array_shuffle #4220
implement array_shuffle #4220
Conversation
c81aa7c
to
5b53bb1
Compare
Seems like the CI job fails as we use a Postgres version for our tests that does not support |
/// let shuffled = diesel::select(array_shuffle::<Array<Integer>, _>(vec![1, 2, 3, 4, 5])) | ||
/// .get_result::<Vec<i32>>(connection)?; | ||
/// assert_eq!(5, shuffled.len()); | ||
/// assert!(shuffled != vec![1, 2, 3, 4, 5]); // It's very unlikely to get the same order |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously this test will fail in just under 1% of runs, when the shuffle happens to do nothing. I'm a bit uncomfortable about this - one test like this might be fine, but if we set a precedent and we had many tests like this our suite will become flaky and "just rerun the suite" will become a common approach rather than digging into the problem.
@weiznich please let me know if you think I'm being overcautious.
A simple alternative would be
println!("{:?}", shuffled); // e.g., `[3, 2, 5, 1, 4]`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can set bits corresponding to numbers in vec and check that the result is 31.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, or sort the result in Rust and compare with the sorted array.
I had another look at this and I think the best way forward for now is to mark this test as |
5b53bb1
to
26cc45a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just changed the test to no_run
, otherwise this looks good to me. Thanks for working on this 👍
Implemented
array_shuffle
function for postgres under #4153