MCPcopy Create free account
hub / github.com/buttplugio/buttplug / test_ping_timeout

Function test_ping_timeout

crates/buttplug_tests/tests/test_server.rs:172–211  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

170
171#[tokio::test]
172async fn test_ping_timeout() {
173 let server = ButtplugServerBuilder::default()
174 .max_ping_time(100)
175 .finish()
176 .expect("Test, assuming infallible.");
177 let recv = server.event_stream();
178 pin_mut!(recv);
179 let msg = RequestServerInfoV4::new(
180 "Test Client",
181 BUTTPLUG_CURRENT_API_MAJOR_VERSION,
182 BUTTPLUG_CURRENT_API_MINOR_VERSION,
183 );
184 sleep(Duration::from_millis(150)).await;
185 let reply = server
186 .parse_checked_message(ButtplugCheckedClientMessageV4::RequestServerInfo(msg))
187 .await;
188 assert!(
189 reply.is_ok(),
190 "ping timer shouldn't start until handshake finished. {:?}",
191 reply
192 );
193 sleep(Duration::from_millis(300)).await;
194 let pingmsg = PingV0::default();
195 let result = server
196 .parse_checked_message(ButtplugCheckedClientMessageV4::Ping(pingmsg))
197 .await;
198 let err = result.unwrap_err();
199 if !matches!(err.original_error(), ButtplugError::ButtplugPingError(_)) {
200 panic!("Got wrong type of error back!");
201 }
202 // Check that we got an event back about the ping out.
203 let msg = recv.next().await.expect("Test, assuming infallible.");
204 if let ButtplugServerMessageVariant::V4(ButtplugServerMessageV4::Error(e)) = msg {
205 if ErrorCode::ErrorPing != e.error_code() {
206 panic!("Didn't get a ping error");
207 }
208 } else {
209 panic!("Didn't get an error message back");
210 }
211}
212
213#[tokio::test]
214async fn test_device_stop_on_ping_timeout() {

Callers

nothing calls this directly

Calls 7

sleepFunction · 0.85
RequestServerInfoClass · 0.85
PingClass · 0.85
parse_checked_messageMethod · 0.80
finishMethod · 0.45
max_ping_timeMethod · 0.45
event_streamMethod · 0.45

Tested by

no test coverage detected