la10736 / rstest

Fixture-based test framework for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: tests failed by memory allocation of x bytes failure` when only running many cases once

terassyi opened this issue · comments

Hi, I'm using rest conveniently for my project.

What

I encounter a memory allocation error when I run tests using rstest.
This project has about 300 test cases.

This is a part of the output when failing.

$ cargo test

... snip ...
test bgp::rib::tests::works_table_insert_and_remove::case_2 ... ok
test bgp::rib::tests::works_rib_manager_add_peer ... ok
test bgp::rib::tests::works_table_insert_and_remove::case_3 ... ok
test bgp::rib::tests::works_table_insert_and_remove::case_4 ... ok
test controller::reconciler::cluster_bgp::tests::test_get_label_selector::case_1 ... ok
test controller::reconciler::cluster_bgp::tests::test_get_label_selector::case_2 ... ok
test controller::reconciler::cluster_bgp::tests::test_get_label_selector::case_3 ... ok
test controller::reconciler::cluster_bgp::tests::test_match_selector::case_1 ... ok
test controller::reconciler::cluster_bgp::tests::test_match_selector::case_2 ... ok
test controller::reconciler::cluster_bgp::tests::test_match_selector::case_3 ... ok
test controller::reconciler::cluster_bgp::tests::test_match_selector::case_4 ... ok
test controller::reconciler::cluster_bgp::tests::test_match_selector::case_5 ... ok
test controller::reconciler::cluster_bgp::tests::test_match_selector::case_6 ... ok
test controller::reconciler::endpointslice_watcher::tests::works_sync_target_peers::case_1 ... ok
test controller::reconciler::endpointslice_watcher::tests::works_sync_target_peers::case_2 ... ok
test controller::reconciler::endpointslice_watcher::tests::works_sync_target_peers::case_3 ... ok
memory allocation of 2305843009213693952 bytes failed
error: test failed, to rerun pass `--lib`

Caused by:
  process didn't exit successfully: `sudo -E /home/terassyi/workspace/sart/sartd/target/debug/deps/sartd-92e6f14d9e8f1d1c` (signal: 6, SIGABRT: process abort signal)

I wonder if tests are failed out of memory and are caused by controller::reconciler::endpointslice_watcher::tests::works_sync_target_peer.

works_sync_target_peer is below.

#[rstest(
        peers,
        targets,
        updated,
        expected,
        case(BTreeMap::from([]), vec![], false, BTreeMap::from([])),
        case(BTreeMap::from([("peer1".to_string(), AdvertiseStatus::Advertised)]), vec!["peer1".to_string()], false, BTreeMap::from([])),
        case(BTreeMap::from([("peer1".to_string(), AdvertiseStatus::Advertised), ("peer2".to_string(), AdvertiseStatus::Advertised)]), vec!["peer1".to_string(), "peer2".to_string()], false, BTreeMap::from([])),
        case(BTreeMap::from([("peer1".to_string(), AdvertiseStatus::Advertised), ("peer2".to_string(), AdvertiseStatus::NotAdvertised)]), vec!["peer1".to_string(), "peer2".to_string()], false, BTreeMap::from([])),
        case(BTreeMap::from([("peer1".to_string(), AdvertiseStatus::Advertised)]), vec!["peer1".to_string(), "peer2".to_string()], true, BTreeMap::from([("peer1".to_string(), AdvertiseStatus::Advertised), ("peer2".to_string(), AdvertiseStatus::NotAdvertised)])),
        case(BTreeMap::from([("peer1".to_string(), AdvertiseStatus::Advertised), ("peer2".to_string(), AdvertiseStatus::Advertised)]), vec!["peer2".to_string()], true, BTreeMap::from([("peer1".to_string(), AdvertiseStatus::Withdraw), ("peer2".to_string(), AdvertiseStatus::Advertised)])),
        case(BTreeMap::from([("peer1".to_string(), AdvertiseStatus::Advertised), ("peer2".to_string(), AdvertiseStatus::Advertised)]), vec!["peer2".to_string(), "peer3".to_string()], true, BTreeMap::from([("peer1".to_string(), AdvertiseStatus::Withdraw), ("peer2".to_string(), AdvertiseStatus::Advertised), ("peer3".to_string(), AdvertiseStatus::NotAdvertised)])),
    )]
    fn works_sync_target_peers(
        mut peers: BTreeMap<String, AdvertiseStatus>,
        targets: Vec<String>,
        updated: bool,
        expected: BTreeMap<String, AdvertiseStatus>,
    ) {
        let res = sync_target_peers(&mut peers, &targets);
        assert_eq!(res, updated);
        if res {
            assert_eq!(peers, expected);
        }
    }

However, when I run only this test function, I can get successful results like this.

$ cargo test --package sartd --lib -- controller::reconciler::endpointslice_watcher::tests::works_sync_target_peers --nocapture
warning: `sartd` (lib test) generated 185 warnings (run `cargo fix --lib -p sartd --tests` to apply 27 suggestions)
    Finished test [unoptimized + debuginfo] target(s) in 0.06s
     Running unittests src/lib.rs (target/debug/deps/sartd-92e6f14d9e8f1d1c)

running 7 tests
test controller::reconciler::endpointslice_watcher::tests::works_sync_target_peers::case_1 ... ok
test controller::reconciler::endpointslice_watcher::tests::works_sync_target_peers::case_2 ... ok
test controller::reconciler::endpointslice_watcher::tests::works_sync_target_peers::case_3 ... ok
test controller::reconciler::endpointslice_watcher::tests::works_sync_target_peers::case_4 ... ok
test controller::reconciler::endpointslice_watcher::tests::works_sync_target_peers::case_5 ... ok
test controller::reconciler::endpointslice_watcher::tests::works_sync_target_peers::case_6 ... ok
test controller::reconciler::endpointslice_watcher::tests::works_sync_target_peers::case_7 ... ok

test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 237 filtered out; finished in 0.00s

In my consideration, I create BTreeMap for each test case and I also create BTreeMap in other tests.
And many BTreeMap use so much memory and it causes out of memory.

My environment

  • Ubuntu 22.04
  • 13th Gen Intel(R) Core(TM) i9-13900K
  • Mem 64GB

I'm not sure it is correct to report this problem here but I need some help to resolve this.

Thank you.

I found the cause in the other part and resolved it.
And rstest was not the cause.
So close this.
Thank you.