Skip to content

Commit

Permalink
test: avoid fuzz oom
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Oct 11, 2024
1 parent c5c404f commit 2186417
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 2 deletions.
256 changes: 256 additions & 0 deletions crates/fuzz/examples/oom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
use fuzz::{
actions::{ActionWrapper::*, GenericAction},
crdt_fuzzer::{Action::*, FuzzValue::*},
test_multi_sites_on_one_doc,
};
use loro::ContainerType::*;

pub fn main() {
test_multi_sites_on_one_doc(
5,
&mut [
Handle {
site: 1,
target: 0,
container: 0,
action: Generic(GenericAction {
value: I32(53423135),
bool: true,
key: 3271672771,
pos: 72391498414670731,
length: 2534382878240390,
prop: 12587145347420061696,
}),
},
Handle {
site: 0,
target: 0,
container: 0,
action: Generic(GenericAction {
value: Container(Tree),
bool: true,
key: 2248212783,
pos: 10886371984050945,
length: 3393509701437167640,
prop: 2821266740684986392,
}),
},
Handle {
site: 39,
target: 39,
container: 126,
action: Generic(GenericAction {
value: I32(-132),
bool: true,
key: 4281597952,
pos: 9899933171711,
length: 2821266740684990247,
prop: 2821266740684990247,
}),
},
SyncAll,
Sync { from: 191, to: 195 },
Checkout {
site: 1,
to: 783189505,
},
Handle {
site: 195,
target: 195,
container: 195,
action: Generic(GenericAction {
value: I32(842347833),
bool: false,
key: 3351758643,
pos: 13382947428572317639,
length: 14395678941249124793,
prop: 13386888078246266823,
}),
},
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 52, to: 56 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Checkout {
site: 199,
to: 3351758791,
},
Sync { from: 81, to: 199 },
Sync { from: 54, to: 57 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 199, to: 199 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Checkout {
site: 199,
to: 3351758791,
},
Sync { from: 81, to: 199 },
Sync { from: 54, to: 57 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 199, to: 199 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 185, to: 185 },
Sync { from: 199, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 52, to: 56 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Checkout {
site: 199,
to: 3351758791,
},
Sync { from: 81, to: 199 },
Sync { from: 54, to: 57 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 199, to: 199 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Checkout {
site: 199,
to: 3351758791,
},
Sync { from: 81, to: 199 },
Sync { from: 54, to: 57 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 199, to: 199 },
Sync { from: 185, to: 185 },
Checkout {
site: 185,
to: 3115956665,
},
Checkout {
site: 185,
to: 3115956665,
},
Sync { from: 185, to: 185 },
Sync { from: 185, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 52, to: 53 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Checkout {
site: 199,
to: 3351758791,
},
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 52, to: 53 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Checkout {
site: 199,
to: 3351758791,
},
Sync { from: 199, to: 199 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Sync { from: 185, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Checkout {
site: 199,
to: 3351758791,
},
Sync { from: 185, to: 185 },
Sync { from: 185, to: 185 },
Handle {
site: 3,
target: 3,
container: 3,
action: Generic(GenericAction {
value: I32(50529027),
bool: true,
key: 50529027,
pos: 217020518514230019,
length: 217020518514230019,
prop: 217020518514230019,
}),
},
Sync { from: 185, to: 185 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
Sync { from: 199, to: 199 },
],
);
}
5 changes: 3 additions & 2 deletions crates/fuzz/src/one_doc_fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,9 @@ impl OneDocFuzzer {
}
}
Action::Sync { from, to } => {
let a = self.branches[*from as usize].frontiers.clone();
self.branches[*to as usize].frontiers.extend_from_slice(&a);
let mut f = self.branches[*from as usize].frontiers.clone();
f.extend_from_slice(&self.branches[*to as usize].frontiers);
self.branches[*to as usize].frontiers = self.doc.minimize_frontiers(&f);
}
Action::SyncAll => {
let f = self.doc.oplog_frontiers();
Expand Down
6 changes: 6 additions & 0 deletions crates/loro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use loro_internal::handler::HandlerTrait;
use loro_internal::handler::ValueOrHandler;
use loro_internal::loro::ChangeTravelError;
use loro_internal::undo::{OnPop, OnPush};
use loro_internal::version::shrink_frontiers;
pub use loro_internal::version::ImVersionVector;
use loro_internal::DocState;
use loro_internal::LoroDoc as InnerLoroDoc;
Expand Down Expand Up @@ -449,6 +450,11 @@ impl LoroDoc {
self.doc.frontiers_to_vv(frontiers)
}

/// Minimize the frontiers by removing the unnecessary entries.
pub fn minimize_frontiers(&self, frontiers: &[ID]) -> Frontiers {
self.with_oplog(|oplog| shrink_frontiers(frontiers, oplog.dag()))
}

/// Convert `VersionVector` into `Frontiers`
#[inline]
pub fn vv_to_frontiers(&self, vv: &VersionVector) -> Frontiers {
Expand Down

0 comments on commit 2186417

Please sign in to comment.