From f00b7b48e15c44b15e83c764c3dd72ff1452706c Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Mon, 13 Apr 2020 13:37:54 -0700 Subject: [PATCH] add regression test for `Map::fetch()` being `Unpin` --- tests/postgres-macros.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/postgres-macros.rs b/tests/postgres-macros.rs index 0d6e89d5..1ed88811 100644 --- a/tests/postgres-macros.rs +++ b/tests/postgres-macros.rs @@ -1,6 +1,8 @@ use sqlx::Postgres; use sqlx_test::new; +use futures::TryStreamExt; + #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn test_query() -> anyhow::Result<()> { @@ -244,3 +246,21 @@ async fn test_array_from_slice() -> anyhow::Result<()> { Ok(()) } + +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] +async fn fetch_is_usable_issue_224() -> anyhow::Result<()> { + // ensures that the stream returned by `query::Map::fetch()` is usable with `TryStreamExt` + let mut conn = new::().await?; + + let mut stream = + sqlx::query!("select * from generate_series(1, 3) as series(num);").fetch(&mut conn); + + // `num` is generated by a function so we can't assume it's non-null + assert_eq!(stream.try_next().await?.unwrap().num, Some(1)); + assert_eq!(stream.try_next().await?.unwrap().num, Some(2)); + assert_eq!(stream.try_next().await?.unwrap().num, Some(3)); + assert!(stream.try_next().await?.is_none()); + + Ok(()) +}