mock rooms can be joined and have dedicated state of feed

master^2
bel 2020-05-02 14:35:38 -06:00
parent 74b2c36acf
commit ab88ba7fc0
3 changed files with 72 additions and 8 deletions

View File

@ -3,13 +3,14 @@ use super::event::Event;
use rand::{self, Rng}; use rand::{self, Rng};
use rand::distributions::Alphanumeric; use rand::distributions::Alphanumeric;
use crossbeam_channel::{unbounded, Receiver, Sender}; use crossbeam_channel::{unbounded, Sender, Receiver};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MockRoom { pub struct MockRoom {
last: String, last: String,
room_id: String, room_id: String,
events: Vec<Event>, events_s: Sender<Vec<Event>>,
events_r: Receiver<Vec<Event>>,
} }
impl MockRoom { impl MockRoom {
@ -18,10 +19,13 @@ impl MockRoom {
} }
pub fn join(room_id: String) -> MockRoom { pub fn join(room_id: String) -> MockRoom {
let (s, r) = unbounded();
s.send(vec![]).ok().unwrap();
MockRoom { MockRoom {
last: "".to_string(), last: "".to_string(),
room_id: room_id, room_id: room_id,
events: vec![], events_s: s,
events_r: r,
} }
} }
@ -34,7 +38,8 @@ impl Room for MockRoom {
fn sync(&mut self) -> Vec<Event> { fn sync(&mut self) -> Vec<Event> {
let mut unseen: Vec<Event> = vec![]; let mut unseen: Vec<Event> = vec![];
let mut last = self.last.clone(); let mut last = self.last.clone();
for e in &self.events { let events = self.events_r.recv().ok().unwrap();
for e in &events {
if e.next == self.last { if e.next == self.last {
unseen.clear(); unseen.clear();
} else { } else {
@ -42,6 +47,7 @@ impl Room for MockRoom {
last = e.next.clone(); last = e.next.clone();
} }
} }
self.events_s.send(events).ok().unwrap();
self.last = last; self.last = last;
return unseen; return unseen;
} }
@ -52,7 +58,9 @@ impl Room for MockRoom {
next: rands(), next: rands(),
body: message, body: message,
}; };
self.events.push(e); let mut events = self.events_r.recv().ok().unwrap();
events.push(e);
self.events_s.send(events).ok().unwrap();
Ok("ok") Ok("ok")
} }
@ -63,7 +71,7 @@ impl Room for MockRoom {
impl Drop for MockRoom { impl Drop for MockRoom {
fn drop(&mut self) { fn drop(&mut self) {
println!("not impl"); println!("MockRoom::drop not impl");
} }
} }
@ -84,14 +92,15 @@ mod tests {
fn _dummy() -> MockRoom { fn _dummy() -> MockRoom {
let mut r = MockRoom::create(); let mut r = MockRoom::create();
r.last = "1".to_string(); r.last = "1".to_string();
r.events = vec![]; let mut events = r.events_r.recv().ok().unwrap();
for i in 0..5 { for i in 0..5 {
r.events.push(Event{ events.push(Event{
sender: i.to_string(), sender: i.to_string(),
next: i.to_string(), next: i.to_string(),
body: i.to_string(), body: i.to_string(),
}); });
} }
r.events_s.send(events).ok().unwrap();
r r
} }

View File

@ -86,4 +86,38 @@ mod tests {
assert!(r.is_ok()); assert!(r.is_ok());
assert!(r.ok().unwrap().room_id() == "0"); assert!(r.ok().unwrap().room_id() == "0");
} }
#[test]
fn join_clobber() {
let mrs = _dummy();
let mut a = mrs.join("0".to_string()).ok().unwrap();
let mut b = mrs.join("0".to_string()).ok().unwrap();
assert!(a.room_id() == b.room_id());
assert!(a.sync().len() == b.sync().len());
assert!(a.sync().len() == b.sync().len());
assert!(a.sync().len() == 0);
assert!(b.sync().len() == 0);
assert!(a.send("from a".to_string()).is_ok());
assert!(a.sync().len() == 1);
assert!(b.sync().len() == 1);
assert!(b.send("from b".to_string()).is_ok());
assert!(b.send("from b".to_string()).is_ok());
assert!(a.sync().len() == 2);
assert!(b.sync().len() == 2);
assert!(a.send("from a".to_string()).is_ok());
assert!(b.send("from b".to_string()).is_ok());
assert!(a.send("from a".to_string()).is_ok());
assert!(a.sync().len() == 3);
assert!(b.sync().len() == 3);
assert!(a.send("from a".to_string()).is_ok());
assert!(b.send("from b".to_string()).is_ok());
let a = a.sync();
let b = b.sync();
assert!(a.len() == 2);
assert!(b.len() == 2);
assert!(a[0].body == "from a");
assert!(b[0].body == "from a");
assert!(a[1].body == "from b");
assert!(b[1].body == "from b");
}
} }

