MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / finish_module_test

Function finish_module_test

crates/testing/src/modules.rs:349–364  ·  view source on GitHub ↗

These standalone module tests run a `StandaloneEnv` in-process. That means [`CompiledModule::with_module_async`] and [`CompiledModule::with_module`] own the Tokio runtime, host controller, module host, scheduler, `RelationalDB`, JS worker threads, etc. Some modules schedule repeating reducers during `init`. If these helpers return without explicitly shutting the database down, scheduled reducer c

(env: &StandaloneEnv, db_identity: Identity, test_result: std::thread::Result<()>)

Source from the content-addressed store, hash-verified

347/// asks the host controller to exit the module host, closes and waits for the scheduler,
348/// and then shuts down the `RelationalDB`.
349async fn finish_module_test(env: &StandaloneEnv, db_identity: Identity, test_result: std::thread::Result<()>) {
350 let cleanup_result = env.delete_database(&Identity::ZERO, &db_identity).await;
351
352 // Cleanup should not hide the result of the test body.
353 // If the test already panicked, resume that panic after attempting shutdown.
354 // If the test passed, make cleanup failure a test failure.
355 match (test_result, cleanup_result) {
356 (Ok(()), Ok(())) => {}
357 (Ok(()), Err(err)) => panic!("failed to delete test database {db_identity}: {err:#}"),
358 (Err(panic), Ok(())) => std::panic::resume_unwind(panic),
359 (Err(panic), Err(err)) => {
360 log::error!("failed to delete test database {db_identity} after test panic: {err:#}");
361 std::panic::resume_unwind(panic);
362 }
363 }
364}
365
366/// For testing, persist to disk by default, as many tests
367/// exercise functionality like restarting the database.

Callers 2

with_module_asyncMethod · 0.85
with_moduleMethod · 0.85

Calls 1

delete_databaseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…