minerva 0.2.0

Causal ordering for distributed systems
//! The recursion posture, exhibited: merge and read depth are proportional
//! to caller-built nesting, and nothing else can build nesting (no wire
//! frame exists; the depth budget is PRD 0020's recorded duty for the day
//! one does).

use super::super::super::support::dot;
use crate::metis::{DotSet, DotStore, Dotted};

use super::super::TestNode;
use super::reg_block;

/// A chain of `depth` single-child nodes with `leaf` at the bottom, every
/// level under key 0.
fn chain(depth: usize, leaf: TestNode) -> TestNode {
    let mut node = leaf;
    for _ in 0..depth {
        let mut parent = TestNode::new();
        assert!(parent.insert_child(0, node));
        node = parent;
    }
    node
}

#[test]
fn test_a_deep_caller_built_tree_merges_and_reads() {
    let depth = 64;
    let a = Dotted::from_store(chain(depth, reg_block(dot(1, 1), "a")));
    let b = Dotted::from_store(chain(depth, reg_block(dot(2, 1), "b")));

    let merged = a.merge(&b);
    let dots: DotSet = {
        let mut set = DotSet::new();
        for held in merged.store().dots() {
            assert!(set.insert(held));
        }
        set
    };
    assert!(dots.contains(dot(1, 1)) && dots.contains(dot(2, 1)));

    // The leaves live at the same path and became register siblings there.
    let mut node = merged.store();
    for _ in 0..depth {
        node = node.children().get(&0).expect("the chain survives whole");
    }
    assert_eq!(node.register().values().count(), 2);

    // Base change selects one station's fiber through the whole depth.
    let restricted = merged.restrict([1u32]);
    let mut node = restricted.store();
    for _ in 0..depth {
        node = node.children().get(&0).expect("station 1's fiber survives");
    }
    assert_eq!(node.register().values().count(), 1);
}