Skip to content

Commit

Permalink
fix: use correct method to get was_alive for tree node
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Sep 15, 2024
1 parent 225812a commit 29e166f
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 7 deletions.
3 changes: 2 additions & 1 deletion crates/fuzz/src/container/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ impl ApplyDiff for TreeTracker {
}

fn apply_diff(&mut self, diff: Diff) {
// debug!("applying diff: {:#?}", &diff);
// trace!("current tree: {:#?}", &self.tree);
// trace!("applying diff: {:#?}", &diff);
let diff = diff.as_tree().unwrap();
for diff in &diff.diff {
let target = diff.target;
Expand Down
242 changes: 241 additions & 1 deletion crates/fuzz/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10266,12 +10266,252 @@ fn gc_fuzz_17() {
)
}

#[test]
fn gc_fuzz_18() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
&mut [
SyncAll,
Handle {
site: 27,
target: 27,
container: 27,
action: Generic(GenericAction {
value: I32(286989083),
bool: true,
key: 4288224017,
pos: 1953436334768717823,
length: 1956843841325308699,
prop: 1953184666628070171,
}),
},
Handle {
site: 27,
target: 27,
container: 27,
action: Generic(GenericAction {
value: I32(-1994712289),
bool: true,
key: 461970203,
pos: 1953184666628070170,
length: 1953184722462645019,
prop: 9879520012645636895,
}),
},
Handle {
site: 27,
target: 27,
container: 27,
action: Generic(GenericAction {
value: I32(454764571),
bool: true,
key: 454761243,
pos: 1953185035995257627,
length: 8150137753889872667,
prop: 13093571283691877813,
}),
},
Sync { from: 181, to: 181 },
Handle {
site: 255,
target: 27,
container: 27,
action: Generic(GenericAction {
value: Container(Unknown(232)),
bool: true,
key: 4294967295,
pos: 13093571280777456127,
length: 13093571283691877813,
prop: 13093401958901200309,
}),
},
Handle {
site: 27,
target: 27,
container: 27,
action: Generic(GenericAction {
value: I32(-400876773),
bool: false,
key: 3907578088,
pos: 1984146914073451291,
length: 1953184666628070170,
prop: 1953184722462645019,
}),
},
Handle {
site: 27,
target: 27,
container: 27,
action: Generic(GenericAction {
value: I32(454761243),
bool: true,
key: 3044088603,
pos: 576460752303423487,
length: 37167066886380315,
prop: 1808504322244529934,
}),
},
SyncAllUndo {
site: 137,
op_len: 454761243,
},
],
)
}

#[test]
fn minify() {
minify_error(
5,
|n, actions| test_multi_sites_with_gc(n, vec![FuzzTarget::All], actions),
|_, actions| actions.to_vec(),
vec![],
vec![
SyncAll,
SyncAll,
Handle {
site: 27,
target: 27,
container: 27,
action: Generic(GenericAction {
value: I32(286989083),
bool: true,
key: 4288224017,
pos: 1953436334768717823,
length: 1956843841325308699,
prop: 1953184666628070171,
}),
},
Handle {
site: 27,
target: 27,
container: 27,
action: Generic(GenericAction {
value: I32(-1994712289),
bool: true,
key: 461970203,
pos: 1953184666628070170,
length: 1953184722462645019,
prop: 9879520012645636895,
}),
},
Handle {
site: 27,
target: 27,
container: 27,
action: Generic(GenericAction {
value: I32(454764571),
bool: true,
key: 454761243,
pos: 1953185035995257627,
length: 8150137753889872667,
prop: 13093571283691877813,
}),
},
Sync { from: 181, to: 181 },
Sync { from: 181, to: 181 },
Sync { from: 181, to: 181 },
Undo {
site: 113,
op_len: 460419441,
},
Sync { from: 181, to: 181 },
Sync { from: 181, to: 181 },
Sync { from: 181, to: 181 },
Sync { from: 181, to: 181 },
Undo {
site: 113,
op_len: 1903260017,
},
Handle {
site: 255,
target: 27,
container: 27,
action: Generic(GenericAction {
value: Container(Unknown(232)),
bool: true,
key: 4294967295,
pos: 13093571280777456127,
length: 13093571283691877813,
prop: 13093401958901200309,
}),
},
Sync { from: 181, to: 181 },
Sync { from: 113, to: 113 },
Handle {
site: 27,
target: 27,
container: 27,
action: Generic(GenericAction {
value: I32(-400876773),
bool: false,
key: 3907578088,
pos: 1984146914073451291,
length: 1953184666628070170,
prop: 1953184722462645019,
}),
},
Handle {
site: 27,
target: 27,
container: 27,
action: Generic(GenericAction {
value: I32(454761243),
bool: true,
key: 3044088603,
pos: 576460752303423487,
length: 37167066886380315,
prop: 1808504322244529934,
}),
},
Handle {
site: 255,
target: 255,
container: 255,
action: Generic(GenericAction {
value: Container(Unknown(255)),
bool: true,
key: 4294967295,
pos: 1808504320961354239,
length: 14378174507281619225,
prop: 14395694394777257927,
}),
},
Checkout {
site: 50,
to: 842150450,
},
Sync { from: 199, to: 199 },
SyncAllUndo {
site: 137,
op_len: 454761243,
},
Handle {
site: 27,
target: 27,
container: 27,
action: Generic(GenericAction {
value: I32(-1987475063),
bool: true,
key: 2307507147,
pos: 15553137160186484565,
length: 8215691624525624023,
prop: 1953184666635301490,
}),
},
Handle {
site: 35,
target: 35,
container: 35,
action: Generic(GenericAction {
value: I32(589505315),
bool: true,
key: 589505315,
pos: 590711300899,
length: 0,
prop: 0,
}),
},
],
)
}
6 changes: 1 addition & 5 deletions crates/loro-internal/src/state/tree_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,8 @@ impl ContainerState for TreeState {
let need_check = !matches!(ctx.mode, DiffMode::Checkout | DiffMode::Linear);
let mut ans = vec![];
if let InternalDiff::Tree(tree) = &diff {
// println!("before {:?}", self.children);
// assert never cause cycle move
for diff in tree.diff.iter() {
// println!("\ndiff {:?}", diff);
let last_move_op = diff.last_effective_move_op_id;
let target = diff.target;
// create associated metadata container
Expand All @@ -981,8 +979,8 @@ impl ContainerState for TreeState {
let old_parent = self.trees.get(&target).unwrap().parent;
// If this is some, the node is still alive at the moment
let old_index = self.get_index_by_tree_id(&target);
let was_alive = !self.is_node_deleted(&target);
if need_check {
let was_alive = old_index.is_some();
if self
.mov(target, *parent, last_move_op, Some(position.clone()), true)
.is_ok()
Expand Down Expand Up @@ -1096,11 +1094,9 @@ impl ContainerState for TreeState {
.delete_child(&target);
}
}
// println!("after {:?}", self.children);
continue;
}
};
// println!("after {:?}", self.children);
}
}

Expand Down

0 comments on commit 29e166f

Please sign in to comment.