Skip to content

Commit 6069121

Browse files
authored
test: make docker image configurable and ephemeral test more robust (#21)
* feat: make oxia docker image configurable in tests - Support OXIA_IMAGE and OXIA_TAG env vars for test configuration - Default: oxia/oxia:main, also works with streamnative/oxia:latest - Enables CI environments to use their preferred image registry Signed-off-by: mattisonchao <mattisonchao@gmail.com> * test: make ephemeral key test more robust with retry - Replace fixed 2s sleep with retry loop (up to 10 attempts with increasing backoff) to handle variable session cleanup timing Signed-off-by: mattisonchao <mattisonchao@gmail.com> --------- Signed-off-by: mattisonchao <mattisonchao@gmail.com>
1 parent 5ff1b35 commit 6069121

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

liboxia-native/tests/integration_tests.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ use testcontainers::runners::AsyncRunner;
1212
use testcontainers::{ContainerAsync, GenericImage, ImageExt};
1313

1414
const OXIA_PORT: u16 = 6648;
15+
const DEFAULT_OXIA_IMAGE: &str = "oxia/oxia";
16+
const DEFAULT_OXIA_TAG: &str = "main";
1517

1618
async fn start_oxia() -> (ContainerAsync<GenericImage>, String) {
17-
let container = GenericImage::new("oxia/oxia", "main")
19+
let image = std::env::var("OXIA_IMAGE").unwrap_or_else(|_| DEFAULT_OXIA_IMAGE.to_string());
20+
let tag = std::env::var("OXIA_TAG").unwrap_or_else(|_| DEFAULT_OXIA_TAG.to_string());
21+
22+
let container = GenericImage::new(image, tag)
1823
.with_exposed_port(ContainerPort::Tcp(OXIA_PORT))
1924
.with_wait_for(WaitFor::message_on_stdout("Started Grpc server"))
2025
.with_cmd(vec!["oxia", "standalone"])
@@ -465,16 +470,20 @@ async fn test_ephemeral_keys() {
465470
// Shutdown client (which closes session, deleting ephemeral keys)
466471
client1.shutdown().await.unwrap();
467472

468-
// Wait for session to be cleaned up
469-
tokio::time::sleep(Duration::from_secs(2)).await;
470-
471-
// New client should not find the ephemeral key
473+
// Wait for session to be cleaned up (retry with backoff)
472474
let client2 = new_client(&address).await;
473-
let result = client2.get("eph/key1".to_string()).await;
475+
let mut found_deleted = false;
476+
for attempt in 0..10 {
477+
tokio::time::sleep(Duration::from_millis(500 * (attempt + 1))).await;
478+
let result = client2.get("eph/key1".to_string()).await;
479+
if matches!(result, Err(OxiaError::KeyNotFound())) {
480+
found_deleted = true;
481+
break;
482+
}
483+
}
474484
assert!(
475-
matches!(result, Err(OxiaError::KeyNotFound())),
476-
"Expected KeyNotFound for ephemeral key after client shutdown, got: {:?}",
477-
result
485+
found_deleted,
486+
"Expected ephemeral key to be deleted after client shutdown"
478487
);
479488

480489
client2.shutdown().await.unwrap();

0 commit comments

Comments
 (0)