Skip to content

Commit

Permalink
[server] Database Location Change After agdb_server Restart Causes Da…
Browse files Browse the repository at this point in the history
…ta Inaccessibility #1133 (#1135)

fix
  • Loading branch information
michaelvlach authored Jun 22, 2024
1 parent cf2fc90 commit c85cb09
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion agdb_server/src/db_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl DbPool {

for db in dbs {
let (owner, db_name) = db.name.split_once('/').ok_or(ErrorCode::DbInvalid)?;
let db_path = Path::new(&config.data_dir).join(db_name);
let db_path = db_file(owner, db_name, config);
std::fs::create_dir_all(db_audit_dir(owner, config))?;
let server_db =
ServerDb::new(&format!("{}:{}", db.db_type, db_path.to_string_lossy()))?;
Expand Down
46 changes: 46 additions & 0 deletions agdb_server/tests/routes/misc_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::TestServer;
use crate::TestServerImpl;
use crate::ADMIN;
use crate::SERVER_DATA_DIR;
use agdb::QueryBuilder;
use agdb_api::AgdbApi;
use agdb_api::ReqwestClient;
use assert_cmd::cargo::CommandCargoExt;
Expand Down Expand Up @@ -171,3 +172,48 @@ async fn basepath_test() -> anyhow::Result<()> {

Ok(())
}

#[tokio::test]
async fn location_change_after_restart() -> anyhow::Result<()> {
let mut server = TestServerImpl::new().await?;
let mut client = AgdbApi::new(ReqwestClient::new(), &server.address);

{
client.user_login(ADMIN, ADMIN).await?;
client.admin_user_add("user1", "userxpassword").await?;
client.user_logout().await?;
client.user_login("user1", "userxpassword").await?;
client
.db_add("user1", "mydb", agdb_api::DbType::Mapped)
.await?;
client
.db_exec(
"user1",
"mydb",
&vec![QueryBuilder::insert().nodes().count(1).query().into()],
)
.await?;
client.user_logout().await?;
client.user_login(ADMIN, ADMIN).await?;
client.admin_shutdown().await?;
assert!(server.process.wait()?.success());
}

server.process = Command::cargo_bin("agdb_server")?
.current_dir(&server.dir)
.spawn()?;
wait_for_ready(&client).await?;
client.user_login("user1", "userxpassword").await?;
let results = client
.db_exec(
"user1",
"mydb",
&vec![QueryBuilder::select().ids(1).query().into()],
)
.await?;

assert_eq!(results.1.len(), 1);
assert_eq!(results.1[0].result, 1);

Ok(())
}

0 comments on commit c85cb09

Please sign in to comment.