refactor(audio,state): remove dead code (TODO-001,002,004)
Remove unused AudioFrame10ms/20ms structs, disable_failed_vad_backend(), and ServerState dead accessors (replace_from_snapshot, channel_count, client_count). Update tests to use .channels().count()/.clients().count().
This commit is contained in:
@@ -110,11 +110,6 @@ impl ServerState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Replace state with a fresh snapshot (post-reconnect). Satisfies SRS-059.
|
||||
pub fn replace_from_snapshot(&mut self, snapshot: ServerSnapshot) {
|
||||
*self = Self::from_snapshot(snapshot);
|
||||
}
|
||||
|
||||
/// Look up a channel by id.
|
||||
pub fn channel(&self, id: ChannelId) -> Option<&ChannelInfo> {
|
||||
self.channels.get(&id.0)
|
||||
@@ -144,16 +139,6 @@ impl ServerState {
|
||||
.filter_map(|id| self.clients.get(id))
|
||||
}
|
||||
|
||||
/// Number of channels.
|
||||
pub fn channel_count(&self) -> usize {
|
||||
self.channels.len()
|
||||
}
|
||||
|
||||
/// Number of clients.
|
||||
pub fn client_count(&self) -> usize {
|
||||
self.clients.len()
|
||||
}
|
||||
|
||||
/// The channel our own client is currently in.
|
||||
pub fn own_channel(&self) -> Option<&ChannelInfo> {
|
||||
self.client(ClientId(self.own_client_id))
|
||||
@@ -463,8 +448,8 @@ mod tests {
|
||||
assert!(state.is_some());
|
||||
let s = state.as_ref().unwrap();
|
||||
assert_eq!(s.connection_state, ConnectionState::Ready);
|
||||
assert_eq!(s.channel_count(), 2);
|
||||
assert_eq!(s.client_count(), 1);
|
||||
assert_eq!(s.channels().count(), 2);
|
||||
assert_eq!(s.clients().count(), 1);
|
||||
assert_eq!(s.own_client_id, 10);
|
||||
assert_eq!(
|
||||
reduction.deltas,
|
||||
@@ -489,7 +474,7 @@ mod tests {
|
||||
};
|
||||
let reduction = reduce(&mut state, StateEvent::ChannelChanged(ch.clone()));
|
||||
let s = state.as_ref().unwrap();
|
||||
assert_eq!(s.channel_count(), 3);
|
||||
assert_eq!(s.channels().count(), 3);
|
||||
assert!(s.channel(ChannelId(3)).is_some());
|
||||
assert!(matches!(&reduction.deltas[..], [Delta::ChannelUpserted(_)]));
|
||||
let updated = ChannelInfo {
|
||||
@@ -501,7 +486,7 @@ mod tests {
|
||||
state.as_ref().unwrap().channel(ChannelId(3)).unwrap().name,
|
||||
"renamed"
|
||||
);
|
||||
assert_eq!(state.as_ref().unwrap().channel_count(), 3);
|
||||
assert_eq!(state.as_ref().unwrap().channels().count(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -510,7 +495,7 @@ mod tests {
|
||||
reduce(&mut state, StateEvent::Snapshot(sample_snapshot()));
|
||||
let reduction = reduce(&mut state, StateEvent::ChannelDeleted(ChannelId(2)));
|
||||
let s = state.as_ref().unwrap();
|
||||
assert_eq!(s.channel_count(), 1);
|
||||
assert_eq!(s.channels().count(), 1);
|
||||
assert!(s.channel(ChannelId(2)).is_none());
|
||||
assert!(matches!(&reduction.deltas[..], [Delta::ChannelRemoved(_)]));
|
||||
}
|
||||
@@ -528,7 +513,7 @@ mod tests {
|
||||
assert!(s.channel(ChannelId(2)).is_none());
|
||||
assert!(s.client(ClientId(20)).is_none());
|
||||
assert!(s.client(ClientId(30)).is_none());
|
||||
assert_eq!(s.client_count(), 1);
|
||||
assert_eq!(s.clients().count(), 1);
|
||||
assert_eq!(s.clients_in_channel(ChannelId(2)).count(), 0);
|
||||
assert_eq!(
|
||||
reduction.deltas,
|
||||
@@ -547,7 +532,7 @@ mod tests {
|
||||
let new_client = sample_client(20, 2);
|
||||
let reduction = reduce(&mut state, StateEvent::ClientChanged(new_client));
|
||||
let s = state.as_ref().unwrap();
|
||||
assert_eq!(s.client_count(), 2);
|
||||
assert_eq!(s.clients().count(), 2);
|
||||
assert!(matches!(&reduction.deltas[..], [Delta::ClientUpserted(_)]));
|
||||
let moved = ClientInfo {
|
||||
channel: ChannelId(2),
|
||||
@@ -570,7 +555,7 @@ mod tests {
|
||||
let mut state = None;
|
||||
reduce(&mut state, StateEvent::Snapshot(sample_snapshot()));
|
||||
let reduction = reduce(&mut state, StateEvent::ClientLeft(ClientId(10)));
|
||||
assert_eq!(state.as_ref().unwrap().client_count(), 0);
|
||||
assert_eq!(state.as_ref().unwrap().clients().count(), 0);
|
||||
assert!(matches!(&reduction.deltas[..], [Delta::ClientRemoved(_)]));
|
||||
}
|
||||
|
||||
@@ -578,7 +563,7 @@ mod tests {
|
||||
fn reconnect_discards_stale_state() {
|
||||
let mut state = None;
|
||||
reduce(&mut state, StateEvent::Snapshot(sample_snapshot()));
|
||||
assert_eq!(state.as_ref().unwrap().channel_count(), 2);
|
||||
assert_eq!(state.as_ref().unwrap().channels().count(), 2);
|
||||
let reduction = reduce(&mut state, StateEvent::ReconnectStarted);
|
||||
assert!(state.is_none());
|
||||
assert!(matches!(
|
||||
@@ -594,8 +579,8 @@ mod tests {
|
||||
reduce_reconnect_snapshot(&mut state, snap2);
|
||||
let s = state.as_ref().unwrap();
|
||||
assert_eq!(s.server_name, "New Server");
|
||||
assert_eq!(s.channel_count(), 1);
|
||||
assert_eq!(s.client_count(), 1);
|
||||
assert_eq!(s.channels().count(), 1);
|
||||
assert_eq!(s.clients().count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -685,9 +670,7 @@ mod tests {
|
||||
let reduction = reduce(&mut state, StateEvent::Snapshot(snapshot));
|
||||
let s = state.as_ref().unwrap();
|
||||
|
||||
assert_eq!(s.channel_count(), 2);
|
||||
assert_eq!(s.channels().count(), 2);
|
||||
assert_eq!(s.client_count(), 1);
|
||||
assert_eq!(s.clients().count(), 1);
|
||||
assert_eq!(s.channel(ChannelId(1)).unwrap().name, "duplicate");
|
||||
assert_eq!(s.client(ClientId(10)).unwrap().channel, ChannelId(2));
|
||||
@@ -766,7 +749,7 @@ mod tests {
|
||||
reduce(&mut state, StateEvent::Snapshot(sample_snapshot()));
|
||||
let reduction = reduce(&mut state, StateEvent::ChannelDeleted(ChannelId(999)));
|
||||
assert!(reduction.deltas.is_empty());
|
||||
assert_eq!(state.as_ref().unwrap().channel_count(), 2);
|
||||
assert_eq!(state.as_ref().unwrap().channels().count(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -795,12 +778,12 @@ mod tests {
|
||||
deltas_b.extend(reduce(&mut b, e.clone()).deltas);
|
||||
}
|
||||
assert_eq!(
|
||||
a.as_ref().unwrap().channel_count(),
|
||||
b.as_ref().unwrap().channel_count()
|
||||
a.as_ref().unwrap().channels().count(),
|
||||
b.as_ref().unwrap().channels().count()
|
||||
);
|
||||
assert_eq!(
|
||||
a.as_ref().unwrap().client_count(),
|
||||
b.as_ref().unwrap().client_count()
|
||||
a.as_ref().unwrap().clients().count(),
|
||||
b.as_ref().unwrap().clients().count()
|
||||
);
|
||||
assert_eq!(
|
||||
a.as_ref().unwrap().own_client_id,
|
||||
|
||||
Reference in New Issue
Block a user