diff --git a/lib/tests/api/live.rs b/lib/tests/api/live.rs index 4ea4148e..be9237ae 100644 --- a/lib/tests/api/live.rs +++ b/lib/tests/api/live.rs @@ -6,6 +6,8 @@ use futures::TryStreamExt; use surrealdb::Action; use surrealdb::Notification; +const LQ_TIMEOUT: Duration = Duration::from_secs(10); + #[test_log::test(tokio::test)] async fn live_select_table() { let (permit, db) = new_db().await; @@ -21,7 +23,8 @@ async fn live_select_table() { // Create a record let created: Vec = db.create(table).await.unwrap(); // Pull the notification - let notification: Notification = users.next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // The returned record should match the created record assert_eq!(created, vec![notification.data.clone()]); // It should be newly created @@ -31,7 +34,8 @@ async fn live_select_table() { let _: Option = db.update(¬ification.data.id).content(json!({"foo": "bar"})).await.unwrap(); // Pull the notification - let notification: Notification = users.next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // It should be updated assert_eq!(notification.action, Action::Update); @@ -52,7 +56,7 @@ async fn live_select_table() { // Create a record db.create(Resource::from(&table)).await.unwrap(); // Pull the notification - let notification = users.next().await.unwrap(); + let notification = tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap(); // The returned record should be an object assert!(notification.data.is_object()); // It should be newly created @@ -77,7 +81,8 @@ async fn live_select_record_id() { // Create a record let created: Option = db.create(record_id).await.unwrap(); // Pull the notification - let notification: Notification = users.try_next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // The returned record should match the created record assert_eq!(created, Some(notification.data.clone())); // It should be newly created @@ -87,14 +92,16 @@ async fn live_select_record_id() { let _: Option = db.update(¬ification.data.id).content(json!({"foo": "bar"})).await.unwrap(); // Pull the notification - let notification: Notification = users.try_next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // It should be updated assert_eq!(notification.action, Action::Update); // Delete the record let _: Option = db.delete(¬ification.data.id).await.unwrap(); // Pull the notification - let notification: Notification = users.try_next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // It should be deleted assert_eq!(notification.action, Action::Delete); } @@ -108,7 +115,8 @@ async fn live_select_record_id() { // Create a record db.create(Resource::from(record_id)).await.unwrap(); // Pull the notification - let notification = users.next().await.unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap(); // The returned record should be an object assert!(notification.data.is_object()); // It should be newly created @@ -133,7 +141,8 @@ async fn live_select_record_ranges() { // Create a record let created: Option = db.create((table, "jane")).await.unwrap(); // Pull the notification - let notification: Notification = users.try_next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // The returned record should match the created record assert_eq!(created, Some(notification.data.clone())); // It should be newly created @@ -143,14 +152,16 @@ async fn live_select_record_ranges() { let _: Option = db.update(¬ification.data.id).content(json!({"foo": "bar"})).await.unwrap(); // Pull the notification - let notification: Notification = users.try_next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // It should be updated assert_eq!(notification.action, Action::Update); // Delete the record let _: Option = db.delete(¬ification.data.id).await.unwrap(); // Pull the notification - let notification: Notification = users.try_next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // It should be deleted assert_eq!(notification.action, Action::Delete); } @@ -165,7 +176,8 @@ async fn live_select_record_ranges() { // Create a record db.create(Resource::from((table, "job"))).await.unwrap(); // Pull the notification - let notification = users.next().await.unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap(); // The returned record should be an object assert!(notification.data.is_object()); // It should be newly created @@ -195,7 +207,8 @@ async fn live_select_query() { // Create a record let created: Vec = db.create(table).await.unwrap(); // Pull the notification - let notification: Notification = users.next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // The returned record should match the created record assert_eq!(created, vec![notification.data.clone()]); // It should be newly created @@ -205,14 +218,17 @@ async fn live_select_query() { let _: Option = db.update(¬ification.data.id).content(json!({"foo": "bar"})).await.unwrap(); // Pull the notification - let notification: Notification = users.next().await.unwrap().unwrap(); + let notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); + // It should be updated assert_eq!(notification.action, Action::Update); // Delete the record let _: Option = db.delete(¬ification.data.id).await.unwrap(); // Pull the notification - let notification: Notification = users.next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // It should be deleted assert_eq!(notification.action, Action::Delete); } @@ -231,7 +247,8 @@ async fn live_select_query() { // Create a record db.create(Resource::from(&table)).await.unwrap(); // Pull the notification - let notification = users.next().await.unwrap(); + let notification = tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap(); + // The returned record should be an object assert!(notification.data.is_object()); // It should be newly created @@ -252,7 +269,8 @@ async fn live_select_query() { // Create a record let created: Vec = db.create(table).await.unwrap(); // Pull the notification - let notification: Notification = users.next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // The returned record should match the created record assert_eq!(created, vec![notification.data.clone()]); // It should be newly created @@ -262,14 +280,16 @@ async fn live_select_query() { let _: Option = db.update(¬ification.data.id).content(json!({"foo": "bar"})).await.unwrap(); // Pull the notification - let notification: Notification = users.next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // It should be updated assert_eq!(notification.action, Action::Update); // Delete the record let _: Option = db.delete(¬ification.data.id).await.unwrap(); // Pull the notification - let notification: Notification = users.next().await.unwrap().unwrap(); + let notification: Notification = + tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap().unwrap(); // It should be deleted assert_eq!(notification.action, Action::Delete); } @@ -290,7 +310,7 @@ async fn live_select_query() { // Create a record db.create(Resource::from(&table)).await.unwrap(); // Pull the notification - let notification = users.next().await.unwrap(); + let notification = tokio::time::timeout(LQ_TIMEOUT, users.next()).await.unwrap().unwrap(); // The returned record should be an object assert!(notification.data.is_object()); // It should be newly created diff --git a/tests/cli_integration.rs b/tests/cli_integration.rs index f045a86e..5a02a07e 100644 --- a/tests/cli_integration.rs +++ b/tests/cli_integration.rs @@ -670,6 +670,12 @@ mod cli_integration { let output = remove_debug_info(output).replace('\n', ""); // TODO: when enabling the feature flag, turn these to `create` not `update` let allowed = [ + // Delete these + "[[{ changes: [{ define_table: { name: 'thing' } }], versionstamp: 1 }, { changes: [{ update: { id: thing:one } }], versionstamp: 2 }]]", + "[[{ changes: [{ define_table: { name: 'thing' } }], versionstamp: 1 }, { changes: [{ update: { id: thing:one } }], versionstamp: 3 }]]", + "[[{ changes: [{ define_table: { name: 'thing' } }], versionstamp: 2 }, { changes: [{ update: { id: thing:one } }], versionstamp: 3 }]]", + "[[{ changes: [{ define_table: { name: 'thing' } }], versionstamp: 2 }, { changes: [{ update: { id: thing:one } }], versionstamp: 4 }]]", + // Keep these "[[{ changes: [{ define_table: { name: 'thing' } }], versionstamp: 65536 }, { changes: [{ update: { id: thing:one } }], versionstamp: 131072 }]]", "[[{ changes: [{ define_table: { name: 'thing' } }], versionstamp: 65536 }, { changes: [{ update: { id: thing:one } }], versionstamp: 196608 }]]", "[[{ changes: [{ define_table: { name: 'thing' } }], versionstamp: 131072 }, { changes: [{ update: { id: thing:one } }], versionstamp: 196608 }]]",