()
| 314 | #[mz_ore::test] |
| 315 | #[allow(clippy::disallowed_methods)] |
| 316 | fn test_time() { |
| 317 | let server = test_util::TestHarness::default() |
| 318 | .unsafe_mode() |
| 319 | .start_blocking(); |
| 320 | server.enable_feature_flags(&["unsafe_enable_unsafe_functions"]); |
| 321 | let mut client = server.connect(postgres::NoTls).unwrap(); |
| 322 | |
| 323 | // Confirm that `now()` and `current_timestamp()` both return a |
| 324 | // DateTime<Utc>, but don't assert specific times. |
| 325 | let row = client |
| 326 | .query_one("SELECT now(), current_timestamp()", &[]) |
| 327 | .unwrap(); |
| 328 | let _ = row.get::<_, DateTime<Utc>>(0); |
| 329 | let _ = row.get::<_, DateTime<Utc>>(1); |
| 330 | |
| 331 | // Confirm calls to now() return the same DateTime<Utc> both inside and |
| 332 | // outside of subqueries. |
| 333 | let row = client |
| 334 | .query_one("SELECT now(), (SELECT now())", &[]) |
| 335 | .unwrap(); |
| 336 | assert_eq!( |
| 337 | row.get::<_, DateTime<Utc>>(0), |
| 338 | row.get::<_, DateTime<Utc>>(1) |
| 339 | ); |
| 340 | |
| 341 | // Ensure that EXPLAIN selects a timestamp for `now()` and |
| 342 | // `current_timestamp()`, though we don't care what the timestamp is. |
| 343 | let rows = client |
| 344 | .query( |
| 345 | "EXPLAIN OPTIMIZED PLAN AS VERBOSE TEXT FOR SELECT now(), current_timestamp()", |
| 346 | &[], |
| 347 | ) |
| 348 | .unwrap(); |
| 349 | assert_eq!(1, rows.len()); |
| 350 | |
| 351 | // Test that `mz_sleep` causes a delay of at least the appropriate time. |
| 352 | let start = Instant::now(); |
| 353 | client |
| 354 | .batch_execute("SELECT mz_unsafe.mz_sleep(0.3)") |
| 355 | .unwrap(); |
| 356 | let elapsed = start.elapsed(); |
| 357 | assert!( |
| 358 | elapsed >= Duration::from_millis(300), |
| 359 | "start.elapsed() = {:?}", |
| 360 | elapsed |
| 361 | ); |
| 362 | } |
| 363 | |
| 364 | #[mz_ore::test] |
| 365 | #[allow(clippy::disallowed_methods)] |
nothing calls this directly
no test coverage detected