chore: println for develop now

This commit is contained in:
caihongwen 2022-09-07 21:22:07 +08:00
parent 480d4c22dd
commit 52c1e6f33a
3 changed files with 20 additions and 9 deletions

View File

@ -37,8 +37,10 @@ serde_json = "1"
lazy_static = "1.4"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
[build-dependencies]
tonic-build = "0.8"
[dev-dependencies]
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

View File

@ -136,12 +136,14 @@ impl Connection {
};
self.state = match try_connect.await {
Ok(connected) => {
println!("connected successfully!");
tracing::debug!("connected successfully!");
connected
}
Err(error) => {
println!("error connecting {}", error);
tracing::warn!(%error, "error connecting");
let backoff = std::cmp::max(backoff + Self::BACKOFF, MAX_BACKOFF);
let backoff = std::cmp::min(backoff + Self::BACKOFF, MAX_BACKOFF);
State::Disconnected(backoff)
}
};
@ -157,15 +159,20 @@ impl Connection {
} => match Pin::new(resp_bi_stream).next().await {
Some(Ok(payload)) => return payload,
Some(Err(status)) => {
println!("error from stream {}", status);
tracing::warn!(%status, "error from stream");
self.state = State::Disconnected(Self::BACKOFF);
}
None => {
println!("stream closed by server");
tracing::error!("stream closed by server");
self.state = State::Disconnected(Self::BACKOFF);
}
},
State::Disconnected(_) => self.connect().await,
State::Disconnected(_) => {
println!("stream closed Disconnected");
self.connect().await
}
}
}
}
@ -209,14 +216,12 @@ mod tests {
#[tokio::test]
async fn test_remote_connect() {
tracing_subscriber::fmt::init();
println!("test_remote_connect");
let mut remote_connect =
Connection::new(ClientConfig::new().server_addr("http://0.0.0.0:9848".to_string()));
println!(
"try to connect {}",
remote_connect.client_config.server_addr.as_ref().unwrap()
);
remote_connect.connect().await
remote_connect.connect().await;
println!("{:?}", remote_connect.state)
}
#[tokio::test]
@ -225,7 +230,9 @@ mod tests {
let mut remote_connect =
Connection::new(ClientConfig::new().server_addr("http://0.0.0.0:9848".to_string()));
let payload = remote_connect.next_payload().await;
let server_req = payload_helper::build_server_request(payload).unwrap();
let payload = remote_connect.next_payload().await;
// let server_req = payload_helper::build_server_request(payload).unwrap();
println!("{:?}", remote_connect.state);
}
#[tokio::test]

View File

@ -46,6 +46,7 @@ pub(crate) fn build_server_response(
let body_data = resp_payload.body.unwrap().value;
let type_url = metadata.r#type;
let body_str = String::from_utf8(body_data).unwrap();
println!("build_server_response {} with {}", type_url, body_str);
tracing::debug!("build_server_response {} with {}", type_url, body_str);
if TYPE_SERVER_CHECK_SERVER_RESPONSE.eq(&type_url) {
let de: ServerCheckServerResponse = serde_json::from_str(body_str.as_str())?;
@ -65,6 +66,7 @@ pub(crate) fn build_server_request(
let body_data = req_payload.body.unwrap().value;
let type_url = metadata.r#type;
let body_str = String::from_utf8(body_data).unwrap();
println!("build_server_request {} with {}", type_url, body_str);
tracing::debug!("build_server_request {} with {}", type_url, body_str);
if TYPE_CONNECT_RESET_SERVER_REQUEST.eq(&type_url) {
let de: ConnectResetRequest = serde_json::from_str(body_str.as_str())?;