From f8be5c50d165543fedd94b28724f439416eb6334 Mon Sep 17 00:00:00 2001 From: Samuel Corsi-House Date: Mon, 17 Jun 2024 10:23:21 -0400 Subject: [PATCH] add test for Sync trait --- postgres/tests/postgres.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/postgres/tests/postgres.rs b/postgres/tests/postgres.rs index 7e64b42..7ccf5d7 100644 --- a/postgres/tests/postgres.rs +++ b/postgres/tests/postgres.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, env, time::Duration}; +use std::{collections::HashMap, env, pin::Pin, time::Duration}; use futures::future; use serde::{Deserialize, Serialize}; @@ -212,6 +212,27 @@ async fn statement_caches_clear() { assert!(client1.statement_cache.size() == 0); } +#[tokio::test] +async fn sync_trait_get() { + let pool = create_pool(); + + type ClosureFuture = Pin + Send + Sync>>; + async fn test_closure ClosureFuture + Send + Sync + 'static>(_: T) { + return; + } + + test_closure(move |_| Box::pin(async move {})).await; + assert!(true); + + test_closure(move |_| { + let pool = pool.clone(); + Box::pin(async move { + pool.get().await; + }) + }); + assert!(true); +} + struct Env { backup: HashMap>, }