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

Intermittent test failure for intervals_match_pg_values_f64 testcase #3429

Open
3 tasks done
czotomo opened this issue Nov 23, 2022 · 5 comments
Open
3 tasks done

Intermittent test failure for intervals_match_pg_values_f64 testcase #3429

czotomo opened this issue Nov 23, 2022 · 5 comments
Labels

Comments

@czotomo
Copy link
Contributor

czotomo commented Nov 23, 2022

Setup

Versions

  • Rust: 1.60
  • Diesel: master branch
  • Database: doesn't matter
  • Operating System Ubuntu 20 @ WSL

Problem Description

Every now and then, while running tests, I will get a panic in this function

thread 'pg::expression::extensions::interval_dsl::tests::intervals_match_pg_values_f64' panicked at '[quickcheck] TEST FAILED. Arguments: (29757356.223255634)', /home/tomo/.cargo/registry/src/github.com-1ecc6299db9ec823/quickcheck-1.0.3/src/tester.rs:165:28`

What are you trying to accomplish?

Run tests - bin/test

Checklist

  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • This issue can be reproduced without requiring a third party crate

I can get this test to pass by rerunning the test script (sometimes it takes few tries to get it to work).
I have zero idea what might be the case.
FWIW this also shows up on a Macbook Pro @ Ventura MacOS with same Rust + Diesel version combo.

@czotomo czotomo added the tests label Nov 23, 2022
@weiznich
Copy link
Member

That's one of the "fuzzing" tests. For reference:

fn intervals_match_pg_values_f64() {

These are hard to debug. It would be helpful to investigate which of test calls causes the problem. After that we should be able to reproduce this by using the printed value + the test code behind the macro. Can you try to get these informations

@czotomo
Copy link
Contributor Author

czotomo commented Nov 24, 2022

I'll see what I can do!

@czotomo
Copy link
Contributor Author

czotomo commented Jan 21, 2023

@weiznich apologies for the delay
It seems it's only test_years function that fails, examples of values from quickcheck's panic:
(21634.64816430318)
(11.708915433687343)
(-5.152681370545959)
(842030.0574014463)
(313684.5795225026)
(81.90706702184103)

@weiznich
Copy link
Member

@czotomo Thanks for providing these values. I will try to have a look at that.

@clouds56
Copy link
Contributor

let val = -705.0759657500337; // or std::mem::transmute(13872785166456217622u64)
test_years(val); // this would fail
let value = val.years(); // PgInterval { microseconds: 0, days: 0, months: -8460 }
let sql_str = format!("'{} years'::interval", val); // PgInterval { microseconds: 0, days: 0, months: -8461 }

And I've tried select '-705.0759657500337 years'::interval; on my postgres it shows

      interval      
--------------------
 -705 years -1 mons
(1 row)

According to docs for postgres 16, the fraction part should be rounded instead of trunced.

Fractional parts of units greater than months are rounded to be an integer number of months, e.g. '1.5 years' becomes '1 year 6 mons'.

I've tried patch it with round and the test seems passed.

fn years(self) -> PgInterval {
((self * 12.0).trunc() as i32).months()
}

    fn years(self) -> PgInterval {
        ((self * 12.0).round() as i32).months()
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants