Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Add unit tests for the traffic watcher services (#27) #101

Merged
merged 37 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
82ae8ab
Pick peers module and related objects from the 'on-start-on-stop'
evdokimovs Apr 28, 2020
66c2342
Cleanup [run ci]
evdokimovs Apr 28, 2020
90242fc
Final reread [run ci]
evdokimovs Apr 28, 2020
5d9955a
Merge branch 'master' into traffic-watchers-impl [run ci]
evdokimovs Apr 28, 2020
f9d6d69
Minor config doc update [run ci]
evdokimovs Apr 28, 2020
160c8e5
Remove outdated TODO [run ci]
evdokimovs Apr 28, 2020
c6be452
review
alexlapa May 1, 2020
4e681e9
Merge branch 'master' into traffic-watchers-impl
alexlapa May 1, 2020
2e1efe4
Move received FlowMetricSources to the PeerStat [run ci]
evdokimovs May 1, 2020
19b011d
refactor [run ci]
alexlapa May 1, 2020
fd20a0c
Send tracks stopping from the PeerMetricsService [run ci];5D
evdokimovs May 4, 2020
69911f4
More stable 'rpc_settings_from_spec_works' E2E test [run ci]
evdokimovs May 4, 2020
69f767a
WIP: bitflag based MediaTrafficState tracking
evdokimovs May 5, 2020
2a1b08a
review
alexlapa May 6, 2020
eeb3bff
Merge remote-tracking branch 'origin/traffic-watchers-impl' into traf…
alexlapa May 6, 2020
c5dfbcc
review
alexlapa May 6, 2020
48b6be9
Fix docs, fix double HashMap lookup
evdokimovs May 6, 2020
cb7f4f1
Merge branch 'traffic-watchers-impl' of github.com:instrumentisto/med…
evdokimovs May 6, 2020
34b9e7f
Final doc improvements [run ci]
evdokimovs May 6, 2020
fbe274a
minor refactor
alexlapa May 6, 2020
a39292f
Add TrafficWatcher unit tests
evdokimovs May 11, 2020
a76d9fd
All tests done
evdokimovs May 12, 2020
2f3ee14
Add docs
evdokimovs May 12, 2020
d8fbbce
Fix module visibility
evdokimovs May 12, 2020
ea1e731
Merge branch 'master' into traffic-watchers-tests
evdokimovs May 12, 2020
895bc4e
Reread [run ci]
evdokimovs May 12, 2020
be22ae4
Cleanup dead code [run ci]
evdokimovs May 12, 2020
8cdbb5f
refactor
alexlapa May 13, 2020
91c1d7e
Fix docs [run ci]
evdokimovs May 13, 2020
18648bf
improve tests [run ci]
alexlapa May 19, 2020
6ae2fe7
Fix wrong NoTrafficFlowing emitting [run ci]
evdokimovs May 21, 2020
1fe1578
Remove unneeded code [run ci]
evdokimovs May 21, 2020
fa35bed
Merge branch 'master' into traffic-watchers-tests
alexlapa May 22, 2020
789629f
fix merge [run ci]
alexlapa May 22, 2020
607f624
Merge branch 'master' into traffic-watchers-tests
alexlapa May 29, 2020
651f1d7
cargo update, revert some unnecessary changes
alexlapa May 29, 2020
b9c7ea2
Minor corrections
tyranron May 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 42 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions proto/client-api/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,18 @@ impl From<HighResTimeStamp> for SystemTime {
}
}

impl From<SystemTime> for HighResTimeStamp {
#[allow(clippy::cast_precision_loss)]
#[inline]
fn from(time: SystemTime) -> Self {
HighResTimeStamp(
time.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis() as f64,
)
}
}

/// Hashing string representation.
///
/// Some people believe that such behavior is incorrect (but in some programming
Expand Down
2 changes: 1 addition & 1 deletion src/api/control/refs/fid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl TryFrom<String> for StatefulFid {
member_id
}
} else {
return Ok(Fid::<ToRoom>::new(room_id.to_string().into()).into());
return Ok(Fid::<ToRoom>::new(room_id.into()).into());
};

let endpoint_id = if let Some(endpoint_id) = splitted.next() {
Expand Down
63 changes: 63 additions & 0 deletions src/media/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,66 @@ impl Peer<Stable> {
Ok(mids)
}
}

#[cfg(test)]
pub mod tests {
use super::*;

/// Returns [`PeerStateMachine`] with provided count of the `MediaTrack`s
/// media types.
pub fn test_peer_from_peer_tracks(
send_audio: u32,
send_video: u32,
recv_audio: u32,
recv_video: u32,
) -> PeerStateMachine {
let mut peer = Peer {
state: Stable {},
context: Context {
id: Id(1),
sdp_offer: None,
sdp_answer: None,
senders: HashMap::new(),
receivers: HashMap::new(),
member_id: MemberId::from("test-member"),
is_force_relayed: false,
partner_peer: Id(2),
ice_user: None,
endpoints: Vec::new(),
partner_member: MemberId::from("partner-member"),
},
};

let mut track_id_counter = Counter::default();

for _ in 0..send_audio {
let track_id = track_id_counter.next_id();
let track =
MediaTrack::new(track_id, MediaType::Audio(AudioSettings {}));
peer.context.senders.insert(track_id, Rc::new(track));
}

for _ in 0..send_video {
let track_id = track_id_counter.next_id();
let track =
MediaTrack::new(track_id, MediaType::Video(VideoSettings {}));
peer.context.senders.insert(track_id, Rc::new(track));
}

for _ in 0..recv_audio {
let track_id = track_id_counter.next_id();
let track =
MediaTrack::new(track_id, MediaType::Audio(AudioSettings {}));
peer.context.receivers.insert(track_id, Rc::new(track));
}

for _ in 0..recv_video {
let track_id = track_id_counter.next_id();
let track =
MediaTrack::new(track_id, MediaType::Video(VideoSettings {}));
peer.context.receivers.insert(track_id, Rc::new(track));
}

peer.into()
}
}
22 changes: 22 additions & 0 deletions src/signalling/peers/media_traffic_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ mod tracks_state_tests {
get_diff_added(state_before, state_after).unwrap(),
MediaType::Video
);

let state_before = MediaTrafficState::with_media_type(MediaType::Audio);
let state_after = MediaTrafficState::with_media_type(MediaType::Both);
assert_eq!(
get_diff_added(state_before, state_after).unwrap(),
MediaType::Video,
);

let state_before = MediaTrafficState::with_media_type(MediaType::Video);
let state_after = MediaTrafficState::with_media_type(MediaType::Both);
assert_eq!(
get_diff_added(state_before, state_after).unwrap(),
MediaType::Audio,
);
}

#[test]
Expand Down Expand Up @@ -278,5 +292,13 @@ mod tracks_state_tests {
let before = MediaTrafficState::new();
let after = MediaTrafficState::with_media_type(MediaType::Both);
assert!(get_diff_removed(before, after).is_none());

let before = MediaTrafficState::with_media_type(MediaType::Both);
let after = MediaTrafficState::with_media_type(MediaType::Audio);
assert_eq!(get_diff_removed(before, after).unwrap(), MediaType::Video);

let before = MediaTrafficState::with_media_type(MediaType::Both);
let after = MediaTrafficState::with_media_type(MediaType::Video);
assert_eq!(get_diff_removed(before, after).unwrap(), MediaType::Audio);
}
}
Loading