From 5b42b65d9b2b874ffa9fdb95cc4050c393c2c040 Mon Sep 17 00:00:00 2001 From: Paul Loyd Date: Sat, 28 Sep 2024 18:47:10 +0400 Subject: [PATCH] fix(mock): work with advanced time --- CHANGELOG.md | 4 ++++ src/test/mock.rs | 5 +++-- tests/it/main.rs | 4 ++-- tests/it/mock.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 tests/it/mock.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 64806f48..81e9ba7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Fixed +- mock: work with the advanced time via `tokio::time::advance()` ([#165]). + +[#165]: https://github.com/ClickHouse/clickhouse-rs/pull/165 ## [0.13.0] - 2024-09-27 ### Added diff --git a/src/test/mock.rs b/src/test/mock.rs index 35b5dec2..41636d45 100644 --- a/src/test/mock.rs +++ b/src/test/mock.rs @@ -10,7 +10,7 @@ use std::{ use bytes::Bytes; use http_body_util::{BodyExt as _, Full}; use hyper::{body::Incoming, server::conn, service, Request, Response, StatusCode}; -use hyper_util::rt::{TokioIo, TokioTimer}; +use hyper_util::rt::TokioIo; use tokio::{net::TcpListener, task::AbortHandle}; use super::{Handler, HandlerFn}; @@ -127,7 +127,8 @@ async fn server(listener: TcpListener, shared: Arc>) { }; let serving = conn::http1::Builder::new() - .timer(TokioTimer::new()) + // N.B.: We set no timeouts here because it works incorrectly with + // advanced time via `tokio::time::advance(duration)`. .keep_alive(false) .serve_connection( TokioIo::new(stream), diff --git a/tests/it/main.rs b/tests/it/main.rs index 75349175..647f6206 100644 --- a/tests/it/main.rs +++ b/tests/it/main.rs @@ -1,5 +1,4 @@ -use clickhouse::sql::Identifier; -use clickhouse::{sql, Client, Row}; +use clickhouse::{sql, sql::Identifier, Client, Row}; use serde::{Deserialize, Serialize}; macro_rules! prepare_database { @@ -60,6 +59,7 @@ mod cursor_error; mod insert; mod inserter; mod ip; +mod mock; mod nested; mod query; mod time; diff --git a/tests/it/mock.rs b/tests/it/mock.rs new file mode 100644 index 00000000..2db04537 --- /dev/null +++ b/tests/it/mock.rs @@ -0,0 +1,27 @@ +#![cfg(feature = "test-util")] + +use std::time::Duration; + +use clickhouse::{test, Client}; + +use crate::SimpleRow; + +async fn test_provide() { + let mock = test::Mock::new(); + let client = Client::default().with_url(mock.url()); + let expected = vec![SimpleRow::new(1, "one"), SimpleRow::new(2, "two")]; + mock.add(test::handlers::provide(&expected)); + + let actual = crate::fetch_rows::(&client, "doesn't matter").await; + assert_eq!(actual, expected); +} + +#[tokio::test] +async fn provide() { + test_provide().await; + + // Same but with the advanced time. + tokio::time::pause(); + tokio::time::advance(Duration::from_secs(100_000)).await; + test_provide().await; +}