2024-02-20 14:32:37 +00:00
|
|
|
mod helpers;
|
2024-03-01 12:51:32 +00:00
|
|
|
mod parse;
|
|
|
|
|
2024-02-20 14:32:37 +00:00
|
|
|
use helpers::new_ds;
|
|
|
|
use surrealdb::dbs::Session;
|
|
|
|
use surrealdb::err::Error;
|
2024-03-15 11:21:32 +00:00
|
|
|
use surrealdb::fflags::FFLAGS;
|
2024-02-20 14:32:37 +00:00
|
|
|
use surrealdb::sql::Value;
|
2024-02-27 15:18:25 +00:00
|
|
|
|
2024-02-20 14:32:37 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn live_query_sends_registered_lq_details() -> Result<(), Error> {
|
|
|
|
if !FFLAGS.change_feed_live_queries.enabled() {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
let sql = "
|
|
|
|
DEFINE TABLE lq_test_123 CHANGEFEED 10m;
|
|
|
|
LIVE SELECT * FROM lq_test_123;
|
|
|
|
";
|
|
|
|
let dbs = new_ds().await?;
|
2024-02-27 15:18:25 +00:00
|
|
|
let ses = Session::owner().with_ns("test").with_db("test").with_rt(true);
|
2024-02-20 14:32:37 +00:00
|
|
|
let res = &mut dbs.execute(sql, &ses, None).await?;
|
|
|
|
assert_eq!(res.len(), 2);
|
2024-02-27 15:18:25 +00:00
|
|
|
|
|
|
|
// Define table didnt fail
|
2024-02-20 14:32:37 +00:00
|
|
|
let tmp = res.remove(0).result;
|
|
|
|
assert!(tmp.is_ok());
|
2024-02-27 15:18:25 +00:00
|
|
|
|
|
|
|
// Live query returned a valid uuid
|
2024-02-20 14:32:37 +00:00
|
|
|
let actual = res.remove(0).result?;
|
2024-02-27 15:18:25 +00:00
|
|
|
let live_id = match actual {
|
|
|
|
Value::Uuid(live_id) => live_id,
|
|
|
|
_ => panic!("Expected a UUID"),
|
|
|
|
};
|
|
|
|
assert!(!live_id.is_nil());
|
|
|
|
|
|
|
|
// Create some data
|
|
|
|
let res = &mut dbs.execute("CREATE lq_test_123", &ses, None).await?;
|
|
|
|
assert_eq!(res.len(), 1);
|
|
|
|
|
|
|
|
let result = res.remove(0);
|
|
|
|
assert!(result.result.is_ok());
|
|
|
|
|
|
|
|
dbs.process_lq_notifications(&Default::default()).await?;
|
|
|
|
|
|
|
|
let notifications_chan = dbs.notifications().unwrap();
|
|
|
|
|
|
|
|
assert!(notifications_chan.try_recv().is_ok());
|
|
|
|
assert!(notifications_chan.try_recv().is_err());
|
|
|
|
|
2024-02-20 14:32:37 +00:00
|
|
|
Ok(())
|
|
|
|
}
|