Skip to content

Commit

Permalink
fix node conflict tests in rust
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmurariu committed Jul 23, 2024
1 parent 21526d1 commit b19ff59
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 642 deletions.
58 changes: 55 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ debug = true

[workspace.dependencies]
#[public-storage]
pometry-storage = { version = ">=0.8.1", path = "pometry-storage" }
# pometry-storage = { version = ">=0.8.1", path = "pometry-storage" }
#[private-storage]
# pometry-storage = { path = "pometry-storage-private", package = "pometry-storage-private" }
pometry-storage = { path = "pometry-storage-private", package = "pometry-storage-private" }
async-graphql = { version = "7.0.5", features = ["dynamic-schema"] }
async-graphql-poem = "7.0.5"
dynamic-graphql = "0.9.0"
Expand Down
94 changes: 40 additions & 54 deletions raphtory/src/db/graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,11 @@ mod db_tests {

assert!(!g.has_edge(9, 7));
assert!(g.has_edge(7, 9));
}

#[test]
fn has_edge_str() {
let g = Graph::new();
g.add_edge(2, "haaroon", "northLondon", NO_PROPS, None)
.unwrap();
assert!(g.has_edge("haaroon", "northLondon"));
Expand Down Expand Up @@ -1009,19 +1013,29 @@ mod db_tests {
});
}

#[test]
fn test_add_node_with_nums() {
let graph = Graph::new();

graph.add_node(1, 831, NO_PROPS, None).unwrap();
test_storage!(&graph, |graph| {
assert!(graph.has_node(831));

assert_eq!(graph.count_nodes(), 1);
});
}

#[test]
fn test_add_node_with_strings() {
let graph = Graph::new();

graph.add_node(0, "haaroon", NO_PROPS, None).unwrap();
graph.add_node(1, "hamza", NO_PROPS, None).unwrap();
graph.add_node(1, 831, NO_PROPS, None).unwrap();
test_storage!(&graph, |graph| {
assert!(graph.has_node(831));
assert!(graph.has_node("haaroon"));
assert!(graph.has_node("hamza"));

assert_eq!(graph.count_nodes(), 3);
assert_eq!(graph.count_nodes(), 2);
});
}

Expand Down Expand Up @@ -1326,7 +1340,29 @@ mod db_tests {
}

#[test]
fn check_node_history() {
fn check_node_history_str() {
let graph = Graph::new();

graph.add_node(4, "Lord Farquaad", NO_PROPS, None).unwrap();
graph.add_node(6, "Lord Farquaad", NO_PROPS, None).unwrap();
graph.add_node(7, "Lord Farquaad", NO_PROPS, None).unwrap();
graph.add_node(8, "Lord Farquaad", NO_PROPS, None).unwrap();

// FIXME: Node updates without properties or edges are currently not supported in disk_graph (see issue #46)
test_graph(&graph, |graph| {
let times_of_farquaad = graph.node("Lord Farquaad").unwrap().history();

assert_eq!(times_of_farquaad, [4, 6, 7, 8]);

let view = graph.window(1, 8);

let windowed_times_of_farquaad = view.node("Lord Farquaad").unwrap().history();
assert_eq!(windowed_times_of_farquaad, [4, 6, 7]);
});
}

#[test]
fn check_node_history_num() {
let graph = Graph::new();

graph.add_node(1, 1, NO_PROPS, None).unwrap();
Expand All @@ -1335,25 +1371,16 @@ mod db_tests {
graph.add_node(4, 1, NO_PROPS, None).unwrap();
graph.add_node(8, 1, NO_PROPS, None).unwrap();

graph.add_node(4, "Lord Farquaad", NO_PROPS, None).unwrap();
graph.add_node(6, "Lord Farquaad", NO_PROPS, None).unwrap();
graph.add_node(7, "Lord Farquaad", NO_PROPS, None).unwrap();
graph.add_node(8, "Lord Farquaad", NO_PROPS, None).unwrap();

// FIXME: Node updates without properties or edges are currently not supported in disk_graph (see issue #46)
test_graph(&graph, |graph| {
let times_of_one = graph.node(1).unwrap().history();
let times_of_farquaad = graph.node("Lord Farquaad").unwrap().history();

assert_eq!(times_of_one, [1, 2, 3, 4, 8]);
assert_eq!(times_of_farquaad, [4, 6, 7, 8]);

let view = graph.window(1, 8);

let windowed_times_of_one = view.node(1).unwrap().history();
let windowed_times_of_farquaad = view.node("Lord Farquaad").unwrap().history();
assert_eq!(windowed_times_of_one, [1, 2, 3, 4]);
assert_eq!(windowed_times_of_farquaad, [4, 6, 7]);
});
}

Expand Down Expand Up @@ -1411,47 +1438,6 @@ mod db_tests {
});
}

#[test]
fn check_node_history_multiple_shards() {
let graph = Graph::new();

graph.add_node(1, 1, NO_PROPS, None).unwrap();
graph.add_node(2, 1, NO_PROPS, None).unwrap();
graph.add_node(3, 1, NO_PROPS, None).unwrap();
graph.add_node(4, 1, NO_PROPS, None).unwrap();
graph.add_node(5, 2, NO_PROPS, None).unwrap();
graph.add_node(6, 2, NO_PROPS, None).unwrap();
graph.add_node(7, 2, NO_PROPS, None).unwrap();
graph.add_node(8, 1, NO_PROPS, None).unwrap();
graph.add_node(9, 2, NO_PROPS, None).unwrap();
graph.add_node(10, 2, NO_PROPS, None).unwrap();

graph.add_node(4, "Lord Farquaad", NO_PROPS, None).unwrap();
graph.add_node(6, "Lord Farquaad", NO_PROPS, None).unwrap();
graph.add_node(7, "Lord Farquaad", NO_PROPS, None).unwrap();
graph.add_node(8, "Lord Farquaad", NO_PROPS, None).unwrap();

// FIXME: Issue #46
test_graph(&graph, |graph| {
let times_of_one = graph.node(1).unwrap().history();
let times_of_farquaad = graph.node("Lord Farquaad").unwrap().history();
let times_of_upper = graph.node(2).unwrap().history();

assert_eq!(times_of_one, [1, 2, 3, 4, 8]);
assert_eq!(times_of_farquaad, [4, 6, 7, 8]);
assert_eq!(times_of_upper, [5, 6, 7, 9, 10]);

let view = graph.window(1, 8);
let windowed_times_of_one = view.node(1).unwrap().history();
let windowed_times_of_two = view.node(2).unwrap().history();
let windowed_times_of_farquaad = view.node("Lord Farquaad").unwrap().history();

assert_eq!(windowed_times_of_one, [1, 2, 3, 4]);
assert_eq!(windowed_times_of_farquaad, [4, 6, 7]);
assert_eq!(windowed_times_of_two, [5, 6, 7]);
});
}

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

Expand Down
Loading

0 comments on commit b19ff59

Please sign in to comment.