Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/dst/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "spacetimedb-dst"
name = "spacetimedb-dst-lib"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
Expand Down
20 changes: 0 additions & 20 deletions crates/dst/README.md

This file was deleted.

5 changes: 3 additions & 2 deletions crates/dst/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,11 @@ impl EngineTarget {
impl TargetDriver<Interaction> for EngineTarget {
type Observation = Observation;

fn execute(&mut self, interaction: &Interaction) -> Result<Self::Observation, anyhow::Error> {
async fn execute<'a>(&'a mut self, interaction: &'a Interaction) -> Result<Self::Observation, anyhow::Error> {
EngineTarget::execute(self, interaction)
}
}

pub struct EngineTest;

impl TestSuite for EngineTest {
Expand All @@ -289,7 +290,7 @@ impl TestSuite for EngineTest {

type Properties = EngineProperties;

fn build(&self, rng: Rng) -> Result<(Self::Interactions, Self::Target, Self::Properties), anyhow::Error> {
async fn build(&self, rng: Rng) -> Result<(Self::Interactions, Self::Target, Self::Properties), anyhow::Error> {
let schema = default_schema(rng.clone());
let runtime_seed = rng.next_u64();
let target = EngineTarget::init(schema.clone(), runtime_seed)?;
Expand Down
6 changes: 6 additions & 0 deletions crates/dst/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod engine;
pub mod schema;
pub mod sim;
pub mod traits;

pub use traits::{Properties, TargetDriver, TestSuite, TestSuiteParts};
91 changes: 0 additions & 91 deletions crates/dst/src/main.rs

This file was deleted.

6 changes: 6 additions & 0 deletions crates/dst/src/sim/commitlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ pub struct InMemoryCommitlog {
options: Options,
}

impl Default for InMemoryCommitlog {
fn default() -> Self {
Self::new()
}
}

impl InMemoryCommitlog {
pub fn new() -> Self {
Self {
Expand Down
34 changes: 20 additions & 14 deletions crates/dst/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use spacetimedb_runtime::sim::Rng;
pub trait TargetDriver<I> {
type Observation;

fn execute(&mut self, interaction: &I) -> Result<Self::Observation, Error>;
fn execute<'a>(
&'a mut self,
interaction: &'a I,
) -> impl std::future::Future<Output = Result<Self::Observation, Error>> + 'a;
}

/// Ensures if Output of `TargetDrive` is expected for the input
Expand All @@ -20,32 +23,35 @@ pub type TestSuiteParts<S> = (
);

pub trait TestSuite {
type Interaction;
type Interaction: std::fmt::Debug;
type Interactions: Iterator<Item = Self::Interaction> + std::fmt::Debug;
type Target: TargetDriver<Self::Interaction>;
type Properties: Properties<Self::Interaction, <Self::Target as TargetDriver<Self::Interaction>>::Observation>;

fn build(&self, rng: Rng) -> Result<TestSuiteParts<Self>, Error>
fn build(&self, rng: Rng) -> impl std::future::Future<Output = Result<TestSuiteParts<Self>, Error>> + '_
where
Self: Sized;

fn run(&self, rng: Rng, max_interactions: Option<usize>) -> Result<(), Error>
fn run(&self, rng: Rng, max_interactions: usize) -> impl std::future::Future<Output = Result<(), Error>> + '_
where
Self: Sized,
{
let (mut interactions, mut target, mut properties) = self.build(rng)?;
async move {
let (mut interactions, mut target, mut properties) = self.build(rng).await?;

let result = (|| {
for interaction in interactions.by_ref().take(max_interactions.unwrap_or(usize::MAX)) {
let observation = target.execute(&interaction)?;
properties.observe(&interaction, &observation)?;
}
let result = async {
for interaction in interactions.by_ref().take(max_interactions) {
let observation = target.execute(&interaction).await?;
properties.observe(&interaction, &observation)?;
}

Ok(())
})();
Ok(())
}
.await;

tracing::info!(interaction_counts = ?interactions, "final interaction counts");
tracing::info!(interaction_counts = ?interactions, "final interaction counts");

result
result
}
}
}
Loading