| 1210 | type IntoFuture = BoxFuture<'static, Self::Output>; |
| 1211 | |
| 1212 | fn into_future(mut self) -> Self::IntoFuture { |
| 1213 | Box::pin(async move { |
| 1214 | assert!( |
| 1215 | self.pg_config.get_ports().is_empty(), |
| 1216 | "specifying multiple ports is not supported" |
| 1217 | ); |
| 1218 | self.pg_config.port(self.port); |
| 1219 | |
| 1220 | let (client, mut conn) = self.pg_config.connect(self.tls).await?; |
| 1221 | let mut notice_callback = self.notice_callback.take(); |
| 1222 | |
| 1223 | let handle = task::spawn(|| "connect", async move { |
| 1224 | while let Some(msg) = std::future::poll_fn(|cx| conn.poll_message(cx)).await { |
| 1225 | match msg { |
| 1226 | Ok(AsyncMessage::Notice(notice)) => { |
| 1227 | if let Some(callback) = notice_callback.as_mut() { |
| 1228 | callback(notice); |
| 1229 | } |
| 1230 | } |
| 1231 | Ok(msg) => { |
| 1232 | tracing::debug!(?msg, "Dropping message from database"); |
| 1233 | } |
| 1234 | Err(e) => { |
| 1235 | // tokio_postgres::Connection docs say: |
| 1236 | // > Return values of None or Some(Err(_)) are “terminal”; callers |
| 1237 | // > should not invoke this method again after receiving one of those |
| 1238 | // > values. |
| 1239 | tracing::info!("connection error: {e}"); |
| 1240 | break; |
| 1241 | } |
| 1242 | } |
| 1243 | } |
| 1244 | tracing::info!("connection closed"); |
| 1245 | }); |
| 1246 | |
| 1247 | let output = H::transform_result(client, handle); |
| 1248 | Ok(output) |
| 1249 | }) |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | /// A running instance of `environmentd`, that exposes blocking/synchronous test helpers. |