Sometimes links are not entered into the cache #9

Closed
opened 7 months ago by KMK · 1 comments
KMK commented 7 months ago

Here is a test case

#[test]
fn test_save_cached_links_alway_caches() {
    let cache = web::Data::new(Mutex::new(Vec::<Link>::new()));
    let mut l = Link {
        id: 0,
        url_from: "0".into(),
        url_to: "foo".into(),
        key: Vec::new(),
        time: Utc::now().naive_utc(),
        clicks: 0,
        phishing: 0
    };
    while l.id <= u64::from(CONFIG.general.max_cache_size) {
        assert!(
            check_cached_links(&l.url_from, &cache).is_none(),
            "Link not yet cached #{}", l.id
        );
        save_cached_links(l.clone(), &cache);
        let cached_link = check_cached_links(&l.url_from, &cache);
        assert!(
            cached_link.is_some(),
            "link cached #{}", l.id
        );
        let cached_link = cached_link.unwrap();
        assert_eq!(
            (cached_link.id, &cached_link.url_from),
            (l.id, &l.url_from)
        );
        l.id += 1;
        l.url_from = format!("{}", l.id);
    }
}
Here is a test case #[test] fn test_save_cached_links_alway_caches() { let cache = web::Data::new(Mutex::new(Vec::<Link>::new())); let mut l = Link { id: 0, url_from: "0".into(), url_to: "foo".into(), key: Vec::new(), time: Utc::now().naive_utc(), clicks: 0, phishing: 0 }; while l.id <= u64::from(CONFIG.general.max_cache_size) { assert!( check_cached_links(&l.url_from, &cache).is_none(), "Link not yet cached #{}", l.id ); save_cached_links(l.clone(), &cache); let cached_link = check_cached_links(&l.url_from, &cache); assert!( cached_link.is_some(), "link cached #{}", l.id ); let cached_link = cached_link.unwrap(); assert_eq!( (cached_link.id, &cached_link.url_from), (l.id, &l.url_from) ); l.id += 1; l.url_from = format!("{}", l.id); } }
Owner

Thanks for reporting. I misunderstood the Vec::drain() function, I'm working on a fix. Thanks for providing the unit test (this is new to me), I'll integrate it in rs-short.

Thanks for reporting. I misunderstood the `Vec::drain()` function, I'm working on a fix. Thanks for providing the unit test (this is new to me), I'll integrate it in rs-short.
neil referenced this issue from a commit 7 months ago
neil closed this issue 7 months ago
neil referenced this issue from a commit 7 months ago
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.