Skip to content

Commit

Permalink
tweak some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Mar 28, 2024
1 parent daaf0d4 commit 5c8ad8c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
37 changes: 26 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ async fn init_rxqlite<P>(
base_dir: P,
instance_params: InstanceParams,
is_test_node: bool,
) -> anyhow::Result<(Arc<App>, tokio::task::JoinHandle<()>)>
) -> anyhow::Result<
(
Arc<App>,
tokio::task::JoinHandle<()>,
)>
where
P: AsRef<Path>,
{
Expand Down Expand Up @@ -298,9 +302,10 @@ where
let notifications_addr = instance_params.notifications_addr.clone();

let _ = task::spawn(async move {
notifications::start_notification_server_tls(notifications_addr, notification_config,is_test_node)
.await
.unwrap();
if let Err(err) = notifications::start_notification_server_tls(notifications_addr, notification_config,is_test_node)
.await {
tracing::error!("Notification server error: {}",err);
}
});

let config_builder: ConfigBuilder<ServerConfig, WantsServerCert> = ServerConfig::builder()
Expand All @@ -327,18 +332,22 @@ where
//let listener = TcpListener::bind(instance_params.rpc_addr.clone()).await?;

let handle = task::spawn(async move {
let _= server
.accept_with_tls_config(listener, config)
.await;

if let Err(err) = server
.accept_with_tls_config(listener, config)
.await {
tracing::error!("Toy rpc error: {}",err);
}
});
handle
} else {
let notifications_addr = instance_params.notifications_addr.clone();

let _ = task::spawn(async move {
notifications::start_notification_server(notifications_addr,is_test_node)
.await
.unwrap();
if let Err(err) = notifications::start_notification_server(notifications_addr,is_test_node)
.await {
tracing::error!("Notification server error: {}",err);
}
});

server_builder = server_builder.register(echo_service);
Expand All @@ -359,7 +368,12 @@ where
//let listener = TcpListener::bind(instance_params.rpc_addr.clone()).await?;

let handle = task::spawn(async move {
let _=server.accept_websocket(listener).await;

if let Err(err) = server
.accept_websocket(listener)
.await {
tracing::error!("Toy rpc error: {}",err);
}
});
handle
};
Expand Down Expand Up @@ -602,6 +616,7 @@ where

tokio::select! {
_ = handle => {

}
_ = signal::ctrl_c() => {
//std::process::exit(0);
Expand Down
5 changes: 4 additions & 1 deletion src/tests/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ pub const DELAY_BETWEEN_KILL_AND_START: tokio::time::Duration= tokio::time::Dura
pub const DELAY_BETWEEN_LEADER_VACATION_RETRIES: tokio::time::Duration =
tokio::time::Duration::from_secs(1);

pub const LEADER_VACATION_RETRIES: usize = 5;
pub const LEADER_VACATION_RETRIES: usize = 10;

pub const NOTIFICATIONS_READ_TIMEOUT: tokio::time::Duration= tokio::time::Duration::from_secs(120);

pub const WAIT_FOR_LAST_APPLIED_LOG_SECS: usize= 120;
11 changes: 7 additions & 4 deletions src/tests/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use sqlx_sqlite_cipher::notifications::{Action, Notification};
#[cfg(target_os = "linux")]
use super::consts::DELAY_BETWEEN_KILL_AND_START;
*/

use super::consts::NOTIFICATIONS_READ_TIMEOUT;

use super::consts::{LEADER_VACATION_RETRIES,DELAY_BETWEEN_LEADER_VACATION_RETRIES};

fn do_notifications(test_name: &str,
Expand Down Expand Up @@ -70,7 +73,7 @@ fn do_notifications(test_name: &str,

let notification_stream = client.notification_stream.as_mut().unwrap();
let message = notification_stream
.read_timeout(tokio::time::Duration::from_secs(60))
.read_timeout(NOTIFICATIONS_READ_TIMEOUT)
.await
.unwrap();
assert!(message.is_some());
Expand Down Expand Up @@ -102,7 +105,7 @@ fn do_notifications(test_name: &str,
}
let notification_stream = client.notification_stream.as_mut().unwrap();
let message = notification_stream
.read_timeout(tokio::time::Duration::from_secs(60))
.read_timeout(NOTIFICATIONS_READ_TIMEOUT)
.await
.unwrap();
assert!(message.is_some());
Expand Down Expand Up @@ -190,7 +193,7 @@ fn do_notifications2(test_name: &str,

let notification_stream = client.notification_stream.as_mut().unwrap();
let message = notification_stream
.read_timeout(tokio::time::Duration::from_secs(60))
.read_timeout(NOTIFICATIONS_READ_TIMEOUT)
.await
.unwrap();
assert!(message.is_some());
Expand Down Expand Up @@ -222,7 +225,7 @@ fn do_notifications2(test_name: &str,
}
let notification_stream = client.notification_stream.as_mut().unwrap();
let message = notification_stream
.read_timeout(tokio::time::Duration::from_secs(60))
.read_timeout(NOTIFICATIONS_READ_TIMEOUT)
.await
.unwrap();
assert!(message.is_some());
Expand Down
7 changes: 5 additions & 2 deletions src/tests/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use ring::digest;
use std::fs::File;
use std::io::BufReader;

use super::consts::{LEADER_VACATION_RETRIES,DELAY_BETWEEN_LEADER_VACATION_RETRIES};
use super::consts::{
LEADER_VACATION_RETRIES,
DELAY_BETWEEN_LEADER_VACATION_RETRIES,
WAIT_FOR_LAST_APPLIED_LOG_SECS};

fn do_simple_query(test_name: &str, tls_config: Option<TestTlsConfig>) {
let rt = Runtime::new().unwrap();
Expand Down Expand Up @@ -56,7 +59,7 @@ fn do_simple_query(test_name: &str, tls_config: Option<TestTlsConfig>) {
MessageResponse::Error(err) => panic!("{}", err),
}

tm.wait_for_last_applied_log(response.log_id, 60)
tm.wait_for_last_applied_log(response.log_id, WAIT_FOR_LAST_APPLIED_LOG_SECS)
.await
.unwrap();

Expand Down

0 comments on commit 5c8ad8c

Please sign in to comment.