Skip to content

Commit d4e0806

Browse files
authored
ci: fix flaky ttc test (#17665)
1 parent 6d97c3f commit d4e0806

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

tests/sqllogictests/src/error.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use serde::Deserialize;
2222
use serde::Serialize;
2323
use serde_json::Error as SerdeJsonError;
2424
use sqllogictest::TestError;
25+
use testcontainers::core::error::ClientError;
2526
use thiserror::Error;
2627
use walkdir::Error as WalkDirError;
2728

@@ -80,3 +81,9 @@ impl From<String> for DSqlLogicTestError {
8081
DSqlLogicTestError::SelfError(value)
8182
}
8283
}
84+
85+
impl From<ClientError> for DSqlLogicTestError {
86+
fn from(value: ClientError) -> Self {
87+
DSqlLogicTestError::SelfError(value.to_string())
88+
}
89+
}

tests/sqllogictests/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use std::future::Future;
1717
use std::path::Path;
1818
use std::time::Instant;
1919

20-
use bollard::Docker;
2120
use clap::Parser;
2221
use client::TTCClient;
2322
use futures_util::stream;
@@ -161,12 +160,11 @@ async fn run_hybrid_client(
161160
) -> Result<()> {
162161
println!("Hybird client starts to run with: {:?}", args);
163162

164-
let docker = Docker::connect_with_local_defaults().unwrap();
165163
for (c, _) in HYBRID_CONFIGS.iter() {
166164
match c.as_ref() {
167165
ClientType::MySQL | ClientType::Http => {}
168166
ClientType::Ttc(image, port) => {
169-
run_ttc_container(&docker, image, *port, args.port, cs).await?;
167+
run_ttc_container(image, *port, args.port, cs).await?;
170168
}
171169
ClientType::Hybird => panic!("Can't run hybrid client in hybrid client"),
172170
}

tests/sqllogictests/src/util.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use redis::Commands;
2626
use serde::Deserialize;
2727
use serde::Serialize;
2828
use serde_json::Value;
29+
use testcontainers::core::client::docker_client_instance;
2930
use testcontainers::core::error::WaitContainerError;
3031
use testcontainers::core::IntoContainerPort;
3132
use testcontainers::core::WaitFor;
@@ -242,12 +243,12 @@ fn run_script(name: &str, args: &[&str]) -> Result<()> {
242243
}
243244

244245
pub async fn run_ttc_container(
245-
docker: &Docker,
246246
image: &str,
247247
port: u16,
248248
http_server_port: u16,
249249
cs: &mut Vec<ContainerAsync<GenericImage>>,
250250
) -> Result<()> {
251+
let docker = &docker_client_instance().await?;
251252
let mut images = image.split(":");
252253
let image = images.next().unwrap();
253254
let tag = images.next().unwrap_or("latest");
@@ -264,8 +265,6 @@ pub async fn run_ttc_container(
264265
let start = Instant::now();
265266
println!("Start container {container_name}");
266267

267-
stop_container(docker, &container_name).await;
268-
269268
let mut i = 1;
270269
loop {
271270
let container_res = GenericImage::new(image, tag)
@@ -287,28 +286,24 @@ pub async fn run_ttc_container(
287286
match container_res {
288287
Ok(container) => {
289288
println!(
290-
"Start container {} using {} secs success",
289+
"Start container {container_name} {} using {duration} secs success",
291290
container.id(),
292-
duration
293291
);
294292
cs.push(container);
295293
return Ok(());
296294
}
297295
Err(err) => {
298-
println!(
299-
"Start container {} using {} secs failed: {}",
300-
container_name, duration, err
301-
);
296+
println!("Start container {container_name} using {duration} secs failed: {err}");
302297
if err.to_string().to_ascii_lowercase().contains("timeout")
303298
|| err.to_string().to_ascii_lowercase().contains("conflict")
304299
{
305-
println!("start to stop container {container_name}");
300+
println!("Start to stop container {container_name}");
306301
stop_container(docker, &container_name).await;
307302
}
308303
if i == CONTAINER_RETRY_TIMES || duration >= CONTAINER_TIMEOUT_SECONDS {
309304
break;
310305
} else {
311-
println!("retry start container {container_name} after {duration}");
306+
println!("retry start container {container_name} after {duration} secs");
312307
i += 1;
313308
}
314309
}
@@ -330,7 +325,7 @@ pub async fn lazy_run_dictionary_containers(
330325
return Ok(None);
331326
}
332327
println!("Start run dictionary source server container");
333-
let docker = Docker::connect_with_local_defaults().unwrap();
328+
let docker = docker_client_instance().await?;
334329
let redis = run_redis_server(&docker).await?;
335330
let mysql = run_mysql_server(&docker).await?;
336331
let dict_container = DictionaryContainer { redis, mysql };
@@ -469,11 +464,15 @@ async fn run_mysql_server(docker: &Docker) -> Result<ContainerAsync<Mysql>> {
469464

470465
// Stop the running container to avoid conflict
471466
async fn stop_container(docker: &Docker, container_name: &str) {
472-
let _ = docker.stop_container(container_name, None).await;
467+
if let Err(err) = docker.stop_container(container_name, None).await {
468+
println!("stop container {container_name} err: {err}");
469+
}
473470
let options = Some(RemoveContainerOptions {
474471
force: true,
475472
..Default::default()
476473
});
477-
let _ = docker.remove_container(container_name, options).await;
478-
println!("Stop container {container_name}");
474+
if let Err(err) = docker.remove_container(container_name, options).await {
475+
println!("remove container {container_name} err: {err}");
476+
}
477+
println!("Stopped container {container_name}");
479478
}

0 commit comments

Comments
 (0)