From 1ae6c22be0406da523837e888537b29df6c7acd8 Mon Sep 17 00:00:00 2001 From: D3SOX Date: Sat, 14 Nov 2026 22:00:52 +0100 Subject: [PATCH 1/4] fix(sync): stop activity writes and polls from reading every stored event Activity events carry padded payloads that SQLite stores in overflow pages, with `expires_at` behind them. Filtering by expiry therefore read every stored payload of the account: inside each write transaction with activity, which holds the write lock, and on every change poll. On slow storage that held the lock long enough for other requests to fail as busy. Index the filtered columns, and filter already processed broadcasts in SQL so /events no longer loads their payloads. --- .../down.sql | 1 + .../up.sql | 6 + .../down.sql | 1 + .../up.sql | 6 + src/database/sync_event.rs | 133 ++++++++++++++++-- src/handlers/encrypted_sync.rs | 31 ++-- 6 files changed, 158 insertions(+), 20 deletions(-) create mode 100644 migrations/postgres/2026-11-14-000000-0000_sync_event_account_expiry/down.sql create mode 100644 migrations/postgres/2026-11-14-000000-0000_sync_event_account_expiry/up.sql create mode 100644 migrations/sqlite/2026-11-14-000000-0000_sync_event_account_expiry/down.sql create mode 100644 migrations/sqlite/2026-11-14-000000-0000_sync_event_account_expiry/up.sql diff --git a/migrations/postgres/2026-11-14-000000-0000_sync_event_account_expiry/down.sql b/migrations/postgres/2026-11-14-000000-0000_sync_event_account_expiry/down.sql new file mode 100644 index 0000000..561cc5c --- /dev/null +++ b/migrations/postgres/2026-11-14-000000-0000_sync_event_account_expiry/down.sql @@ -0,0 +1 @@ +DROP INDEX sync_event_account_expiry; diff --git a/migrations/postgres/2026-11-14-000000-0000_sync_event_account_expiry/up.sql b/migrations/postgres/2026-11-14-000000-0000_sync_event_account_expiry/up.sql new file mode 100644 index 0000000..7092644 --- /dev/null +++ b/migrations/postgres/2026-11-14-000000-0000_sync_event_account_expiry/up.sql @@ -0,0 +1,6 @@ +-- Activity payloads are padded to tens of kilobytes. SQLite stores most of +-- such a row in overflow pages, with the columns after `payload` at the end, +-- so filtering events by `expires_at` read every stored payload, inside each +-- write transaction with activity and on every change poll. Index the columns +-- these queries filter and return instead. +CREATE INDEX sync_event_account_expiry ON sync_event(account_id, recipient, expires_at, id); diff --git a/migrations/sqlite/2026-11-14-000000-0000_sync_event_account_expiry/down.sql b/migrations/sqlite/2026-11-14-000000-0000_sync_event_account_expiry/down.sql new file mode 100644 index 0000000..561cc5c --- /dev/null +++ b/migrations/sqlite/2026-11-14-000000-0000_sync_event_account_expiry/down.sql @@ -0,0 +1 @@ +DROP INDEX sync_event_account_expiry; diff --git a/migrations/sqlite/2026-11-14-000000-0000_sync_event_account_expiry/up.sql b/migrations/sqlite/2026-11-14-000000-0000_sync_event_account_expiry/up.sql new file mode 100644 index 0000000..7092644 --- /dev/null +++ b/migrations/sqlite/2026-11-14-000000-0000_sync_event_account_expiry/up.sql @@ -0,0 +1,6 @@ +-- Activity payloads are padded to tens of kilobytes. SQLite stores most of +-- such a row in overflow pages, with the columns after `payload` at the end, +-- so filtering events by `expires_at` read every stored payload, inside each +-- write transaction with activity and on every change poll. Index the columns +-- these queries filter and return instead. +CREATE INDEX sync_event_account_expiry ON sync_event(account_id, recipient, expires_at, id); diff --git a/src/database/sync_event.rs b/src/database/sync_event.rs index d67fd57..b7a8c8b 100644 --- a/src/database/sync_event.rs +++ b/src/database/sync_event.rs @@ -79,11 +79,13 @@ pub async fn list( conn: &mut DbConnection, owner: &str, target: &str, + since: &str, now: i64, ) -> Result, DbError> { + // Filter broadcasts here, so already processed payloads are not loaded. sync_event .filter(account_id.eq(owner)) - .filter(recipient.eq(target).or(recipient.eq(""))) + .filter(recipient.eq(target).or(recipient.eq("").and(id.gt(since)))) .filter(expires_at.gt(now)) .order((created_at.desc(), id.desc())) .limit(200) @@ -196,10 +198,18 @@ mod tests { .unwrap(), SaveResult::Conflict ); - assert_eq!(list(&mut conn, "a", "phone", now).await.unwrap().len(), 1); - assert!(list(&mut conn, "b", "phone", now).await.unwrap().is_empty()); + assert_eq!( + list(&mut conn, "a", "phone", "", now).await.unwrap().len(), + 1 + ); + assert!( + list(&mut conn, "b", "phone", "", now) + .await + .unwrap() + .is_empty() + ); append(&mut conn, "a", "phone", "video", now).await.unwrap(); - let events = list(&mut conn, "a", "phone", now).await.unwrap(); + let events = list(&mut conn, "a", "phone", "", now).await.unwrap(); assert_eq!(events.len(), 2); let message = events .iter() @@ -211,10 +221,16 @@ mod tests { acknowledge(&mut conn, "a", "laptop", &message.id) .await .unwrap(); - assert_eq!(list(&mut conn, "a", "phone", now).await.unwrap().len(), 2); - assert_eq!(list(&mut conn, "a", "laptop", now).await.unwrap().len(), 1); assert_eq!( - list(&mut conn, "a", "phone", now + DAY) + list(&mut conn, "a", "phone", "", now).await.unwrap().len(), + 2 + ); + assert_eq!( + list(&mut conn, "a", "laptop", "", now).await.unwrap().len(), + 1 + ); + assert_eq!( + list(&mut conn, "a", "phone", "", now + DAY) .await .unwrap() .len(), @@ -223,21 +239,24 @@ mod tests { acknowledge(&mut conn, "a", "phone", &message.id) .await .unwrap(); - assert_eq!(list(&mut conn, "a", "phone", now).await.unwrap().len(), 1); + assert_eq!( + list(&mut conn, "a", "phone", "", now).await.unwrap().len(), + 1 + ); for offset in 1..105 { append(&mut conn, "a", "", "activity", now + offset) .await .unwrap(); } assert_eq!( - list(&mut conn, "a", "phone", now + 105) + list(&mut conn, "a", "phone", "", now + 105) .await .unwrap() .len(), 100 ); assert!( - list(&mut conn, "a", "phone", now + 31 * DAY) + list(&mut conn, "a", "phone", "", now + 31 * DAY) .await .unwrap() .is_empty() @@ -260,7 +279,7 @@ mod tests { .is_err() ); assert_eq!( - list(&mut conn, "a", "device-0", now + 106) + list(&mut conn, "a", "device-0", "", now + 106) .await .unwrap() .len(), @@ -283,7 +302,12 @@ mod tests { }) .await; assert!(result.is_err()); - assert!(list(&mut conn, "b", "phone", now).await.unwrap().is_empty()); + assert!( + list(&mut conn, "b", "phone", "", now) + .await + .unwrap() + .is_empty() + ); assert!( crate::database::encrypted_sync::get_full(&mut conn, "b", "settings") .await @@ -291,4 +315,89 @@ mod tests { .is_none() ); } + + /// Activity payloads are padded to tens of kilobytes, so SQLite stores + /// most of each event in a chain of overflow pages, followed by the + /// columns after `payload`. Every write with activity and every change + /// poll must not walk those chains: on a slow disk that held the write + /// lock for seconds per request. + #[actix_rt::test] + async fn writes_and_polls_do_not_read_stored_event_payloads() { + use crate::database::encrypted_sync; + use crate::models::EncryptedSync; + use diesel_async::SimpleAsyncConnection; + + let (database, mut conn) = crate::database::TestFileDatabase::new().await; + conn.batch_execute("INSERT INTO account (id, name_hash) VALUES ('a', 'a');") + .await + .unwrap(); + encrypted_sync::create( + &mut conn, + &EncryptedSync { + account_id: "a".to_owned(), + collection: "watchStats".to_owned(), + revision: 1, + payload: "stats".to_owned(), + }, + ) + .await + .unwrap(); + let padded = "E".repeat(87_610); + let now = 10 * DAY; + // Below the retention limit, so the next append deletes none of them. + for index in 0..99 { + append(&mut conn, "a", "", &padded, now - 1000 + index) + .await + .unwrap(); + } + let newest = list(&mut conn, "a", "phone", "", now).await.unwrap()[0] + .id + .clone(); + conn.batch_execute("PRAGMA wal_checkpoint(TRUNCATE);") + .await + .unwrap(); + drop(conn); + + // Point every full overflow page of the stored payloads at a page + // past the end of the file, so walking a chain fails as corrupt. + let mut file = std::fs::read(&database.url).unwrap(); + let mut cut = 0; + for page in file.chunks_mut(4096) { + if page[4..].iter().all(|&byte| byte == b'E') { + page[..4].copy_from_slice(&u32::MAX.to_be_bytes()); + cut += 1; + } + } + assert!(cut >= 99 * 20, "only {cut} overflow pages found"); + std::fs::write(&database.url, file).unwrap(); + + let mut conn = database.connect_without_waiting().await; + assert_eq!( + event_ids(&mut conn, "a", "phone", now).await.unwrap().len(), + 99 + ); + assert!( + list(&mut conn, "a", "phone", &newest, now) + .await + .unwrap() + .is_empty() + ); + assert_eq!( + encrypted_sync::save( + &mut conn, + "a", + "watchStats", + 1, + "new stats", + usize::MAX, + Some(("activity", now)), + ) + .await + .unwrap(), + SaveResult::Saved + ); + let events = list(&mut conn, "a", "phone", &newest, now).await.unwrap(); + assert_eq!(events.len(), 1); + assert_eq!(events[0].payload, "activity"); + } } diff --git a/src/handlers/encrypted_sync.rs b/src/handlers/encrypted_sync.rs index 6462767..562a84c 100644 --- a/src/handlers/encrypted_sync.rs +++ b/src/handlers/encrypted_sync.rs @@ -457,13 +457,15 @@ async fn get_sync_events( query: web::Query, ) -> HandlerResult { let mut conn = get_db_conn!(pool); - let events = sync_event::list(&mut conn, &account.id, &session.device_id, now_ms()?) - .await - .map_err(HandlerError::database)?; - let events: Vec<_> = events - .into_iter() - .filter(|event| !event.recipient.is_empty() || event.id > query.since) - .collect(); + let events = sync_event::list( + &mut conn, + &account.id, + &session.device_id, + &query.since, + now_ms()?, + ) + .await + .map_err(HandlerError::database)?; Ok(HttpResponse::Ok() .insert_header(("Cache-Control", "no-store")) .json(events)) @@ -698,6 +700,7 @@ mod migration_tests { &mut conn, &account.id, "", + "", super::now_ms().unwrap(), ) .await @@ -1235,8 +1238,20 @@ mod change_tests { .await .unwrap() .spawn_blocking(|conn| { + use diesel::migration::MigrationSource; + + let migrations = MIGRATIONS.migrations().unwrap(); + let changes = migrations + .iter() + .find(|migration| { + migration + .name() + .to_string() + .ends_with("_encrypted_sync_changes") + }) + .unwrap(); Ok(conn - .revert_last_migration(MIGRATIONS) + .revert_migration(&**changes) .map_err(|error| error.to_string())) }) .await From 8c00a0e577aa8740f44755d76f52839197d593c5 Mon Sep 17 00:00:00 2001 From: D3SOX Date: Sat, 14 Nov 2026 22:00:53 +0100 Subject: [PATCH 2/4] fix(api): answer with a retryable 503 when no database connection is free A pool timeout panicked the request, so clients saw a dropped connection instead of the busy response they retry. --- src/handlers.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/handlers.rs b/src/handlers.rs index 925ff1f..8373237 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -166,6 +166,21 @@ impl HandlerError { Self::InternalDatabaseError } } + + /// Every pooled connection may be waiting for the write lock, so a pool + /// timeout is as retryable as the busy error those connections will get. + pub fn pool(error: diesel_async::pooled_connection::bb8::RunError) -> Self { + match error { + diesel_async::pooled_connection::bb8::RunError::TimedOut => { + log::warn!("database busy: no pooled connection became available"); + Self::DatabaseBusy + } + diesel_async::pooled_connection::bb8::RunError::User(error) => { + log::error!("database connection error: {error}"); + Self::InternalDatabaseError + } + } + } } /// SQLite reports a write lock it could not get within its busy timeout, and @@ -283,7 +298,7 @@ macro_rules! get_db_conn { $pool .get() .await - .expect("Couldn't get db connection from the pool") + .map_err($crate::handlers::HandlerError::pool)? }; } @@ -312,4 +327,42 @@ mod tests { .contains_key(actix_web::http::header::RETRY_AFTER) ); } + + /// Requests that cannot get a connection, because every pooled one waits + /// for the write lock, get a retryable response instead of a dropped + /// connection. + #[actix_rt::test] + async fn an_exhausted_pool_is_reported_as_retryable() { + use actix_web::{App, HttpResponse, get, test, web}; + use diesel_async::pooled_connection::{AsyncDieselConnectionManager, bb8::Pool}; + + #[get("/")] + async fn handler(pool: crate::WebData) -> super::HandlerResult { + let _conn = crate::get_db_conn!(pool); + Ok(HttpResponse::Ok().finish()) + } + + let pool = Pool::builder() + .max_size(1) + .connection_timeout(std::time::Duration::from_millis(10)) + .build(AsyncDieselConnectionManager::::new( + ":memory:", + )) + .await + .unwrap(); + let _held = pool.get_owned().await.unwrap(); + let app = test::init_service( + App::new() + .app_data(web::Data::new(pool.clone())) + .service(handler), + ) + .await; + let response = test::call_service(&app, test::TestRequest::get().to_request()).await; + assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE); + assert!( + response + .headers() + .contains_key(actix_web::http::header::RETRY_AFTER) + ); + } } From b45b730a0521a1ab09e35a815a8be376925a6883 Mon Sep 17 00:00:00 2001 From: D3SOX Date: Sat, 14 Nov 2026 22:11:33 +0100 Subject: [PATCH 3/4] docs(sync): describe the event index without SQLite storage details --- .../up.sql | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/migrations/postgres/2026-11-14-000000-0000_sync_event_account_expiry/up.sql b/migrations/postgres/2026-11-14-000000-0000_sync_event_account_expiry/up.sql index 7092644..fad51ee 100644 --- a/migrations/postgres/2026-11-14-000000-0000_sync_event_account_expiry/up.sql +++ b/migrations/postgres/2026-11-14-000000-0000_sync_event_account_expiry/up.sql @@ -1,6 +1,4 @@ --- Activity payloads are padded to tens of kilobytes. SQLite stores most of --- such a row in overflow pages, with the columns after `payload` at the end, --- so filtering events by `expires_at` read every stored payload, inside each --- write transaction with activity and on every change poll. Index the columns --- these queries filter and return instead. +-- Activity events are filtered by account, recipient and expiry, often only +-- for their IDs. Index those columns so these queries can skip the rows and +-- their large padded payloads. CREATE INDEX sync_event_account_expiry ON sync_event(account_id, recipient, expires_at, id); From 13c294238cffc8640b6d5022df0d38e8af32cf1d Mon Sep 17 00:00:00 2001 From: D3SOX Date: Sat, 14 Nov 2026 23:16:00 +0100 Subject: [PATCH 4/4] test: validate metadata against local feeds instead of YouTube YouTube's feeds fail intermittently with 404 and 500 responses, which failed CI on every branch. --- src/route_tests.rs | 24 +++----- src/validation.rs | 148 ++++++++++++++++++++------------------------- 2 files changed, 71 insertions(+), 101 deletions(-) diff --git a/src/route_tests.rs b/src/route_tests.rs index 22a449a..1c84221 100644 --- a/src/route_tests.rs +++ b/src/route_tests.rs @@ -856,16 +856,9 @@ fn test_app_parts( app } -/// The canonical name of the channel the metadata tests submit. -const FEED_CHANNEL_ID: &str = "UC8-Th83bH_thdKZDJCrn88g"; - -async fn canonical_feed_channel_name() -> String { - ytrss::RssChannel::fetch_from_channel_id(FEED_CHANNEL_ID) - .await - .unwrap() - .name() - .to_owned() -} +/// The channel the metadata tests submit, and the canonical name its feed reports. +const FEED_CHANNEL_ID: &str = crate::validation::test::FEED_CHANNEL.0; +const CANONICAL_FEED_CHANNEL_NAME: &str = crate::validation::test::FEED_CHANNEL.1; /// Regression test: PATCH inserted missing entries without charging the quota. #[actix_web::test] @@ -937,7 +930,7 @@ async fn history_keeps_stored_metadata_it_cannot_verify() { "upload_date": 1, "thumbnail_url": "https://i.ytimg.com/vi/forged/hqdefault.jpg", "duration": 1, - "uploader": { "id": channel_id, "name": "Tonight Show", "verified": true } + "uploader": { "id": channel_id, "name": "Feed Channel", "verified": true } }, "metadata": { "added_date": 1, "watched_state": "completed" } })) @@ -948,7 +941,7 @@ async fn history_keeps_stored_metadata_it_cannot_verify() { assert_eq!(stored["video"]["duration"], 60); assert_eq!( stored["video"]["uploader"]["name"], - canonical_feed_channel_name().await + CANONICAL_FEED_CHANNEL_NAME ); } @@ -960,7 +953,7 @@ async fn bulk_subscriptions_store_canonical_names_for_duplicates() { let token = seed_account(&pool).await; let app = test::init_service(test_app_parts(pool)).await; - let channel = json!({ "id": FEED_CHANNEL_ID, "name": "Tonight Show", "verified": true }); + let channel = json!({ "id": FEED_CHANNEL_ID, "name": "Feed Channel", "verified": true }); let request = test::TestRequest::put() .uri("/v1/subscriptions/bulk") .insert_header(("Authorization", token.clone())) @@ -976,8 +969,5 @@ async fn bulk_subscriptions_store_canonical_names_for_duplicates() { .insert_header(("Authorization", token)) .to_request(); let subscriptions: Value = test::call_and_read_body_json(&app, request).await; - assert_eq!( - subscriptions[0]["name"], - canonical_feed_channel_name().await - ); + assert_eq!(subscriptions[0]["name"], CANONICAL_FEED_CHANNEL_NAME); } diff --git a/src/validation.rs b/src/validation.rs index 0b8d7f5..95d2f4a 100644 --- a/src/validation.rs +++ b/src/validation.rs @@ -137,12 +137,28 @@ pub fn dedup_channels(channels: &mut Vec) { channels.retain(|channel| seen.insert(channel.clone())); } +#[cfg(not(test))] +async fn fetch_channel_feed(channel_id: &str) -> Result { + RssChannel::fetch_from_channel_id(channel_id).await +} + +/// YouTube's feeds fail intermittently with 404 and 500 responses, so tests +/// serve the feed of [`test::FEED_CHANNEL`] instead, and no other. +#[cfg(test)] +async fn fetch_channel_feed(channel_id: &str) -> Result { + let (id, name) = test::FEED_CHANNEL; + if channel_id != id { + return Err(ytrss::YouTubeError::ConnectionError); + } + RssChannel::from_xml(&test::feed("channel", id, name)) +} + /// Validate a channel against its YouTube RSS feed. /// /// Deliberately takes no database connection so that callers cannot hold one /// across the network round-trip. pub async fn validate_channel_against_youtube(channel: &mut Channel) -> HandlerResult<()> { - let rss_channel = RssChannel::fetch_from_channel_id(&channel.id) + let rss_channel = fetch_channel_feed(&channel.id) .await .map_err(|_| HandlerError::YouTubeConnectError)?; @@ -240,7 +256,7 @@ pub async fn validate_videos_against_youtube( } } - let channel_rss = RssChannel::fetch_from_channel_id(&channel.id) + let channel_rss = fetch_channel_feed(&channel.id) .await .map_err(|_| HandlerError::YouTubeConnectError)?; validate_videos_against_feed(video_datas, needs_validation, channel, &channel_rss) @@ -384,7 +400,7 @@ fn validate_playlist_information( } #[cfg(test)] -mod test { +pub(crate) mod test { use ytrss::{RssChannel, RssPlaylist}; use crate::{ @@ -396,8 +412,11 @@ mod test { }, }; + /// The channel whose feed handlers can fetch in tests, and its canonical name. + pub(crate) const FEED_CHANNEL: (&str, &str) = ("UC_feed_channel", "Canonical Feed Channel"); + /// A feed as served by YouTube, with one video entry. - fn feed(kind: &str, owner_id: &str, owner_name: &str) -> String { + pub(crate) fn feed(kind: &str, owner_id: &str, owner_name: &str) -> String { format!( r#" @@ -568,69 +587,57 @@ mod test { assert!(!verify_image_url("ftp://i1.ytimg.com/vi/x/hqdefault.jpg")); } - #[actix_rt::test] - async fn test_channel_validator() { - let channel_rss = RssChannel::fetch_from_channel_id("UC8-Th83bH_thdKZDJCrn88g") - .await - .unwrap(); + #[test] + fn test_channel_validator() { + let channel_rss = channel_feed(); + let submitted = |name: &str, avatar: &str| Channel { + id: "UC_channel".to_string(), + name: name.to_string(), + avatar: Some(avatar.to_string()), + verified: true, + }; assert!( validate_channel_information( - Channel { - id: "UC8-Th83bH_thdKZDJCrn88g".to_string(), - name: "The Tonight Show Starring Jimmy Fallon".to_string(), - avatar: Some("https://i1.ytimg.com/vi/hTC6Xa5TrRc/hqdefault.jpg".to_string(),), - verified: true, - }, + submitted("Canonical Name", "https://i1.ytimg.com/vi/x/hqdefault.jpg"), &channel_rss ) .is_ok() ); - assert!( validate_channel_information( - Channel { - id: "UC8-Th83bH_thdKZDJCrn88g".to_string(), - name: "The Tonight Show Starring Jimmy Fallon".to_string(), - avatar: Some( - "https://i1.example.com/vi/hTC6Xa5TrRc/hqdefault.jpg".to_string(), - ), - verified: true, - }, + submitted( + "Canonical Name", + "https://i1.example.com/vi/x/hqdefault.jpg" + ), &channel_rss ) .is_err() ); - assert!( validate_channel_information( - Channel { - id: "UC8-Th83bH_thdKZDJCrn88g".to_string(), - name: "Wrong channel name".to_string(), - avatar: Some( - "https://i1.example.com/vi/hTC6Xa5TrRc/hqdefault.jpg".to_string(), - ), - verified: true, - }, + submitted( + "Wrong channel name", + "https://i1.ytimg.com/vi/x/hqdefault.jpg" + ), &channel_rss ) .is_err() ); } - #[actix_rt::test] - async fn test_channel_validator_mismatching_uploader_names() { + #[test] + fn test_channel_validator_mismatching_uploader_names() { // the RSS uploader name is different to the one on the web UI - let channel_rss = RssChannel::fetch_from_channel_id("UCjp_3PEaOau_nT_3vnqKIvg") - .await - .unwrap(); + let channel_rss = + RssChannel::from_xml(&feed("channel", "UC_channel", "Junya.じゅんや")).unwrap(); assert!( validate_channel_information( Channel { - id: "UCjp_3PEaOau_nT_3vnqKIvg".to_string(), + id: "UC_channel".to_string(), name: "Junya Official Channel".to_string(), - avatar: Some("https://yt3.googleusercontent.com/ytc/AIdro_mFt9iiVlgxD1gBW74I1o6H8xFtOg5AwqPj2_1JKHJ4UJg=s160-c-k-c0x00ffffff-no-rj".to_string()), + avatar: Some("https://yt3.googleusercontent.com/a.jpg".to_string()), verified: true, }, &channel_rss @@ -639,52 +646,25 @@ mod test { ); } - #[actix_rt::test] - async fn test_video_validator() { - let video = CreateVideo { - id: "kMO1L5J1cn8".to_string(), - title: "Minecraft Livestream [FaceCam] | Kotti".to_string(), - upload_date: 1549036231000, /* 2019-02-01T16:50:31+00:00 */ - thumbnail_url: "https://i4.ytimg.com/vi/kMO1L5J1cn8/hqdefault.jpg".to_string(), - duration: 4352, - uploader: Channel { - id: "UCWnQYRWgTbsLTDOAVc3uzRg".to_string(), - name: "KottiXD".to_string(), - avatar: Some("https://yt3.googleusercontent.com/ytc/AIdro_lBXTw2HqumabqUMrMcWlB5BVUa-bDCP1YQ0Jwf89C6RMY=s160-c-k-c0x00ffffff-no-rj".to_string()), - verified: false, - }, - }; - - let channel_rss = RssChannel::fetch_from_channel_id(&video.uploader.id) - .await - .unwrap(); - assert!(validate_video_information(video, &channel_rss).is_ok()); - } - - #[actix_rt::test] - async fn test_playlist_validator() { - let channel_rss = RssPlaylist::fetch_from_playlist_id("PLI-n-55RUT-_Ej39IlAxon_hOJWeET7cI") - .await - .unwrap(); - - let playlist = ExtendedPlaylist { - id: "PLI-n-55RUT-_Ej39IlAxon_hOJWeET7cI".to_string(), - title: "Best German Songs".to_string(), - description: "Songs 2026 - Songs with Lyrics Playlist - My Mix - Mix Songs - Music Playlist 2026. Welcome to a curated playlist featuring the best English songs with lyrics that speak to the heart. Sing along to powerful lyrics that capture the essence of love, life, and everything in between. Mix, songs 2026, new songs 2026, top songs, best songs, my mix, mix songs, songs mix, my mix playlist, songs playlist, songs with lyrics playlist, my playlist, good songs, english songs. Songs January 2026, february 2026, march 2026, april 2026, may 2026, june 2026, july 2026, august 2026, september 2026, october 2026, november 2026, december 2026 etc. Songs 2027 - music playlist 2025.".to_string(), - thumbnail_url: Some("https://i.ytimg.com/vi/M1P0HAr-8zg/hqdefault.jpg?sqp=-oaymwEXCNACELwBSFryq4qpAwkIARUAAIhCGAE=&rs=AOn4CLBXQ360CqPdgkFrha1H3l9cx23I8A".to_string()), - video_count: Some(120), - }; - - assert!(validate_playlist_information(playlist, &channel_rss).is_ok()); - - let playlist = ExtendedPlaylist { - id: "PLI-n-55RUT-_Ej39IlAxon_hOJWeET7cI".to_string(), - title: "Best German Songs".to_string(), + #[test] + fn test_playlist_validator() { + let playlist_rss = + RssPlaylist::from_xml(&feed("playlist", "UC_owner", "Playlist Title")).unwrap(); + let playlist = |video_count| ExtendedPlaylist { + id: "PL_playlist".to_string(), + title: "Submitted Title".to_string(), description: "".to_string(), - thumbnail_url: Some("https://i.ytimg.com/vi/M1P0HAr-8zg/hqdefault.jpg?sqp=-oaymwEXCNACELwBSFryq4qpAwkIARUAAIhCGAE=&rs=AOn4CLBXQ360CqPdgkFrha1H3l9cx23I8A".to_string()), - video_count: Some(0), // impossible video count because feed is larger than 0 + thumbnail_url: Some("https://i.ytimg.com/vi/in_feed/hqdefault.jpg".to_string()), + video_count: Some(video_count), }; - assert!(validate_playlist_information(playlist, &channel_rss).is_err()); + assert_eq!( + validate_playlist_information(playlist(120), &playlist_rss) + .unwrap() + .title, + "Playlist Title" + ); + // impossible video count because the feed holds a video + assert!(validate_playlist_information(playlist(0), &playlist_rss).is_err()); } }