Skip to content

Commit de075b9

Browse files
authored
fix(mock): work with advanced time (#165)
1 parent 1e9731f commit de075b9

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
<!-- next-header -->
88

99
## [Unreleased] - ReleaseDate
10+
### Fixed
11+
- mock: work with the advanced time via `tokio::time::advance()` ([#165]).
12+
13+
[#165]: https://github.com/ClickHouse/clickhouse-rs/pull/165
1014

1115
## [0.13.0] - 2024-09-27
1216
### Added

src/test/mock.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
use bytes::Bytes;
1111
use http_body_util::{BodyExt as _, Full};
1212
use hyper::{body::Incoming, server::conn, service, Request, Response, StatusCode};
13-
use hyper_util::rt::{TokioIo, TokioTimer};
13+
use hyper_util::rt::TokioIo;
1414
use tokio::{net::TcpListener, task::AbortHandle};
1515

1616
use super::{Handler, HandlerFn};
@@ -127,7 +127,8 @@ async fn server(listener: TcpListener, shared: Arc<Mutex<Shared>>) {
127127
};
128128

129129
let serving = conn::http1::Builder::new()
130-
.timer(TokioTimer::new())
130+
// N.B.: We set no timeouts here because it works incorrectly with
131+
// advanced time via `tokio::time::advance(duration)`.
131132
.keep_alive(false)
132133
.serve_connection(
133134
TokioIo::new(stream),

tests/it/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use clickhouse::sql::Identifier;
2-
use clickhouse::{sql, Client, Row};
1+
use clickhouse::{sql, sql::Identifier, Client, Row};
32
use serde::{Deserialize, Serialize};
43

54
macro_rules! prepare_database {
@@ -60,6 +59,7 @@ mod cursor_error;
6059
mod insert;
6160
mod inserter;
6261
mod ip;
62+
mod mock;
6363
mod nested;
6464
mod query;
6565
mod time;

tests/it/mock.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![cfg(feature = "test-util")]
2+
3+
use std::time::Duration;
4+
5+
use clickhouse::{test, Client};
6+
7+
use crate::SimpleRow;
8+
9+
async fn test_provide() {
10+
let mock = test::Mock::new();
11+
let client = Client::default().with_url(mock.url());
12+
let expected = vec![SimpleRow::new(1, "one"), SimpleRow::new(2, "two")];
13+
mock.add(test::handlers::provide(&expected));
14+
15+
let actual = crate::fetch_rows::<SimpleRow>(&client, "doesn't matter").await;
16+
assert_eq!(actual, expected);
17+
}
18+
19+
#[tokio::test]
20+
async fn provide() {
21+
test_provide().await;
22+
23+
// Same but with the advanced time.
24+
tokio::time::pause();
25+
tokio::time::advance(Duration::from_secs(100_000)).await;
26+
test_provide().await;
27+
}

0 commit comments

Comments
 (0)