Skip to content

Commit

Permalink
fix(mock): work with advanced time (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
loyd authored Sep 29, 2024
1 parent 1e9731f commit de075b9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- next-header -->

## [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
Expand Down
5 changes: 3 additions & 2 deletions src/test/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -127,7 +127,8 @@ async fn server(listener: TcpListener, shared: Arc<Mutex<Shared>>) {
};

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),
Expand Down
4 changes: 2 additions & 2 deletions tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -60,6 +59,7 @@ mod cursor_error;
mod insert;
mod inserter;
mod ip;
mod mock;
mod nested;
mod query;
mod time;
Expand Down
27 changes: 27 additions & 0 deletions tests/it/mock.rs
Original file line number Diff line number Diff line change
@@ -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::<SimpleRow>(&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;
}

0 comments on commit de075b9

Please sign in to comment.