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

Method load_module

crates/testing/src/modules.rs:258–332  ·  view source on GitHub ↗

Load a module with the given config. If "reuse_db_path" is set, the module will be loaded in the given path, without resetting the database. This is used to speed up benchmarks running under callgrind (it allows them to reuse native-compiled wasm modules).

(&self, config: Config, reuse_db_path: Option<&RootDir>)

Source from the content-addressed store, hash-verified

256 /// without resetting the database.
257 /// This is used to speed up benchmarks running under callgrind (it allows them to reuse native-compiled wasm modules).
258 pub async fn load_module(&self, config: Config, reuse_db_path: Option<&RootDir>) -> ModuleHandle {
259 let paths = match reuse_db_path {
260 Some(path) => SpacetimePaths::from_root_dir(path),
261 None => {
262 let root_dir = RootDir(env::temp_dir().join("stdb").join(&self.name));
263
264 // The database created in the `temp` folder can't be randomized,
265 // so it persists after running the test.
266 std::fs::remove_dir(&root_dir).ok();
267
268 SpacetimePaths::from_root_dir(&root_dir)
269 }
270 };
271
272 let certs = CertificateAuthority::in_cli_config_dir(&paths.cli_config_dir);
273 let env = spacetimedb_standalone::StandaloneEnv::init(
274 spacetimedb_standalone::StandaloneOptions {
275 db_config: config,
276 durability: Default::default(),
277 websocket: WebSocketOptions::default(),
278 wasm: Default::default(),
279 v8: Default::default(),
280 },
281 &certs,
282 paths.data_dir.into(),
283 JobCores::without_pinned_cores(),
284 )
285 .await
286 .unwrap();
287 // TODO: Fix this when we update identity generation.
288 let identity = Identity::ZERO;
289 let db_identity = SpacetimeAuth::alloc(&env).await.unwrap().claims.identity;
290 let connection_id = generate_random_connection_id();
291
292 env.publish_database(
293 &identity,
294 DatabaseDef {
295 database_identity: db_identity,
296 program_bytes: self.program_bytes(),
297 num_replicas: None,
298 host_type: self.host_type,
299 parent: None,
300 organization: None,
301 },
302 MigrationPolicy::Compatible,
303 )
304 .await
305 .unwrap();
306
307 let database = env.get_database_by_identity(&db_identity).await.unwrap().unwrap();
308 let instance = env.get_leader_replica_by_database(database.id).await.unwrap();
309
310 let client_id = ClientActorId {
311 identity,
312 connection_id,
313 name: env.client_actor_index().next_client_name(),
314 };
315

Callers 4

mainFunction · 0.80
buildMethod · 0.80
with_module_asyncMethod · 0.80
with_moduleMethod · 0.80

Calls 13

joinMethod · 0.80
next_client_nameMethod · 0.80
module_watcherMethod · 0.80
initFunction · 0.50
okMethod · 0.45
unwrapMethod · 0.45
publish_databaseMethod · 0.45
program_bytesMethod · 0.45
client_actor_indexMethod · 0.45

Tested by

no test coverage detected