fn test_sock_cache_add_context_pre_existing()

in nfm-controller/src/events/sock_cache.rs [310:352]


    fn test_sock_cache_add_context_pre_existing() {
        // Add an initial context.
        let sock_key: SockKey = 55;
        let context = SockContext {
            address_family: AF_INET,
            local_ipv4: 99,
            ..Default::default()
        };
        let mut now_us = 100;
        let mut sock_cache = SockCache::new();
        sock_cache.add_context(sock_key, context, now_us);

        // Add a second context and verify it takes precedence.
        let context2 = SockContext {
            address_family: AF_INET,
            local_ipv4: context.local_ipv4 * 2,
            ..Default::default()
        };
        now_us *= 2;

        let result = sock_cache.add_context(sock_key, context2, now_us);
        assert_eq!(
            result,
            SockOperationResult {
                completed: 0,
                partial: 1,
                failed: 0,
            }
        );
        let wrapper = sock_cache.get(&sock_key).unwrap();
        assert_eq!(wrapper.context, context2);
        assert_eq!(
            wrapper.agg_stats,
            AggSockStats {
                stats: SockStats {
                    last_touched_us: now_us,
                    ..Default::default()
                },
                cpus: vec![],
            }
        );
        assert_eq!(sock_cache.len(), 1);
    }