MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / test_time

Function test_time

src/environmentd/tests/sql.rs:316–362  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

314#[mz_ore::test]
315#[allow(clippy::disallowed_methods)]
316fn 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)]

Callers

nothing calls this directly

Calls 9

nowFunction · 0.85
start_blockingMethod · 0.80
unsafe_modeMethod · 0.80
enable_feature_flagsMethod · 0.80
unwrapMethod · 0.80
batch_executeMethod · 0.80
connectMethod · 0.45
query_oneMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected