Compare commits

..

4 Commits

Author SHA1 Message Date
kozabrada123 9622415d0d
Merge badf3e9d47 into 82a3f98db7 2024-01-18 16:09:43 +00:00
kozabrada123 badf3e9d47 testing tests 2024-01-18 17:10:11 +01:00
kozabrada123 f7a2285dd5 tests: better gateway auth test 2024-01-18 16:27:45 +01:00
kozabrada123 6f9ed86a4c chore: json isn't a doc test 2024-01-18 16:27:07 +01:00
2 changed files with 44 additions and 3 deletions

View File

@ -12,12 +12,12 @@ use serde::{Deserialize, Serialize};
/// Examples of the event: /// Examples of the event:
/// ///
/// When receiving: /// When receiving:
/// ``` /// ```json
/// {"op":12,"d":{"video_ssrc":0,"user_id":"463640391196082177","streams":[{"ssrc":26595,"rtx_ssrc":26596,"rid":"100","quality":100,"max_resolution":{"width":1280,"type":"fixed","height":720},"max_framerate":30,"active":false}],"audio_ssrc":26597}}{"op":12,"d":{"video_ssrc":0,"user_id":"463640391196082177","streams":[{"ssrc":26595,"rtx_ssrc":26596,"rid":"100","quality":100,"max_resolution":{"width":1280,"type":"fixed","height":720},"max_framerate":30,"active":false}],"audio_ssrc":26597}} /// {"op":12,"d":{"video_ssrc":0,"user_id":"463640391196082177","streams":[{"ssrc":26595,"rtx_ssrc":26596,"rid":"100","quality":100,"max_resolution":{"width":1280,"type":"fixed","height":720},"max_framerate":30,"active":false}],"audio_ssrc":26597}}{"op":12,"d":{"video_ssrc":0,"user_id":"463640391196082177","streams":[{"ssrc":26595,"rtx_ssrc":26596,"rid":"100","quality":100,"max_resolution":{"width":1280,"type":"fixed","height":720},"max_framerate":30,"active":false}],"audio_ssrc":26597}}
/// ``` /// ```
/// ///
/// When sending: /// When sending:
/// ``` /// ```json
/// {"op":12,"d":{"audio_ssrc":2307250864,"video_ssrc":0,"rtx_ssrc":0,"streams":[{"type":"video","rid":"100","ssrc":26595,"active":false,"quality":100,"rtx_ssrc":26596,"max_bitrate":2500000,"max_framerate":30,"max_resolution":{"type":"fixed","width":1280,"height":720}}]}} /// {"op":12,"d":{"audio_ssrc":2307250864,"video_ssrc":0,"rtx_ssrc":0,"streams":[{"type":"video","rid":"100","ssrc":26595,"active":false,"quality":100,"rtx_ssrc":26596,"max_bitrate":2500000,"max_framerate":30,"max_resolution":{"type":"fixed","width":1280,"height":720}}]}}
/// ``` /// ```
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq)] #[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq)]

View File

@ -1,10 +1,12 @@
mod common; mod common;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use std::time::Duration;
use async_trait::async_trait;
use chorus::errors::GatewayError; use chorus::errors::GatewayError;
use chorus::gateway::*; use chorus::gateway::*;
use chorus::types::{self, ChannelModifySchema, RoleCreateModifySchema, RoleObject}; use chorus::types::{self, ChannelModifySchema, GatewayReady, RoleCreateModifySchema, RoleObject};
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*; use wasm_bindgen_test::*;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
@ -20,6 +22,18 @@ async fn test_gateway_establish() {
common::teardown(bundle).await common::teardown(bundle).await
} }
#[derive(Debug)]
struct GatewayReadyObserver {
channel: tokio::sync::mpsc::Sender<()>,
}
#[async_trait]
impl Observer<GatewayReady> for GatewayReadyObserver {
async fn update(&self, _data: &GatewayReady) {
self.channel.send(()).await.unwrap();
}
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] #[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
/// Tests establishing a connection and authenticating /// Tests establishing a connection and authenticating
@ -28,10 +42,37 @@ async fn test_gateway_authenticate() {
let gateway: GatewayHandle = Gateway::spawn(bundle.urls.wss.clone()).await.unwrap(); let gateway: GatewayHandle = Gateway::spawn(bundle.urls.wss.clone()).await.unwrap();
let (ready_send, mut ready_receive) = tokio::sync::mpsc::channel(1);
let observer = Arc::new(GatewayReadyObserver {
channel: ready_send,
});
gateway
.events
.lock()
.await
.session
.ready
.subscribe(observer);
let mut identify = types::GatewayIdentifyPayload::common(); let mut identify = types::GatewayIdentifyPayload::common();
identify.token = bundle.user.token.clone(); identify.token = bundle.user.token.clone();
gateway.send_identify(identify).await; gateway.send_identify(identify).await;
let current_time = std::time::Instant::now();
tokio::select! {
// Fail, we timed out waiting for it
() = safina_timer::sleep_until(current_time + Duration::from_secs(20)) => {
println!("Timed out waiting for event, failing..");
assert!(false);
}
// Sucess, we have received it
Some(_) = ready_receive.recv() => {}
};
common::teardown(bundle).await common::teardown(bundle).await
} }