Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] Database Location Change After agdb_server Restart Causes Data Inaccessibility #1133 #1135

Merged
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 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(())
}