View File

@ -557,3 +557,24 @@
2020-05-02 14:11:12,328 - synapse.storage.data_stores.main.event_push_actions - 511 - INFO - event_push_action_stream_orderings-40 - Found stream ordering 1 day ago: it's 2 2020-05-02 14:11:12,328 - synapse.storage.data_stores.main.event_push_actions - 511 - INFO - event_push_action_stream_orderings-40 - Found stream ordering 1 day ago: it's 2
2020-05-02 14:11:12,336 - synapse.storage.data_stores.main - 425 - INFO - generate_user_daily_visits-81 - Calling _generate_user_daily_visits 2020-05-02 14:11:12,336 - synapse.storage.data_stores.main - 425 - INFO - generate_user_daily_visits-81 - Calling _generate_user_daily_visits
2020-05-02 14:12:42,319 - synapse.metrics - 464 - INFO - - Collecting gc 1 2020-05-02 14:12:42,319 - synapse.metrics - 464 - INFO - - Collecting gc 1
2020-05-02 14:16:12,336 - synapse.storage.data_stores.main - 425 - INFO - generate_user_daily_visits-82 - Calling _generate_user_daily_visits
2020-05-02 14:18:37,323 - synapse.metrics - 464 - INFO - - Collecting gc 1
2020-05-02 14:21:12,322 - synapse.storage.data_stores.main.event_push_actions - 834 - INFO - rotate_notifs-13 - Rotating notifications
2020-05-02 14:21:12,329 - synapse.storage.data_stores.main.event_push_actions - 499 - INFO - event_push_action_stream_orderings-41 - Searching for stream ordering 1 month ago
2020-05-02 14:21:12,331 - synapse.storage.data_stores.main.event_push_actions - 504 - INFO - event_push_action_stream_orderings-41 - Found stream ordering 1 month ago: it's 2
2020-05-02 14:21:12,331 - synapse.storage.data_stores.main.event_push_actions - 506 - INFO - event_push_action_stream_orderings-41 - Searching for stream ordering 1 day ago
2020-05-02 14:21:12,332 - synapse.storage.data_stores.main.event_push_actions - 511 - INFO - event_push_action_stream_orderings-41 - Found stream ordering 1 day ago: it's 2
2020-05-02 14:21:12,334 - synapse.storage.data_stores.main.event_push_actions - 878 - INFO - rotate_notifs-13 - Rotating notifications up to: 2
2020-05-02 14:21:12,336 - synapse.storage.data_stores.main.event_push_actions - 913 - INFO - rotate_notifs-13 - Rotating notifications, handling 0 rows
2020-05-02 14:21:12,337 - synapse.storage.data_stores.main.event_push_actions - 947 - INFO - rotate_notifs-13 - Rotating notifications, deleted 0 push actions
2020-05-02 14:21:12,351 - synapse.storage.data_stores.main - 425 - INFO - generate_user_daily_visits-83 - Calling _generate_user_daily_visits
2020-05-02 14:24:02,323 - synapse.metrics - 464 - INFO - - Collecting gc 1
2020-05-02 14:24:02,326 - synapse.metrics - 464 - INFO - - Collecting gc 2
2020-05-02 14:26:12,336 - synapse.storage.data_stores.main - 425 - INFO - generate_user_daily_visits-84 - Calling _generate_user_daily_visits
2020-05-02 14:28:42,321 - synapse.metrics - 464 - INFO - - Collecting gc 1
2020-05-02 14:31:12,323 - synapse.storage.data_stores.main.event_push_actions - 499 - INFO - event_push_action_stream_orderings-42 - Searching for stream ordering 1 month ago
2020-05-02 14:31:12,326 - synapse.storage.data_stores.main.event_push_actions - 504 - INFO - event_push_action_stream_orderings-42 - Found stream ordering 1 month ago: it's 2
2020-05-02 14:31:12,327 - synapse.storage.data_stores.main.event_push_actions - 506 - INFO - event_push_action_stream_orderings-42 - Searching for stream ordering 1 day ago
2020-05-02 14:31:12,327 - synapse.storage.data_stores.main.event_push_actions - 511 - INFO - event_push_action_stream_orderings-42 - Found stream ordering 1 day ago: it's 2
2020-05-02 14:31:12,336 - synapse.storage.data_stores.main - 425 - INFO - generate_user_daily_visits-85 - Calling _generate_user_daily_visits
2020-05-02 14:34:22,322 - synapse.metrics - 464 - INFO - - Collecting gc 1