update voice heartbeat, fix the new test issue
This commit is contained in:
parent
2bf022924b
commit
a787a989ef
|
@ -233,7 +233,6 @@ dependencies = [
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rustls",
|
"rustls",
|
||||||
"rustls-native-certs",
|
"rustls-native-certs",
|
||||||
"safina-timer",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde-aux",
|
"serde-aux",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -1801,15 +1800,6 @@ version = "1.0.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
|
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "safina-timer"
|
|
||||||
version = "0.1.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1081a264d1a3e81b75c4bcd5696094fb6ce470c2ded14cbd47bcb5229079b9df"
|
|
||||||
dependencies = [
|
|
||||||
"once_cell",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "salsa20"
|
name = "salsa20"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
|
|
|
@ -11,7 +11,7 @@ website = ["https://discord.com/invite/m3FpcapGDD"]
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["client", "rt-multi-thread"]
|
default = ["client", "rt-multi-thread", "voice"]
|
||||||
backend = ["dep:poem", "dep:sqlx"]
|
backend = ["dep:poem", "dep:sqlx"]
|
||||||
rt-multi-thread = ["tokio/rt-multi-thread"]
|
rt-multi-thread = ["tokio/rt-multi-thread"]
|
||||||
rt = ["tokio/rt"]
|
rt = ["tokio/rt"]
|
||||||
|
@ -57,7 +57,6 @@ sqlx = { version = "0.7.3", features = [
|
||||||
], optional = true }
|
], optional = true }
|
||||||
discortp = { version = "0.5.0", optional = true, features = ["rtp", "discord", "demux"] }
|
discortp = { version = "0.5.0", optional = true, features = ["rtp", "discord", "demux"] }
|
||||||
crypto_secretbox = {version = "0.1.1", optional = true}
|
crypto_secretbox = {version = "0.1.1", optional = true}
|
||||||
safina-timer = "0.1.11"
|
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
|
|
|
@ -1,12 +1,25 @@
|
||||||
use std::{
|
|
||||||
sync::Arc,
|
|
||||||
time::{Duration, Instant},
|
|
||||||
};
|
|
||||||
|
|
||||||
use futures_util::SinkExt;
|
use futures_util::SinkExt;
|
||||||
use log::*;
|
use log::*;
|
||||||
use safina_timer::sleep_until;
|
|
||||||
use tokio::sync::{mpsc::Sender, Mutex};
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
use tokio::time::Instant;
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
use wasmtimer::std::Instant;
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
use tokio::time::sleep_until;
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
use wasmtimer::tokio::sleep_until;
|
||||||
|
|
||||||
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
|
use tokio::sync::{
|
||||||
|
mpsc::{Receiver, Sender},
|
||||||
|
Mutex,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
use tokio::task;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
gateway::heartbeat::HEARTBEAT_ACK_TIMEOUT,
|
gateway::heartbeat::HEARTBEAT_ACK_TIMEOUT,
|
||||||
|
@ -37,7 +50,7 @@ impl VoiceHeartbeatHandler {
|
||||||
let kill_receive = kill_rc.resubscribe();
|
let kill_receive = kill_rc.resubscribe();
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
tokio::task::spawn(async move {
|
task::spawn(async move {
|
||||||
Self::heartbeat_task(
|
Self::heartbeat_task(
|
||||||
websocket_tx,
|
websocket_tx,
|
||||||
heartbeat_interval,
|
heartbeat_interval,
|
||||||
|
@ -73,15 +86,13 @@ impl VoiceHeartbeatHandler {
|
||||||
websocket_tx: Arc<Mutex<Sink>>,
|
websocket_tx: Arc<Mutex<Sink>>,
|
||||||
heartbeat_interval: Duration,
|
heartbeat_interval: Duration,
|
||||||
starting_nonce: u64,
|
starting_nonce: u64,
|
||||||
mut receive: tokio::sync::mpsc::Receiver<VoiceHeartbeatThreadCommunication>,
|
mut receive: Receiver<VoiceHeartbeatThreadCommunication>,
|
||||||
mut kill_receive: tokio::sync::broadcast::Receiver<()>,
|
mut kill_receive: tokio::sync::broadcast::Receiver<()>,
|
||||||
) {
|
) {
|
||||||
let mut last_heartbeat_timestamp: Instant = Instant::now();
|
let mut last_heartbeat_timestamp: Instant = Instant::now();
|
||||||
let mut last_heartbeat_acknowledged = true;
|
let mut last_heartbeat_acknowledged = true;
|
||||||
let mut nonce: u64 = starting_nonce;
|
let mut nonce: u64 = starting_nonce;
|
||||||
|
|
||||||
safina_timer::start_timer_thread();
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if kill_receive.try_recv().is_ok() {
|
if kill_receive.try_recv().is_ok() {
|
||||||
trace!("VGW: Closing heartbeat task");
|
trace!("VGW: Closing heartbeat task");
|
||||||
|
|
|
@ -12,6 +12,16 @@ use wasm_bindgen_test::*;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
wasm_bindgen_test_configure!(run_in_browser);
|
wasm_bindgen_test_configure!(run_in_browser);
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
use tokio::time::Instant;
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
use wasmtimer::std::Instant;
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
use tokio::time::sleep;
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
use wasmtimer::tokio::sleep;
|
||||||
|
|
||||||
#[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 (hello and heartbeats) on the local gateway;
|
/// Tests establishing a connection (hello and heartbeats) on the local gateway;
|
||||||
|
@ -61,11 +71,9 @@ async fn test_gateway_authenticate() {
|
||||||
|
|
||||||
gateway.send_identify(identify).await;
|
gateway.send_identify(identify).await;
|
||||||
|
|
||||||
let current_time = std::time::Instant::now();
|
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
// Fail, we timed out waiting for it
|
// Fail, we timed out waiting for it
|
||||||
() = safina_timer::sleep_until(current_time + Duration::from_secs(20)) => {
|
() = sleep(Duration::from_secs(20)) => {
|
||||||
println!("Timed out waiting for event, failing..");
|
println!("Timed out waiting for event, failing..");
|
||||||
assert!(false);
|
assert!(false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue