Skip to content

Conversation

csonto
Copy link
Contributor

@csonto csonto commented Apr 6, 2023

Compilation on i686 ends with error:

error[E0308]: mismatched types
   --> src/write_batcher/tests.rs:100:51
    |
100 |     let mut rng = rand::rngs::SmallRng::from_seed([0; 32]);
    |                   ------------------------------- ^^^^^^^ expected an array with a fixed size of 16 elements, found one with 32 elements
    |                   |
    |                   arguments to this function are incorrect
    |

Compilation on i686 ends with error:

    error[E0308]: mismatched types
       --> src/write_batcher/tests.rs:100:51
        |
    100 |     let mut rng = rand::rngs::SmallRng::from_seed([0; 32]);
        |                   ------------------------------- ^^^^^^^ expected an array with a fixed size of 16 elements, found one with 32 elements
        |                   |
        |                   arguments to this function are incorrect
        |
@csonto
Copy link
Contributor Author

csonto commented Apr 6, 2023

This is error from Fedora build system, running tests on 64 bit system in 32 bit chroot.

Not sure this affects other 32 bit platforms, using only x86.

Reported as not reproducible on 64 bit system when building with cargo build --target i686-unknown-linux-gnu, this is not working on my system, can not try with test instead of build

@mingnus
Copy link
Collaborator

mingnus commented Apr 6, 2023

The random seed for SmallRng is 128-bit on 32-bit platforms, and 256-bit on 64-bit platforms (for PRNGs Xoshiro128PlusPlus and Xoshiro256PlusPlus, respectively). I would prefer this way:

diff --git a/src/write_batcher/tests.rs b/src/write_batcher/tests.rs
index 2da65396..85ef7daf 100644
--- a/src/write_batcher/tests.rs
+++ b/src/write_batcher/tests.rs
@@ -96,8 +96,10 @@ fn writes_should_be_performed_in_batch() {
 
 #[test]
 fn write_hit() {
+    type SeedType = <SmallRng as rand::SeedableRng>::Seed;
+
     let mut src = vec![0u8; 4096];
-    let mut rng = rand::rngs::SmallRng::from_seed([0; 32]);
+    let mut rng = SmallRng::from_seed(SeedType::default());
     rng.fill_bytes(&mut src[4..]);
     assert!(checksum::write_checksum(&mut src[..], BT::NODE).is_ok());
@@ -132,8 +134,10 @@ fn write_hit() {
 
 #[test]
 fn read_hit() {
+    type SeedType = <SmallRng as rand::SeedableRng>::Seed;
+
     let mut src = vec![0u8; 4096];
-    let mut rng = rand::rngs::SmallRng::from_seed([0; 32]);
+    let mut rng = SmallRng::from_seed(SeedType::default());
     rng.fill_bytes(&mut src[4..]);
     assert!(checksum::write_checksum(&mut src[..], BT::NODE).is_ok());

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.

2 participants