aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/tests
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-03-25 05:16:10 +0000
committermat <git@matdoes.dev>2025-03-25 05:16:10 +0000
commit8af265e48bf9f3d5263c074d034770e4216bb3f3 (patch)
tree2605ce1d6ed8c74d47b6c355e6918721b0dc07aa /azalea-client/tests
parent4c53498f0795f821066941f39917ad2e4fa9a3cc (diff)
downloadazalea-drasl-8af265e48bf9f3d5263c074d034770e4216bb3f3.tar.xz
PongPlugin
Diffstat (limited to 'azalea-client/tests')
-rw-r--r--azalea-client/tests/reply_to_ping_with_pong.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/azalea-client/tests/reply_to_ping_with_pong.rs b/azalea-client/tests/reply_to_ping_with_pong.rs
new file mode 100644
index 00000000..4ef5b2cc
--- /dev/null
+++ b/azalea-client/tests/reply_to_ping_with_pong.rs
@@ -0,0 +1,35 @@
+use std::sync::Arc;
+
+use azalea_client::{packet::game::SendPacketEvent, test_simulation::*};
+use azalea_protocol::packets::{
+ ConnectionProtocol,
+ game::{ClientboundPing, ServerboundGamePacket},
+};
+use bevy_ecs::observer::Trigger;
+use bevy_log::tracing_subscriber;
+use parking_lot::Mutex;
+
+#[test]
+fn reply_to_ping_with_pong() {
+ let _ = tracing_subscriber::fmt::try_init();
+
+ let mut simulation = Simulation::new(ConnectionProtocol::Game);
+ let reply_count = Arc::new(Mutex::new(0));
+ let reply_count_clone = reply_count.clone();
+ simulation
+ .app
+ .add_observer(move |trigger: Trigger<SendPacketEvent>| {
+ if trigger.sent_by == simulation.entity {
+ if let ServerboundGamePacket::Pong(packet) = &trigger.packet {
+ assert_eq!(packet.id, 123);
+ *reply_count_clone.lock() += 1;
+ }
+ }
+ });
+
+ simulation.tick();
+ simulation.receive_packet(ClientboundPing { id: 123 });
+ simulation.tick();
+
+ assert_eq!(*reply_count.lock(), 1);
+}