From dbffaedc2f3a92ed6ffc34406cd4338da9a579f6 Mon Sep 17 00:00:00 2001 From: ad hoc Date: Wed, 15 Nov 2023 18:34:34 +0100 Subject: [PATCH] test namespace creation on dirty instance --- libsql-server/tests/standalone/mod.rs | 52 +++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/libsql-server/tests/standalone/mod.rs b/libsql-server/tests/standalone/mod.rs index a59d0d9ac7..2746d70d0a 100644 --- a/libsql-server/tests/standalone/mod.rs +++ b/libsql-server/tests/standalone/mod.rs @@ -1,6 +1,7 @@ //! Tests for standalone primary configuration -use crate::common::{net::SimServer, snapshot_metrics}; +use crate::common::net::{SimServer, TurmoilAcceptor}; +use crate::common::{http::Client, snapshot_metrics}; use super::common; @@ -11,7 +12,7 @@ use libsql::{Database, Value}; use tempfile::tempdir; use tokio::sync::Notify; -use libsql_server::config::UserApiConfig; +use libsql_server::config::{AdminApiConfig, UserApiConfig}; use common::net::{init_tracing, TestServer, TurmoilConnector}; @@ -260,3 +261,50 @@ fn random_rowid() { sim.run().unwrap(); } + +#[test] +fn dirty_startup_dont_prevent_namespace_creation() { + let mut sim = turmoil::Builder::new().build(); + + sim.host("primary", || async { + init_tracing(); + let tmp = tempdir()?; + let server = TestServer { + path: tmp.path().to_owned().into(), + user_api_config: UserApiConfig { + hrana_ws_acceptor: None, + ..Default::default() + }, + admin_api_config: Some(AdminApiConfig { + acceptor: TurmoilAcceptor::bind(([0, 0, 0, 0], 9090)).await.unwrap(), + connector: TurmoilConnector, + disable_metrics: true, + }), + disable_default_namespace: true, + disable_namespaces: false, + ..Default::default() + }; + + tokio::fs::File::create(tmp.path().join(".sentinel")) + .await + .unwrap(); + server.start_sim(8080).await?; + + Ok(()) + }); + + sim.client("test", async { + let client = Client::new(); + let resp = client + .post( + "http://primary:9090/v1/namespaces/test/create", + serde_json::json!({}), + ) + .await + .unwrap(); + assert!(resp.status().is_success()); + Ok(()) + }); + + sim.run().unwrap(); +}