a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 1 | #![cfg(feature = "mirror")] |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 2 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 3 | use std::time::Duration; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 4 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 5 | use futures_util::StreamExt; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 6 | use macltok::{ |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 7 | ClientHandle, Command, ConnectionState, Engine, EngineConfig, Event, MentionCoverage, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 8 | MentionsBoundary, MentionsPage, MentionsUpdate, Mirror, MirrorHandle, StateChange, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 9 | Subscription, TimelineChange, TimelineCommand, TimelineDiff, TimelineId, TimelineItem, Update, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 10 | UploadOutcome, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 11 | }; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 12 | use matrix_sdk::{ |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 13 | ruma::{ |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 14 | OwnedRoomId, OwnedTransactionId, TransactionId, api::client::sync::sync_events::v5, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 15 | event_id, room_id, user_id, |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 16 | }, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 17 | test_utils::mocks::MatrixMockServer, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 18 | }; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 19 | use tokio::sync::mpsc; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 20 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 21 | struct Harness { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 22 | handle: ClientHandle, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 23 | mirror: MirrorHandle, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 24 | inject: mpsc::UnboundedSender<Event>, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 25 | room_id: OwnedRoomId, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 26 | _server: MatrixMockServer, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 27 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 28 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 29 | /// the mirror reads the real engine's stream with synthetic events mixed in, so a test can |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 30 | /// hand it a diff the engine never would |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 31 | async fn start(config: EngineConfig, capacity: usize) -> Harness { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 32 | let server = MatrixMockServer::new().await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 33 | server |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 34 | .mock_sliding_sync() |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 35 | .ok(v5::Response::new("1".to_owned())) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 36 | .mount() |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 37 | .await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 38 | let client = server.client_builder().build().await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 39 | let room_id = room_id!("!mirror:localhost"); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 40 | server.mock_room_state_encryption().plain().mount().await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 41 | server.sync_joined_room(&client, room_id).await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 42 | let (engine, handle, events) = |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 43 | Engine::from_client(client, config.with_initial_history_limit(0)) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 44 | .await |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 45 | .unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 46 | tokio::spawn(engine.run()); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 47 | let (inject, mut injected) = mpsc::unbounded_channel(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 48 | let injected = futures_util::stream::poll_fn(move |context| injected.poll_recv(context)); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 49 | let (mirror, mirror_handle) = Mirror::with_capacity( |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 50 | handle.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 51 | futures_util::stream::select(events, injected), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 52 | capacity, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 53 | ); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 54 | tokio::spawn(mirror.run()); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 55 | Harness { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 56 | handle, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 57 | mirror: mirror_handle, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 58 | inject, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 59 | room_id: room_id.to_owned(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 60 | _server: server, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 61 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 62 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 63 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 64 | async fn next_matching( |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 65 | subscription: &mut Subscription, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 66 | predicate: impl Fn(&StateChange) -> bool, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 67 | ) -> Update { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 68 | tokio::time::timeout(Duration::from_secs(5), async { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 69 | loop { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 70 | let update = subscription.next().await.expect("the mirror stopped"); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 71 | if predicate(&update.change) { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 72 | return update; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 73 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 74 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 75 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 76 | .await |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 77 | .expect("expected update did not arrive") |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 78 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 79 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 80 | fn timeline_change( |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 81 | change: &StateChange, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 82 | id: &TimelineId, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 83 | predicate: impl Fn(&TimelineChange) -> bool, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 84 | ) -> bool { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 85 | matches!(change, StateChange::Timeline { timeline_id, change } if timeline_id == id && predicate(change)) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 86 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 87 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 88 | fn item(timestamp_ms: u64) -> TimelineItem { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 89 | TimelineItem::DayDivider { timestamp_ms } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 90 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 91 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 92 | fn reset(timeline_id: &TimelineId, items: Vec<TimelineItem>) -> Event { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 93 | Event::TimelineReset { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 94 | timeline_id: timeline_id.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 95 | items: items.into(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 96 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 97 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 98 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 99 | /// the room never opens, so every resync is refused and the divergence holds still to be looked at |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 100 | #[tokio::test] |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 101 | async fn diverged_batch_keeps_last_good_items_until_a_reset() { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 102 | let harness = start(EngineConfig::default(), 256).await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 103 | let timeline_id = TimelineId::from(harness.room_id.clone()); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 104 | let mut updates = harness.mirror.subscribe(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 105 | harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 106 | .inject |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 107 | .send(reset(&timeline_id, vec![item(1), item(2)])) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 108 | .unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 109 | for diffs in [ |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 110 | vec![ |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 111 | TimelineDiff::PushBack { value: item(3) }, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 112 | TimelineDiff::Remove { index: 7 }, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 113 | ], |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 114 | vec![TimelineDiff::PushBack { value: item(4) }], |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 115 | ] { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 116 | harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 117 | .inject |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 118 | .send(Event::TimelineChanged { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 119 | timeline_id: timeline_id.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 120 | diffs, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 121 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 122 | .unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 123 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 124 | next_matching(&mut updates, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 125 | timeline_change(change, &timeline_id, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 126 | matches!(change, TimelineChange::Diverged) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 127 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 128 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 129 | .await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 130 | let snapshot = harness.mirror.snapshot(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 131 | let timeline = &snapshot.timelines[&timeline_id]; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 132 | assert!(timeline.diverged); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 133 | assert_eq!(timeline.items, [item(1), item(2)].into_iter().collect()); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 134 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 135 | harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 136 | .inject |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 137 | .send(reset(&timeline_id, vec![item(5)])) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 138 | .unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 139 | let update = next_matching(&mut updates, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 140 | timeline_change(change, &timeline_id, |_| true) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 141 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 142 | .await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 143 | assert!( |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 144 | timeline_change(&update.change, &timeline_id, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 145 | matches!(change, TimelineChange::Reset { .. }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 146 | }), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 147 | "a diverged timeline took {update:?}" |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 148 | ); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 149 | let snapshot = harness.mirror.snapshot(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 150 | let timeline = &snapshot.timelines[&timeline_id]; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 151 | assert!(!timeline.diverged); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 152 | assert_eq!(timeline.items, [item(5)].into_iter().collect()); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 153 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 154 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 155 | #[tokio::test] |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 156 | async fn a_diff_for_a_timeline_without_a_reset_diverges_it() { |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 157 | let harness = start(EngineConfig::default(), 256).await; |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 158 | let timeline_id = TimelineId::from(harness.room_id.clone()); |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 159 | let mut updates = harness.mirror.subscribe(); |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 160 | harness |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 161 | .inject |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 162 | .send(Event::TimelineChanged { |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 163 | timeline_id: timeline_id.clone(), |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 164 | diffs: vec![TimelineDiff::PushBack { value: item(1) }], |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 165 | }) |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 166 | .unwrap(); |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 167 | next_matching(&mut updates, |change| { |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 168 | timeline_change(change, &timeline_id, |change| { |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 169 | matches!(change, TimelineChange::Diverged) |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 170 | }) |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 171 | }) |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 172 | .await; |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 173 | let snapshot = harness.mirror.snapshot(); |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 174 | let timeline = &snapshot.timelines[&timeline_id]; |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 175 | assert!(timeline.diverged); |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 176 | assert!(timeline.items.is_empty()); |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 177 | } |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 178 | |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 179 | #[tokio::test] |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 180 | async fn room_and_thread_timelines_stay_apart() { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 181 | let harness = start(EngineConfig::default(), 256).await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 182 | let room = TimelineId::from(harness.room_id.clone()); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 183 | let thread = TimelineId::thread( |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 184 | harness.room_id.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 185 | event_id!("$root:localhost").to_owned(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 186 | ); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 187 | let mut updates = harness.mirror.subscribe(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 188 | harness.inject.send(reset(&room, vec![item(1)])).unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 189 | harness.inject.send(reset(&thread, vec![item(2)])).unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 190 | harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 191 | .inject |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 192 | .send(Event::TimelineChanged { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 193 | timeline_id: thread.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 194 | diffs: vec![TimelineDiff::PushBack { value: item(3) }], |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 195 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 196 | .unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 197 | next_matching(&mut updates, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 198 | timeline_change(change, &thread, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 199 | matches!(change, TimelineChange::Changed { .. }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 200 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 201 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 202 | .await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 203 | let snapshot = harness.mirror.snapshot(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 204 | assert_eq!( |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 205 | snapshot.timelines[&room].items, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 206 | [item(1)].into_iter().collect() |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 207 | ); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 208 | assert_eq!( |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 209 | snapshot.timelines[&thread].items, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 210 | [item(2), item(3)].into_iter().collect() |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 211 | ); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 212 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 213 | |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 214 | #[tokio::test(flavor = "multi_thread", worker_threads = 4)] |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 215 | async fn subscribers_joining_mid_stream_see_no_gap_and_nothing_twice() { |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 216 | const CHUNKS: u64 = 64; |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 217 | const CHUNK: u64 = 32; |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 218 | let harness = start(EngineConfig::default(), 4096).await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 219 | let transaction_id = TransactionId::new(); |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 220 | let mut followers = Vec::new(); |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 221 | for chunk in 0..CHUNKS { |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 222 | for uploaded_bytes in chunk * CHUNK + 1..=(chunk + 1) * CHUNK { |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 223 | harness |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 224 | .inject |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 225 | .send(Event::MediaUploadProgress { |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 226 | room_id: harness.room_id.clone(), |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 227 | transaction_id: transaction_id.clone(), |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 228 | uploaded_bytes, |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 229 | total_bytes: CHUNKS * CHUNK, |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 230 | complete: false, |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 231 | }) |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 232 | .unwrap(); |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 233 | } |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 234 | followers.push(tokio::spawn(follow( |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 235 | harness.mirror.subscribe(), |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 236 | transaction_id.clone(), |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 237 | CHUNKS * CHUNK, |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 238 | ))); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 239 | } |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 240 | for follower in followers { |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 241 | follower.await.unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 242 | } |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 243 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 244 | |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 245 | async fn follow(mut updates: Subscription, transaction_id: OwnedTransactionId, total: u64) { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 246 | let first = updates.next().await.unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 247 | let StateChange::State(state) = &first.change else { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 248 | panic!("a subscription opened with {first:?}"); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 249 | }; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 250 | let mut seen = state |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 251 | .uploads |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 252 | .get(&transaction_id) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 253 | .map_or(0, |upload| upload.uploaded_bytes); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 254 | let mut sequence = first.sequence; |
0b8ce8dc9a1c | atagen | 2026-09-26 12:30 UTC | 255 | while seen < total { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 256 | let update = next_matching(&mut updates, |_| true).await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 257 | assert_eq!(update.sequence, sequence + 1); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 258 | sequence = update.sequence; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 259 | if let StateChange::Upload { upload, .. } = update.change { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 260 | assert_eq!(upload.uploaded_bytes, seen + 1); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 261 | seen += 1; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 262 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 263 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 264 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 265 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 266 | #[tokio::test] |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 267 | async fn lagging_subscriber_starts_over_from_a_fresh_state() { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 268 | let harness = start(EngineConfig::default(), 4).await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 269 | let transaction_id = TransactionId::new(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 270 | let mut updates = harness.mirror.subscribe(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 271 | assert!(matches!( |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 272 | updates.next().await.unwrap().change, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 273 | StateChange::State(_) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 274 | )); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 275 | for uploaded_bytes in 1..=20 { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 276 | harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 277 | .inject |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 278 | .send(Event::MediaUploadProgress { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 279 | room_id: harness.room_id.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 280 | transaction_id: transaction_id.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 281 | uploaded_bytes, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 282 | total_bytes: 20, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 283 | complete: uploaded_bytes == 20, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 284 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 285 | .unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 286 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 287 | tokio::time::timeout(Duration::from_secs(5), async { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 288 | while !harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 289 | .mirror |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 290 | .snapshot() |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 291 | .uploads |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 292 | .get(&transaction_id) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 293 | .is_some_and(|upload| upload.complete) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 294 | { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 295 | tokio::task::yield_now().await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 296 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 297 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 298 | .await |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 299 | .expect("the mirror never caught up"); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 300 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 301 | let update = updates.next().await.unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 302 | let StateChange::State(state) = &update.change else { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 303 | panic!("a lagged subscription carried on with {update:?}"); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 304 | }; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 305 | assert!(state.uploads[&transaction_id].complete); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 306 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 307 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 308 | #[tokio::test] |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 309 | async fn resync_does_not_deadlock_on_full_queues() { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 310 | let config = EngineConfig::default() |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 311 | .with_command_capacity(1) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 312 | .with_event_capacity(1); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 313 | let harness = start(config, 1024).await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 314 | let timeline_id = TimelineId::from(harness.room_id.clone()); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 315 | let mut updates = harness.mirror.subscribe(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 316 | harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 317 | .handle |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 318 | .open_room(harness.room_id.clone()) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 319 | .await |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 320 | .unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 321 | next_matching(&mut updates, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 322 | timeline_change(change, &timeline_id, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 323 | matches!(change, TimelineChange::Reset { .. }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 324 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 325 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 326 | .await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 327 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 328 | let flood = tokio::spawn({ |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 329 | let handle = harness.handle.clone(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 330 | let timeline_id = timeline_id.clone(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 331 | async move { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 332 | loop { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 333 | let command = Command::Timeline(TimelineCommand::Paginate { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 334 | timeline_id: timeline_id.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 335 | limit: 1, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 336 | }); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 337 | if handle.send(command).await.is_err() { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 338 | return; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 339 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 340 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 341 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 342 | }); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 343 | for _ in 0..10 { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 344 | harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 345 | .inject |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 346 | .send(Event::TimelineChanged { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 347 | timeline_id: timeline_id.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 348 | diffs: vec![TimelineDiff::Remove { index: 1000 }], |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 349 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 350 | .unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 351 | next_matching(&mut updates, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 352 | timeline_change(change, &timeline_id, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 353 | matches!(change, TimelineChange::Diverged) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 354 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 355 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 356 | .await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 357 | next_matching(&mut updates, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 358 | timeline_change(change, &timeline_id, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 359 | matches!(change, TimelineChange::Reset { .. }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 360 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 361 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 362 | .await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 363 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 364 | flood.abort(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 365 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 366 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 367 | #[tokio::test] |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 368 | async fn closing_a_timeline_evicts_it() { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 369 | let harness = start(EngineConfig::default(), 256).await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 370 | let timeline_id = TimelineId::from(harness.room_id.clone()); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 371 | let mut updates = harness.mirror.subscribe(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 372 | harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 373 | .handle |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 374 | .open_room(harness.room_id.clone()) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 375 | .await |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 376 | .unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 377 | harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 378 | .handle |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 379 | .close_room(harness.room_id.clone()) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 380 | .await |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 381 | .unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 382 | next_matching(&mut updates, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 383 | timeline_change(change, &timeline_id, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 384 | matches!(change, TimelineChange::Closed) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 385 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 386 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 387 | .await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 388 | assert!( |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 389 | !harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 390 | .mirror |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 391 | .snapshot() |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 392 | .timelines |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 393 | .contains_key(&timeline_id) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 394 | ); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 395 | } |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 396 | |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 397 | #[tokio::test] |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 398 | async fn an_upload_ends_on_finished() { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 399 | let harness = start(EngineConfig::default(), 256).await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 400 | let transaction_id = TransactionId::new(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 401 | let mut updates = harness.mirror.subscribe(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 402 | harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 403 | .inject |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 404 | .send(Event::MediaUploadProgress { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 405 | room_id: harness.room_id.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 406 | transaction_id: transaction_id.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 407 | uploaded_bytes: 5, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 408 | total_bytes: 10, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 409 | complete: false, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 410 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 411 | .unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 412 | next_matching(&mut updates, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 413 | matches!(change, StateChange::Upload { .. }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 414 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 415 | .await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 416 | assert!( |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 417 | harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 418 | .mirror |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 419 | .snapshot() |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 420 | .uploads |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 421 | .contains_key(&transaction_id) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 422 | ); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 423 | harness |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 424 | .inject |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 425 | .send(Event::MediaUploadFinished { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 426 | room_id: harness.room_id.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 427 | transaction_id: transaction_id.clone(), |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 428 | outcome: UploadOutcome::Cancelled, |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 429 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 430 | .unwrap(); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 431 | next_matching(&mut updates, |change| { |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 432 | matches!(change, StateChange::UploadFinished { .. }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 433 | }) |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 434 | .await; |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 435 | assert!(harness.mirror.snapshot().uploads.is_empty()); |
a319bae745d8 | atagen | 2026-09-26 09:59 UTC | 436 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 437 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 438 | #[tokio::test] |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 439 | async fn mentions_updates_require_the_current_account_and_revision() { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 440 | let harness = start(EngineConfig::default(), 256).await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 441 | let mut updates = harness.mirror.subscribe(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 442 | let account = tokio::time::timeout(Duration::from_secs(5), async { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 443 | loop { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 444 | let state = harness.mirror.snapshot(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 445 | if state.mentions.is_some() { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 446 | break state.user_id.clone().unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 447 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 448 | updates.next().await.unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 449 | } |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 450 | }) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 451 | .await |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 452 | .expect("the initial mentions snapshot did not arrive"); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 453 | let mentions_update = |account, revision| { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 454 | Event::MentionsChanged(MentionsUpdate { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 455 | snapshot: MentionsPage { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 456 | entries: Vec::new(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 457 | next_cursor: None, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 458 | end_reached: true, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 459 | coverage: MentionCoverage::default(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 460 | unread_count: 0, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 461 | revision, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 462 | boundary: MentionsBoundary { account, revision }, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 463 | }, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 464 | upserts: Vec::new(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 465 | removed: Vec::new(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 466 | }) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 467 | }; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 468 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 469 | harness |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 470 | .inject |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 471 | .send(mentions_update(account.clone(), 100)) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 472 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 473 | next_matching( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 474 | &mut updates, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 475 | |change| matches!(change, StateChange::Mentions(update) if update.snapshot.revision == 100), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 476 | ) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 477 | .await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 478 | assert_eq!( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 479 | harness |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 480 | .mirror |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 481 | .snapshot() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 482 | .mentions |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 483 | .as_ref() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 484 | .unwrap() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 485 | .revision, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 486 | 100 |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 487 | ); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 488 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 489 | harness |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 490 | .inject |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 491 | .send(mentions_update(account.clone(), 99)) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 492 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 493 | harness |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 494 | .inject |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 495 | .send(mentions_update( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 496 | user_id!("@other:localhost").to_owned(), |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 497 | 101, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 498 | )) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 499 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 500 | harness |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 501 | .inject |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 502 | .send(Event::ConnectionChanged(ConnectionState::Stopped)) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 503 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 504 | next_matching(&mut updates, |change| { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 505 | matches!(change, StateChange::Connection(ConnectionState::Stopped)) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 506 | }) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 507 | .await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 508 | assert_eq!( |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 509 | harness |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 510 | .mirror |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 511 | .snapshot() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 512 | .mentions |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 513 | .as_ref() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 514 | .unwrap() |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 515 | .revision, |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 516 | 100 |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 517 | ); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 518 | |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 519 | harness.inject.send(Event::LoggedOut).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 520 | harness.inject.send(mentions_update(account, 102)).unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 521 | harness |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 522 | .inject |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 523 | .send(Event::ConnectionChanged(ConnectionState::Stopped)) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 524 | .unwrap(); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 525 | next_matching(&mut updates, |change| { |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 526 | matches!(change, StateChange::Connection(ConnectionState::Stopped)) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 527 | }) |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 528 | .await; |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 529 | assert!(harness.mirror.snapshot().mentions.is_none()); |
cbb715e11963 | atagen | 2026-10-24 23:24 UTC | 530 | } |