From 2afde65cf8ed68752c9d154a04a61b7abdbfda36 Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 01:29:40 +0200
Subject: [PATCH 01/13] add reqwest client
---
CHANGELOG.md | 4 +
influxdb/Cargo.toml | 27 ++++---
influxdb/src/client/mod.rs | 75 +++++++++++++------
.../src/integrations/serde_integration/mod.rs | 39 +++++-----
influxdb/src/lib.rs | 26 +++++--
5 files changed, 113 insertions(+), 58 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 920eb58..dcfcc0b 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]
+### Added
+
+- reqwest-based http client (enabled by default)
+
## [0.4.0] - 2021-03-08
### Fixed
diff --git a/influxdb/Cargo.toml b/influxdb/Cargo.toml
index 6ebbf5a..c07bf8f 100644
--- a/influxdb/Cargo.toml
+++ b/influxdb/Cargo.toml
@@ -18,24 +18,31 @@ travis-ci = { repository = "Empty2k12/influxdb-rust", branch = "master" }
[dependencies]
chrono = { version = "0.4.11", features = ["serde"] }
futures = "0.3.4"
-lazy_static = "1.4.0"
+http = "0.2.4"
influxdb_derive = { version = "0.4.0", optional = true }
+lazy_static = "1.4.0"
regex = "1.3.5"
-surf = { version = "2.2.0", default-features = false }
+reqwest = { version = "0.11.4", default-features = false, optional = true }
+surf = { version = "2.2.0", default-features = false, optional = true }
serde = { version = "1.0.104", features = ["derive"], optional = true }
serde_json = { version = "1.0.48", optional = true }
thiserror = "1.0"
[features]
-use-serde = ["serde", "serde_json"]
-curl-client = ["surf/curl-client"]
-h1-client = ["surf/h1-client"]
-h1-client-rustls = ["surf/h1-client-rustls"]
-hyper-client = ["surf/hyper-client"]
-wasm-client = ["surf/wasm-client"]
-default = ["use-serde", "hyper-client"]
+default = ["use-serde", "reqwest-client-rustls"]
derive = ["influxdb_derive"]
+use-serde = ["serde", "serde_json"]
+
+# http clients
+curl-client = ["surf", "surf/curl-client"]
+h1-client = ["surf", "surf/h1-client"]
+h1-client-rustls = ["surf", "surf/h1-client-rustls"]
+hyper-client = ["surf", "surf/hyper-client"]
+reqwest-client = ["reqwest", "reqwest/native-tls-alpn"]
+reqwest-client-rustls = ["reqwest", "reqwest/rustls-tls-webpki-roots"]
+wasm-client = ["surf", "surf/wasm-client"]
[dev-dependencies]
async-std = { version = "1.6.5", features = ["attributes"] }
-tokio = { version = "0.2.22", features = ["rt-threaded", "macros"] }
\ No newline at end of file
+tokio02 = { package = "tokio", version = "0.2.22", features = ["rt-threaded", "macros"] }
+tokio = { version = "1.7", features = ["rt"] }
diff --git a/influxdb/src/client/mod.rs b/influxdb/src/client/mod.rs
index 468b0ae..41ac198 100644
--- a/influxdb/src/client/mod.rs
+++ b/influxdb/src/client/mod.rs
@@ -16,7 +16,11 @@
//! ```
use futures::prelude::*;
-use surf::{self, Client as SurfClient, StatusCode};
+use http::StatusCode;
+#[cfg(feature = "reqwest")]
+use reqwest::{Client as HttpClient, Response as HttpResponse};
+#[cfg(feature = "surf")]
+use surf::{Client as HttpClient, Response as HttpResponse};
use crate::query::QueryType;
use crate::Error;
@@ -29,7 +33,7 @@ use std::sync::Arc;
pub struct Client {
pub(crate) url: Arc,
pub(crate) parameters: Arc>,
- pub(crate) client: SurfClient,
+ pub(crate) client: HttpClient,
}
impl Client {
@@ -57,7 +61,7 @@ impl Client {
Client {
url: Arc::new(url.into()),
parameters: Arc::new(parameters),
- client: SurfClient::new(),
+ client: HttpClient::new(),
}
}
@@ -112,10 +116,25 @@ impl Client {
error: format!("{}", err),
})?;
- let build = res.header("X-Influxdb-Build").unwrap().as_str();
- let version = res.header("X-Influxdb-Version").unwrap().as_str();
+ const BUILD_HEADER: &str = "X-Influxdb-Build";
+ const VERSION_HEADER: &str = "X-Influxdb-Version";
- Ok((build.to_owned(), version.to_owned()))
+ #[cfg(feature = "reqwest")]
+ let (build, version) = {
+ let hdrs = res.headers();
+ (
+ hdrs.get(BUILD_HEADER).and_then(|value| value.to_str().ok()),
+ hdrs.get(VERSION_HEADER)
+ .and_then(|value| value.to_str().ok()),
+ )
+ };
+
+ #[cfg(feature = "surf")]
+ let build = res.header(BUILD_HEADER).map(|value| value.as_str());
+ #[cfg(feature = "surf")]
+ let version = res.header(VERSION_HEADER).map(|value| value.as_str());
+
+ Ok((build.unwrap().to_owned(), version.unwrap().to_owned()))
}
/// Sends a [`ReadQuery`](crate::ReadQuery) or [`WriteQuery`](crate::WriteQuery) to the InfluxDB Server.
@@ -184,32 +203,31 @@ impl Client {
self.client.post(url).body(query.get()).query(¶meters)
}
- }
- .map_err(|err| Error::UrlConstructionError {
+ };
+
+ #[cfg(feature = "surf")]
+ let request_builder = request_builder.map_err(|err| Error::UrlConstructionError {
error: err.to_string(),
})?;
- let request = request_builder.build();
- let mut res = self
- .client
- .send(request)
+ let res = request_builder
+ .send()
.map_err(|err| Error::ConnectionError {
error: err.to_string(),
})
.await?;
+ check_status(&res)?;
- match res.status() {
- StatusCode::Unauthorized => return Err(Error::AuthorizationError),
- StatusCode::Forbidden => return Err(Error::AuthenticationError),
- _ => {}
- }
+ #[cfg(feature = "reqwest")]
+ let body = res.text();
+ #[cfg(feature = "surf")]
+ let mut res = res;
+ #[cfg(feature = "surf")]
+ let body = res.body_string();
- let s = res
- .body_string()
- .await
- .map_err(|_| Error::DeserializationError {
- error: "response could not be converted to UTF-8".to_string(),
- })?;
+ let s = body.await.map_err(|_| Error::DeserializationError {
+ error: "response could not be converted to UTF-8".to_string(),
+ })?;
// todo: improve error parsing without serde
if s.contains("\"error\"") {
@@ -222,6 +240,17 @@ impl Client {
}
}
+pub(crate) fn check_status(res: &HttpResponse) -> Result<(), Error> {
+ let status = res.status();
+ if status == StatusCode::UNAUTHORIZED.as_u16() {
+ Err(Error::AuthorizationError)
+ } else if status == StatusCode::FORBIDDEN.as_u16() {
+ Err(Error::AuthenticationError)
+ } else {
+ Ok(())
+ }
+}
+
#[cfg(test)]
mod tests {
use super::Client;
diff --git a/influxdb/src/integrations/serde_integration/mod.rs b/influxdb/src/integrations/serde_integration/mod.rs
index 3a734af..00390b6 100644
--- a/influxdb/src/integrations/serde_integration/mod.rs
+++ b/influxdb/src/integrations/serde_integration/mod.rs
@@ -48,11 +48,9 @@
mod de;
-use surf::StatusCode;
-
use serde::{de::DeserializeOwned, Deserialize};
-use crate::{Client, Error, Query, ReadQuery};
+use crate::{Client, Error, Query, ReadQuery, client::check_status};
#[derive(Deserialize)]
#[doc(hidden)]
@@ -143,30 +141,31 @@ impl Client {
let url = &format!("{}/query", &self.url);
let mut parameters = self.parameters.as_ref().clone();
parameters.insert("q", read_query);
- let request = self
+ let request_builder = self
.client
.get(url)
- .query(¶meters)
- .map_err(|err| Error::UrlConstructionError {
- error: err.to_string(),
- })?
- .build();
+ .query(¶meters);
- let mut res = self
- .client
- .send(request)
+ #[cfg(feature = "surf")]
+ let request_builder = request_builder.map_err(|err| Error::UrlConstructionError {
+ error: err.to_string(),
+ })?;
+
+ let res = request_builder.send()
.await
.map_err(|err| Error::ConnectionError {
error: err.to_string(),
})?;
-
- match res.status() {
- StatusCode::Unauthorized => return Err(Error::AuthorizationError),
- StatusCode::Forbidden => return Err(Error::AuthenticationError),
- _ => {}
- }
-
- let body = res.body_bytes().await.map_err(|err| Error::ProtocolError {
+ check_status(&res)?;
+
+ #[cfg(feature = "reqwest")]
+ let body = res.bytes();
+ #[cfg(feature = "surf")]
+ let mut res = res;
+ #[cfg(feature = "surf")]
+ let body = res.body_bytes();
+
+ let body = body.await.map_err(|err| Error::ProtocolError {
error: err.to_string(),
})?;
diff --git a/influxdb/src/lib.rs b/influxdb/src/lib.rs
index 117f07f..bfd207d 100644
--- a/influxdb/src/lib.rs
+++ b/influxdb/src/lib.rs
@@ -30,8 +30,8 @@
//! use influxdb::InfluxDbWriteable;
//! use chrono::{DateTime, Utc};
//!
-//! #[async_std::main]
-//! // or #[tokio::main] if you prefer
+//! #[tokio::main]
+//! // or #[async_std::main] if you prefer
//! async fn main() {
//! // Connect to db `test` on `http://localhost:8086`
//! let client = Client::new("http://localhost:8086", "test");
@@ -69,11 +69,21 @@
//!
//! # Choice of HTTP backend
//!
-//! To communicate with InfluxDB, you can choose the HTTP backend to be used configuring the appropriate feature:
+//! To communicate with InfluxDB, you can choose the HTTP backend to be used configuring the appropriate feature. We recommend sticking with the default reqwest-based client, unless you really need async-std compatibility.
//!
-//! - **[hyper](https://github.com/hyperium/hyper)** (used by default)
+//! - **[hyper](https://github.com/hyperium/hyper)** (through reqwest, used by default), with [rustls](https://github.com/ctz/rustls)
+//! ```toml
+//! influxdb = { version = "0.4.0", features = ["derive"] }
+//! ```
+//!
+//! - **[hyper](https://github.com/hyperium/hyper)** (through reqwest), with native TLS (OpenSSL)
+//! ```toml
+//! influxdb = { version = "0.4.0", default-features = false, features = ["derive", "use-serde", "reqwest-client"] }
+//! ```
+//!
+//! - **[hyper](https://github.com/hyperium/hyper)** (through surf), use this if you need tokio 0.2 compatibility
//! ```toml
-//! influxdb = { version = "0.4.0", features = ["derive"] }
+//! influxdb = { version = "0.4.0", default-features = false, features = ["derive", "use-serde", "curl-client"] }
//! ```
//! - **[curl](https://github.com/alexcrichton/curl-rust)**, using [libcurl](https://curl.se/libcurl/)
//! ```toml
@@ -99,6 +109,12 @@
#![allow(clippy::needless_doctest_main)]
#![allow(clippy::needless_lifetimes)] // False positive in client/mod.rs query fn
+#[cfg(all(feature = "reqwest", feature = "surf"))]
+compile_error!("You need to choose between reqwest and surf; enabling both is not supported");
+
+#[cfg(not(any(feature = "reqwest", feature = "surf")))]
+compile_error!("You need to choose an http client; consider not disabling default features");
+
mod client;
mod error;
mod query;
From 01b4c876d8a3ae3262b217cff9adb8ff9d30e982 Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 01:35:00 +0200
Subject: [PATCH 02/13] ci: add reqwest clients
---
.github/workflows/rust.yml | 2 +-
influxdb/Cargo.toml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 209fcae..76d5c40 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -50,7 +50,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- http-backend: [curl-client, h1-client, h1-client-rustls, hyper-client]
+ http-backend: [curl-client, h1-client, h1-client-rustls, hyper-client, reqwest-client, reqwest-client-rustls]
services:
influxdb:
image: influxdb:1.8
diff --git a/influxdb/Cargo.toml b/influxdb/Cargo.toml
index c07bf8f..8aee7f4 100644
--- a/influxdb/Cargo.toml
+++ b/influxdb/Cargo.toml
@@ -45,4 +45,4 @@ wasm-client = ["surf", "surf/wasm-client"]
[dev-dependencies]
async-std = { version = "1.6.5", features = ["attributes"] }
tokio02 = { package = "tokio", version = "0.2.22", features = ["rt-threaded", "macros"] }
-tokio = { version = "1.7", features = ["rt"] }
+tokio = { version = "1.7", features = ["macros", "rt"] }
From 147416f0502ccc4f57e65c7721d080a1343e1050 Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 01:36:01 +0200
Subject: [PATCH 03/13] ci: temporarily disable branch restriction
---
.github/workflows/rust.yml | 1 -
1 file changed, 1 deletion(-)
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 76d5c40..284c13b 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -3,7 +3,6 @@ name: Rust
on:
push:
branches:
- - master
pull_request:
jobs:
From ce2ddc99fe16cbfbc607626cabc9d166f40035fa Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 01:39:13 +0200
Subject: [PATCH 04/13] my nightly rustfmt was bugged
---
influxdb/src/integrations/serde_integration/mod.rs | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/influxdb/src/integrations/serde_integration/mod.rs b/influxdb/src/integrations/serde_integration/mod.rs
index 00390b6..e0b6508 100644
--- a/influxdb/src/integrations/serde_integration/mod.rs
+++ b/influxdb/src/integrations/serde_integration/mod.rs
@@ -50,7 +50,7 @@ mod de;
use serde::{de::DeserializeOwned, Deserialize};
-use crate::{Client, Error, Query, ReadQuery, client::check_status};
+use crate::{client::check_status, Client, Error, Query, ReadQuery};
#[derive(Deserialize)]
#[doc(hidden)]
@@ -141,17 +141,15 @@ impl Client {
let url = &format!("{}/query", &self.url);
let mut parameters = self.parameters.as_ref().clone();
parameters.insert("q", read_query);
- let request_builder = self
- .client
- .get(url)
- .query(¶meters);
+ let request_builder = self.client.get(url).query(¶meters);
#[cfg(feature = "surf")]
let request_builder = request_builder.map_err(|err| Error::UrlConstructionError {
error: err.to_string(),
})?;
- let res = request_builder.send()
+ let res = request_builder
+ .send()
.await
.map_err(|err| Error::ConnectionError {
error: err.to_string(),
@@ -164,7 +162,7 @@ impl Client {
let mut res = res;
#[cfg(feature = "surf")]
let body = res.body_bytes();
-
+
let body = body.await.map_err(|err| Error::ProtocolError {
error: err.to_string(),
})?;
From c40b8a11021899f073b291cdc05671d2eaa19fef Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 01:41:59 +0200
Subject: [PATCH 05/13] bump msrv to 1.46: socket2 crate uses match in const fn
---
.github/workflows/rust.yml | 2 +-
README.tpl | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 284c13b..ba09ab8 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -33,7 +33,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
- rust_release: [1.45, stable, nightly]
+ rust_release: [1.46, stable, nightly]
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
diff --git a/README.tpl b/README.tpl
index 0647cd3..4814b9c 100644
--- a/README.tpl
+++ b/README.tpl
@@ -25,11 +25,11 @@
-
-
+
+
{{readme}}
-@ 2020 Gero Gerke and [contributors](https://github.com/Empty2k12/influxdb-rust/graphs/contributors).
\ No newline at end of file
+@ 2020 Gero Gerke and [contributors](https://github.com/Empty2k12/influxdb-rust/graphs/contributors).
From c2e134070501589074bfb3ccb7200503e0a1be73 Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 01:50:30 +0200
Subject: [PATCH 06/13] ci: do not use --all-features
---
.github/workflows/rust.yml | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index ba09ab8..da37e83 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -25,8 +25,10 @@ jobs:
components: "rustfmt,clippy"
- name: Check code formatting
run: cargo fmt --all -- --check
- - name: Check Clippy lints
- run: cargo clippy --all-targets --all-features -- -D warnings
+ - name: Check Clippy lints (reqwest)
+ run: cargo clippy --all-targets --no-default-features --features use-serde,derive,reqwest-client -- -D warnings
+ - name: Check Clippy lints (surf)
+ run: cargo clippy --all-targets --no-default-features --features use-serde,derive,hyper-client -- -D warnings
compile:
name: Compile (${{ matrix.rust_release }}/${{ matrix.os }})
@@ -121,7 +123,7 @@ jobs:
cargo tarpaulin -v \
--target-dir target/tarpaulin \
--workspace \
- --all-features \
+ --features use-serde,derive \
--exclude-files 'derive/*' \
--exclude-files 'target/*' \
--ignore-panics --ignore-tests \
From c9ad6c71e6274681fdfbffeb398d7cb9a9a961fb Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 01:51:38 +0200
Subject: [PATCH 07/13] update readme
---
README.md | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index 96b4aa1..908f17d 100644
--- a/README.md
+++ b/README.md
@@ -25,8 +25,8 @@
-
-
+
+
@@ -62,8 +62,8 @@ use influxdb::{Client, Query, Timestamp};
use influxdb::InfluxDbWriteable;
use chrono::{DateTime, Utc};
-#[async_std::main]
-// or #[tokio::main] if you prefer
+#[tokio::main]
+// or #[async_std::main] if you prefer
async fn main() {
// Connect to db `test` on `http://localhost:8086`
let client = Client::new("http://localhost:8086", "test");
@@ -101,11 +101,21 @@ in the repository.
## Choice of HTTP backend
-To communicate with InfluxDB, you can choose the HTTP backend to be used configuring the appropriate feature:
+To communicate with InfluxDB, you can choose the HTTP backend to be used configuring the appropriate feature. We recommend sticking with the default reqwest-based client, unless you really need async-std compatibility.
-- **[hyper](https://github.com/hyperium/hyper)** (used by default)
+- **[hyper](https://github.com/hyperium/hyper)** (through reqwest, used by default), with [rustls](https://github.com/ctz/rustls)
+ ```toml
+ influxdb = { version = "0.4.0", features = ["derive"] }
+ ```
+
+- **[hyper](https://github.com/hyperium/hyper)** (through reqwest), with native TLS (OpenSSL)
+ ```toml
+ influxdb = { version = "0.4.0", default-features = false, features = ["derive", "use-serde", "reqwest-client"] }
+ ```
+
+- **[hyper](https://github.com/hyperium/hyper)** (through surf), use this if you need tokio 0.2 compatibility
```toml
- influxdb = { version = "0.4.0", features = ["derive"] }
+ influxdb = { version = "0.4.0", default-features = false, features = ["derive", "use-serde", "curl-client"] }
```
- **[curl](https://github.com/alexcrichton/curl-rust)**, using [libcurl](https://curl.se/libcurl/)
```toml
From cebc42eb930e136c5f0ceacd0645428b6f5014d2 Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 01:54:41 +0200
Subject: [PATCH 08/13] use the correct tokio rt feature
---
influxdb/Cargo.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/influxdb/Cargo.toml b/influxdb/Cargo.toml
index 8aee7f4..0f2ba6f 100644
--- a/influxdb/Cargo.toml
+++ b/influxdb/Cargo.toml
@@ -45,4 +45,4 @@ wasm-client = ["surf", "surf/wasm-client"]
[dev-dependencies]
async-std = { version = "1.6.5", features = ["attributes"] }
tokio02 = { package = "tokio", version = "0.2.22", features = ["rt-threaded", "macros"] }
-tokio = { version = "1.7", features = ["macros", "rt"] }
+tokio = { version = "1.7", features = ["macros", "rt-multi-thread"] }
From dd8b574b6b14431dc43ae63d1aaa356237b8d207 Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 02:03:47 +0200
Subject: [PATCH 09/13] test with tokio by default
---
influxdb/tests/derive_integration_tests.rs | 6 ++--
influxdb/tests/integration_tests.rs | 41 ++++++++++++++--------
2 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/influxdb/tests/derive_integration_tests.rs b/influxdb/tests/derive_integration_tests.rs
index 463fed9..d7c738f 100644
--- a/influxdb/tests/derive_integration_tests.rs
+++ b/influxdb/tests/derive_integration_tests.rs
@@ -51,7 +51,8 @@ fn test_build_query() {
/// INTEGRATION TEST
///
/// This integration tests that writing data and retrieving the data again is working
-#[async_std::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(not(tarpaulin_include))]
async fn test_derive_simple_write() {
const TEST_NAME: &str = "test_derive_simple_write";
@@ -82,7 +83,8 @@ async fn test_derive_simple_write() {
/// This integration tests that writing data and retrieving the data again is working
#[cfg(feature = "derive")]
#[cfg(feature = "use-serde")]
-#[async_std::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(not(tarpaulin_include))]
async fn test_write_and_read_option() {
const TEST_NAME: &str = "test_write_and_read_option";
diff --git a/influxdb/tests/integration_tests.rs b/influxdb/tests/integration_tests.rs
index d92f405..27ec9c7 100644
--- a/influxdb/tests/integration_tests.rs
+++ b/influxdb/tests/integration_tests.rs
@@ -13,7 +13,7 @@ use influxdb::{Client, Error, Query, Timestamp};
///
/// This test case tests whether the InfluxDB server can be connected to and gathers info about it - tested with async_std
#[async_std::test]
-#[cfg(not(tarpaulin_include))]
+#[cfg(not(any(tarpaulin_include, feature = "reqwest")))]
async fn test_ping_influx_db_async_std() {
let client = create_client("notusedhere");
let result = client.ping().await;
@@ -29,7 +29,8 @@ async fn test_ping_influx_db_async_std() {
/// INTEGRATION TEST
///
/// This test case tests whether the InfluxDB server can be connected to and gathers info about it * tested with tokio
-#[tokio::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(not(tarpaulin_include))]
async fn test_ping_influx_db_tokio() {
let client = create_client("notusedhere");
@@ -46,7 +47,8 @@ async fn test_ping_influx_db_tokio() {
/// INTEGRATION TEST
///
/// This test case tests connection error
-#[async_std::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(not(tarpaulin_include))]
async fn test_connection_error() {
let test_name = "test_connection_error";
@@ -67,7 +69,8 @@ async fn test_connection_error() {
/// INTEGRATION TEST
///
/// This test case tests the Authentication
-#[async_std::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(not(tarpaulin_include))]
async fn test_authed_write_and_read() {
const TEST_NAME: &str = "test_authed_write_and_read";
@@ -115,7 +118,8 @@ async fn test_authed_write_and_read() {
/// INTEGRATION TEST
///
/// This test case tests the Authentication
-#[async_std::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(not(tarpaulin_include))]
async fn test_wrong_authed_write_and_read() {
const TEST_NAME: &str = "test_wrong_authed_write_and_read";
@@ -185,7 +189,8 @@ async fn test_wrong_authed_write_and_read() {
/// INTEGRATION TEST
///
/// This test case tests the Authentication
-#[async_std::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(not(tarpaulin_include))]
async fn test_non_authed_write_and_read() {
const TEST_NAME: &str = "test_non_authed_write_and_read";
@@ -240,7 +245,8 @@ async fn test_non_authed_write_and_read() {
/// INTEGRATION TEST
///
/// This integration tests that writing data and retrieving the data again is working
-#[async_std::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(not(tarpaulin_include))]
async fn test_write_and_read_field() {
const TEST_NAME: &str = "test_write_field";
@@ -273,7 +279,8 @@ async fn test_write_and_read_field() {
/// INTEGRATION TEST
///
/// This integration tests that writing data and retrieving the data again is working
-#[async_std::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(feature = "use-serde")]
#[cfg(not(tarpaulin_include))]
async fn test_write_and_read_option() {
@@ -335,7 +342,8 @@ async fn test_write_and_read_option() {
///
/// This test case tests whether JSON can be decoded from a InfluxDB response and whether that JSON
/// is equal to the data which was written to the database
-#[async_std::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(feature = "use-serde")]
#[cfg(not(tarpaulin_include))]
async fn test_json_query() {
@@ -386,8 +394,9 @@ async fn test_json_query() {
/// INTEGRATION TEST
///
/// This test case tests whether the response to a GROUP BY can be parsed by
-// deserialize_next_tagged into a tags struct
-#[async_std::test]
+/// deserialize_next_tagged into a tags struct
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(feature = "use-serde")]
#[cfg(not(tarpaulin_include))]
async fn test_json_query_tagged() {
@@ -451,8 +460,8 @@ async fn test_json_query_tagged() {
///
/// This test case tests whether JSON can be decoded from a InfluxDB response and wether that JSON
/// is equal to the data which was written to the database
-/// (tested with tokio)
-#[tokio::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(feature = "use-serde")]
#[cfg(not(tarpaulin_include))]
async fn test_json_query_vec() {
@@ -503,7 +512,8 @@ async fn test_json_query_vec() {
/// INTEGRATION TEST
///
/// This integration test tests whether using the wrong query method fails building the query
-#[async_std::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(feature = "use-serde")]
#[cfg(not(tarpaulin_include))]
async fn test_serde_multi_query() {
@@ -580,7 +590,8 @@ async fn test_serde_multi_query() {
/// INTEGRATION TEST
///
/// This integration test tests whether using the wrong query method fails building the query
-#[async_std::test]
+#[cfg_attr(feature = "surf", tokio02::test)]
+#[cfg_attr(feature = "reqwest", tokio::test)]
#[cfg(feature = "use-serde")]
#[cfg(not(tarpaulin_include))]
async fn test_wrong_query_errors() {
From a7ffaadd2a0c8f647d2b4795e6140d7f7cb7b12e Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 02:10:14 +0200
Subject: [PATCH 10/13] Revert "test with tokio by default"
This reverts commit dd8b574b6b14431dc43ae63d1aaa356237b8d207.
---
influxdb/tests/derive_integration_tests.rs | 6 ++--
influxdb/tests/integration_tests.rs | 39 ++++++++--------------
2 files changed, 16 insertions(+), 29 deletions(-)
diff --git a/influxdb/tests/derive_integration_tests.rs b/influxdb/tests/derive_integration_tests.rs
index d7c738f..463fed9 100644
--- a/influxdb/tests/derive_integration_tests.rs
+++ b/influxdb/tests/derive_integration_tests.rs
@@ -51,8 +51,7 @@ fn test_build_query() {
/// INTEGRATION TEST
///
/// This integration tests that writing data and retrieving the data again is working
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[async_std::test]
#[cfg(not(tarpaulin_include))]
async fn test_derive_simple_write() {
const TEST_NAME: &str = "test_derive_simple_write";
@@ -83,8 +82,7 @@ async fn test_derive_simple_write() {
/// This integration tests that writing data and retrieving the data again is working
#[cfg(feature = "derive")]
#[cfg(feature = "use-serde")]
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[async_std::test]
#[cfg(not(tarpaulin_include))]
async fn test_write_and_read_option() {
const TEST_NAME: &str = "test_write_and_read_option";
diff --git a/influxdb/tests/integration_tests.rs b/influxdb/tests/integration_tests.rs
index 27ec9c7..4167588 100644
--- a/influxdb/tests/integration_tests.rs
+++ b/influxdb/tests/integration_tests.rs
@@ -13,7 +13,7 @@ use influxdb::{Client, Error, Query, Timestamp};
///
/// This test case tests whether the InfluxDB server can be connected to and gathers info about it - tested with async_std
#[async_std::test]
-#[cfg(not(any(tarpaulin_include, feature = "reqwest")))]
+#[cfg(not(tarpaulin_include))]
async fn test_ping_influx_db_async_std() {
let client = create_client("notusedhere");
let result = client.ping().await;
@@ -29,8 +29,7 @@ async fn test_ping_influx_db_async_std() {
/// INTEGRATION TEST
///
/// This test case tests whether the InfluxDB server can be connected to and gathers info about it * tested with tokio
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[tokio::test]
#[cfg(not(tarpaulin_include))]
async fn test_ping_influx_db_tokio() {
let client = create_client("notusedhere");
@@ -47,8 +46,7 @@ async fn test_ping_influx_db_tokio() {
/// INTEGRATION TEST
///
/// This test case tests connection error
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[async_std::test]
#[cfg(not(tarpaulin_include))]
async fn test_connection_error() {
let test_name = "test_connection_error";
@@ -69,8 +67,7 @@ async fn test_connection_error() {
/// INTEGRATION TEST
///
/// This test case tests the Authentication
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[async_std::test]
#[cfg(not(tarpaulin_include))]
async fn test_authed_write_and_read() {
const TEST_NAME: &str = "test_authed_write_and_read";
@@ -118,8 +115,7 @@ async fn test_authed_write_and_read() {
/// INTEGRATION TEST
///
/// This test case tests the Authentication
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[async_std::test]
#[cfg(not(tarpaulin_include))]
async fn test_wrong_authed_write_and_read() {
const TEST_NAME: &str = "test_wrong_authed_write_and_read";
@@ -189,8 +185,7 @@ async fn test_wrong_authed_write_and_read() {
/// INTEGRATION TEST
///
/// This test case tests the Authentication
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[async_std::test]
#[cfg(not(tarpaulin_include))]
async fn test_non_authed_write_and_read() {
const TEST_NAME: &str = "test_non_authed_write_and_read";
@@ -245,8 +240,7 @@ async fn test_non_authed_write_and_read() {
/// INTEGRATION TEST
///
/// This integration tests that writing data and retrieving the data again is working
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[async_std::test]
#[cfg(not(tarpaulin_include))]
async fn test_write_and_read_field() {
const TEST_NAME: &str = "test_write_field";
@@ -279,8 +273,7 @@ async fn test_write_and_read_field() {
/// INTEGRATION TEST
///
/// This integration tests that writing data and retrieving the data again is working
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[async_std::test]
#[cfg(feature = "use-serde")]
#[cfg(not(tarpaulin_include))]
async fn test_write_and_read_option() {
@@ -342,8 +335,7 @@ async fn test_write_and_read_option() {
///
/// This test case tests whether JSON can be decoded from a InfluxDB response and whether that JSON
/// is equal to the data which was written to the database
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[async_std::test]
#[cfg(feature = "use-serde")]
#[cfg(not(tarpaulin_include))]
async fn test_json_query() {
@@ -395,8 +387,7 @@ async fn test_json_query() {
///
/// This test case tests whether the response to a GROUP BY can be parsed by
/// deserialize_next_tagged into a tags struct
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[async_std::test]
#[cfg(feature = "use-serde")]
#[cfg(not(tarpaulin_include))]
async fn test_json_query_tagged() {
@@ -460,8 +451,8 @@ async fn test_json_query_tagged() {
///
/// This test case tests whether JSON can be decoded from a InfluxDB response and wether that JSON
/// is equal to the data which was written to the database
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+/// (tested with tokio)
+#[tokio::test]
#[cfg(feature = "use-serde")]
#[cfg(not(tarpaulin_include))]
async fn test_json_query_vec() {
@@ -512,8 +503,7 @@ async fn test_json_query_vec() {
/// INTEGRATION TEST
///
/// This integration test tests whether using the wrong query method fails building the query
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[async_std::test]
#[cfg(feature = "use-serde")]
#[cfg(not(tarpaulin_include))]
async fn test_serde_multi_query() {
@@ -590,8 +580,7 @@ async fn test_serde_multi_query() {
/// INTEGRATION TEST
///
/// This integration test tests whether using the wrong query method fails building the query
-#[cfg_attr(feature = "surf", tokio02::test)]
-#[cfg_attr(feature = "reqwest", tokio::test)]
+#[async_std::test]
#[cfg(feature = "use-serde")]
#[cfg(not(tarpaulin_include))]
async fn test_wrong_query_errors() {
From aa321fae7ea2b89476a0c6d6805689478ef070f4 Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 02:12:43 +0200
Subject: [PATCH 11/13] enable async-std/tokio compatibility layer
---
influxdb/Cargo.toml | 3 +--
influxdb/tests/integration_tests.rs | 4 ++--
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/influxdb/Cargo.toml b/influxdb/Cargo.toml
index 0f2ba6f..b493399 100644
--- a/influxdb/Cargo.toml
+++ b/influxdb/Cargo.toml
@@ -43,6 +43,5 @@ reqwest-client-rustls = ["reqwest", "reqwest/rustls-tls-webpki-roots"]
wasm-client = ["surf", "surf/wasm-client"]
[dev-dependencies]
-async-std = { version = "1.6.5", features = ["attributes"] }
-tokio02 = { package = "tokio", version = "0.2.22", features = ["rt-threaded", "macros"] }
+async-std = { version = "1.6.5", features = ["attributes", "tokio02", "tokio1"] }
tokio = { version = "1.7", features = ["macros", "rt-multi-thread"] }
diff --git a/influxdb/tests/integration_tests.rs b/influxdb/tests/integration_tests.rs
index 4167588..c7efe6a 100644
--- a/influxdb/tests/integration_tests.rs
+++ b/influxdb/tests/integration_tests.rs
@@ -28,9 +28,9 @@ async fn test_ping_influx_db_async_std() {
/// INTEGRATION TEST
///
-/// This test case tests whether the InfluxDB server can be connected to and gathers info about it * tested with tokio
+/// This test case tests whether the InfluxDB server can be connected to and gathers info about it - tested with tokio 1.0
#[tokio::test]
-#[cfg(not(tarpaulin_include))]
+#[cfg(not(any(tarpaulin_include, feature = "hyper-client")))]
async fn test_ping_influx_db_tokio() {
let client = create_client("notusedhere");
let result = client.ping().await;
From 51a039e5302d2a554bca3f81659fd0c5e0599f60 Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 02:17:21 +0200
Subject: [PATCH 12/13] there's another tokio test
---
influxdb/tests/integration_tests.rs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/influxdb/tests/integration_tests.rs b/influxdb/tests/integration_tests.rs
index c7efe6a..631023b 100644
--- a/influxdb/tests/integration_tests.rs
+++ b/influxdb/tests/integration_tests.rs
@@ -453,8 +453,10 @@ async fn test_json_query_tagged() {
/// is equal to the data which was written to the database
/// (tested with tokio)
#[tokio::test]
-#[cfg(feature = "use-serde")]
-#[cfg(not(tarpaulin_include))]
+#[cfg(all(
+ feature = "use-serde",
+ not(any(tarpaulin_include, feature = "hyper-client"))
+))]
async fn test_json_query_vec() {
use serde::Deserialize;
From f9ccb0a8ca5c5325c9e600912be6db1a6b877094 Mon Sep 17 00:00:00 2001
From: Dominic
Date: Thu, 24 Jun 2021 02:23:20 +0200
Subject: [PATCH 13/13] Revert "ci: temporarily disable branch restriction"
This reverts commit 147416f0502ccc4f57e65c7721d080a1343e1050.
---
.github/workflows/rust.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index da37e83..9654f39 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -3,6 +3,7 @@ name: Rust
on:
push:
branches:
+ - master
pull_request:
jobs: