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

cookie doctest failure #57943

Closed
Mark-Simulacrum opened this issue Jan 28, 2019 · 2 comments
Closed

cookie doctest failure #57943

Mark-Simulacrum opened this issue Jan 28, 2019 · 2 comments
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Mark-Simulacrum
Copy link
Member

The cookie crate is failing a doc test on CookieJar::iter: https://crater-reports.s3.amazonaws.com/beta-1.33-1/beta-2019-01-22/reg/cookie-0.11.0/log.txt

I haven't looked into this more but it seems to happen pretty consistently on beta and nightly but I haven't reproduced on stable.

cc @alexcrichton

@Mark-Simulacrum Mark-Simulacrum added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Jan 28, 2019
@ishitatsuyuki ishitatsuyuki changed the title cookie test failure cookie doctest failure Jan 28, 2019
@jonas-schievink
Copy link
Contributor

Failing doctest:

    /// ```rust
    /// use cookie::{CookieJar, Cookie};
    ///
    /// let mut jar = CookieJar::new();
    ///
    /// jar.add_original(Cookie::new("name", "value"));
    /// jar.add_original(Cookie::new("second", "two"));
    ///
    /// jar.add(Cookie::new("new", "third"));
    /// jar.add(Cookie::new("another", "fourth"));
    /// jar.add(Cookie::new("yac", "fifth"));
    ///
    /// jar.remove(Cookie::named("name"));
    /// jar.remove(Cookie::named("another"));
    ///
    /// // There are three cookies in the jar: "second", "new", and "yac".
    /// # assert_eq!(jar.iter().count(), 3);
    /// for cookie in jar.iter() {
    ///     match cookie.name() {
    ///         "second" => assert_eq!(cookie.value(), "two"),
    ///         "new" => assert_eq!(cookie.value(), "third"),
    ///         "yac" => assert_eq!(cookie.value(), "fifth"),
    ///         _ => unreachable!("there are only three cookies in the jar")
    ///     }
    /// }
    /// ```

The assertion assert_eq!(jar.iter().count(), 3); is failing.

@alexcrichton
Copy link
Member

This is an internal bug in cookie due to #57043 fixed by rwf2/cookie-rs#111, although I believe it was accidentally fixed.

This program:

extern crate cookie;

use std::collections::HashSet;

#[derive(Debug)]
struct A<'a>(&'a str, bool);

fn main() {
    let mut a = HashSet::new();
    a.insert(A("name", false));
    a.insert(A("second", false));

    let mut b = HashSet::new();
    b.replace(A("new", false));
    b.replace(A("another", false));
    b.replace(A("yac", false));

    b.replace(A("name", true));
    b.remove(&A("another", false));

    println!("{:?}", b.union(&a).collect::<Vec<_>>());
    println!("{:?}", b.iter().chain(a.difference(&b)).collect::<Vec<_>>());
}

impl<'a> std::hash::Hash for A<'a> {
    fn hash<H: std::hash::Hasher>(&self, h: &mut H) {
        self.0.hash(h);
    }
}

impl<'a> PartialEq for A<'a> {
    fn eq(&self, other: &A<'a>) -> bool {
        self.0 == other.0
    }
}

impl<'a> Eq for A<'a> {
}

has different output on stable/beta because of #57043. Both outputs are, however, correct. The cookie crate uses a data structure that only hashes one field (the name) but has other relevant information in the fields such as whether a cookie was removed and such. Depending on the order of iteration a cookie is either flagged as removed or filtered out from iteration.

tl;dr; everything is working as expected, this is a bug in the cookie crate that has already been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants