mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
add support for panicking on warn/error in simulation tests
This commit is contained in:
parent
338f931c51
commit
3087b0c996
16 changed files with 76 additions and 37 deletions
|
@ -17,7 +17,7 @@ pub mod player;
|
||||||
mod plugins;
|
mod plugins;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod test_simulation;
|
pub mod test_utils;
|
||||||
|
|
||||||
pub use account::{Account, AccountOpts};
|
pub use account::{Account, AccountOpts};
|
||||||
pub use azalea_protocol::common::client_information::ClientInformation;
|
pub use azalea_protocol::common::client_information::ClientInformation;
|
||||||
|
|
|
@ -3,6 +3,7 @@ use std::{net::SocketAddr, sync::Arc};
|
||||||
use azalea_entity::{LocalEntity, indexing::EntityUuidIndex};
|
use azalea_entity::{LocalEntity, indexing::EntityUuidIndex};
|
||||||
use azalea_protocol::{
|
use azalea_protocol::{
|
||||||
ServerAddress,
|
ServerAddress,
|
||||||
|
common::client_information::ClientInformation,
|
||||||
connect::{Connection, ConnectionError, Proxy},
|
connect::{Connection, ConnectionError, Proxy},
|
||||||
packets::{
|
packets::{
|
||||||
ClientIntention, ConnectionProtocol, PROTOCOL_VERSION,
|
ClientIntention, ConnectionProtocol, PROTOCOL_VERSION,
|
||||||
|
@ -215,7 +216,7 @@ pub fn poll_create_connection_task(
|
||||||
write_conn,
|
write_conn,
|
||||||
ConnectionProtocol::Login,
|
ConnectionProtocol::Login,
|
||||||
),
|
),
|
||||||
client_information: crate::ClientInformation::default(),
|
client_information: ClientInformation::default(),
|
||||||
instance_holder,
|
instance_holder,
|
||||||
metadata: azalea_entity::metadata::PlayerMetadataBundle::default(),
|
metadata: azalea_entity::metadata::PlayerMetadataBundle::default(),
|
||||||
},
|
},
|
||||||
|
|
6
azalea-client/src/test_utils/mod.rs
Normal file
6
azalea-client/src/test_utils/mod.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
pub mod simulation;
|
||||||
|
pub mod tracing;
|
||||||
|
|
||||||
|
pub mod prelude {
|
||||||
|
pub use super::{simulation::*, tracing::*};
|
||||||
|
}
|
38
azalea-client/src/test_utils/tracing.rs
Normal file
38
azalea-client/src/test_utils/tracing.rs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
use bevy_log::tracing_subscriber::{
|
||||||
|
self, EnvFilter, Layer,
|
||||||
|
layer::{Context, SubscriberExt},
|
||||||
|
registry::LookupSpan,
|
||||||
|
util::SubscriberInitExt,
|
||||||
|
};
|
||||||
|
use tracing::{Event, Level, Subscriber, level_filters::LevelFilter};
|
||||||
|
|
||||||
|
pub fn init_tracing() {
|
||||||
|
init_tracing_with_level(Level::WARN);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_tracing_with_level(max_level: Level) {
|
||||||
|
tracing_subscriber::registry()
|
||||||
|
.with(
|
||||||
|
tracing_subscriber::fmt::layer().with_filter(
|
||||||
|
EnvFilter::builder()
|
||||||
|
.with_default_directive(max_level.into())
|
||||||
|
.from_env_lossy(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.with(TestTracingLayer {
|
||||||
|
panic_on_level: max_level,
|
||||||
|
})
|
||||||
|
.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TestTracingLayer {
|
||||||
|
panic_on_level: Level,
|
||||||
|
}
|
||||||
|
impl<S: Subscriber> Layer<S> for TestTracingLayer {
|
||||||
|
fn on_event(&self, event: &Event<'_>, _ctx: Context<'_, S>) {
|
||||||
|
let level = *event.metadata().level();
|
||||||
|
if level <= self.panic_on_level {
|
||||||
|
panic!("logged on level {level}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
use azalea_client::{InConfigState, InGameState, test_simulation::*};
|
use azalea_client::{InConfigState, InGameState, test_utils::prelude::*};
|
||||||
use azalea_core::{position::ChunkPos, resource_location::ResourceLocation};
|
use azalea_core::{position::ChunkPos, resource_location::ResourceLocation};
|
||||||
use azalea_entity::LocalEntity;
|
use azalea_entity::LocalEntity;
|
||||||
use azalea_protocol::packets::{
|
use azalea_protocol::packets::{
|
||||||
|
@ -7,12 +7,11 @@ use azalea_protocol::packets::{
|
||||||
};
|
};
|
||||||
use azalea_registry::{DataRegistry, DimensionType};
|
use azalea_registry::{DataRegistry, DimensionType};
|
||||||
use azalea_world::InstanceName;
|
use azalea_world::InstanceName;
|
||||||
use bevy_log::tracing_subscriber;
|
|
||||||
use simdnbt::owned::{NbtCompound, NbtTag};
|
use simdnbt::owned::{NbtCompound, NbtTag};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_change_dimension_to_nether_and_back() {
|
fn test_change_dimension_to_nether_and_back() {
|
||||||
let _ = tracing_subscriber::fmt().try_init();
|
init_tracing();
|
||||||
|
|
||||||
generic_test_change_dimension_to_nether_and_back(true);
|
generic_test_change_dimension_to_nether_and_back(true);
|
||||||
generic_test_change_dimension_to_nether_and_back(false);
|
generic_test_change_dimension_to_nether_and_back(false);
|
||||||
|
@ -29,8 +28,6 @@ fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = tracing_subscriber::fmt::try_init();
|
|
||||||
|
|
||||||
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
||||||
assert!(simulation.has_component::<InConfigState>());
|
assert!(simulation.has_component::<InConfigState>());
|
||||||
assert!(!simulation.has_component::<InGameState>());
|
assert!(!simulation.has_component::<InGameState>());
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use azalea_client::test_simulation::*;
|
use azalea_client::test_utils::prelude::*;
|
||||||
use azalea_protocol::packets::ConnectionProtocol;
|
use azalea_protocol::packets::ConnectionProtocol;
|
||||||
use azalea_world::InstanceName;
|
use azalea_world::InstanceName;
|
||||||
use bevy_log::tracing_subscriber;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_client_disconnect() {
|
fn test_client_disconnect() {
|
||||||
let _ = tracing_subscriber::fmt::try_init();
|
init_tracing();
|
||||||
|
|
||||||
let mut simulation = Simulation::new(ConnectionProtocol::Game);
|
let mut simulation = Simulation::new(ConnectionProtocol::Game);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use azalea_client::test_simulation::*;
|
use azalea_client::test_utils::prelude::*;
|
||||||
use azalea_core::{position::ChunkPos, resource_location::ResourceLocation};
|
use azalea_core::{position::ChunkPos, resource_location::ResourceLocation};
|
||||||
use azalea_entity::metadata::Cow;
|
use azalea_entity::metadata::Cow;
|
||||||
use azalea_protocol::packets::{
|
use azalea_protocol::packets::{
|
||||||
|
@ -7,12 +7,11 @@ use azalea_protocol::packets::{
|
||||||
};
|
};
|
||||||
use azalea_registry::{DataRegistry, DimensionType, EntityKind};
|
use azalea_registry::{DataRegistry, DimensionType, EntityKind};
|
||||||
use bevy_ecs::query::With;
|
use bevy_ecs::query::With;
|
||||||
use bevy_log::tracing_subscriber;
|
|
||||||
use simdnbt::owned::{NbtCompound, NbtTag};
|
use simdnbt::owned::{NbtCompound, NbtTag};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_despawn_entities_when_changing_dimension() {
|
fn test_despawn_entities_when_changing_dimension() {
|
||||||
let _ = tracing_subscriber::fmt::try_init();
|
init_tracing();
|
||||||
|
|
||||||
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
||||||
simulation.receive_packet(ClientboundRegistryData {
|
simulation.receive_packet(ClientboundRegistryData {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use azalea_client::{InConfigState, test_simulation::*};
|
use azalea_client::{InConfigState, test_utils::prelude::*};
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_core::resource_location::ResourceLocation;
|
||||||
use azalea_entity::metadata::Health;
|
use azalea_entity::metadata::Health;
|
||||||
use azalea_protocol::packets::{
|
use azalea_protocol::packets::{
|
||||||
|
@ -6,12 +6,11 @@ use azalea_protocol::packets::{
|
||||||
config::{ClientboundFinishConfiguration, ClientboundRegistryData},
|
config::{ClientboundFinishConfiguration, ClientboundRegistryData},
|
||||||
game::ClientboundSetHealth,
|
game::ClientboundSetHealth,
|
||||||
};
|
};
|
||||||
use bevy_log::tracing_subscriber;
|
|
||||||
use simdnbt::owned::{NbtCompound, NbtTag};
|
use simdnbt::owned::{NbtCompound, NbtTag};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fast_login() {
|
fn test_fast_login() {
|
||||||
let _ = tracing_subscriber::fmt::try_init();
|
init_tracing();
|
||||||
|
|
||||||
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
||||||
assert!(simulation.has_component::<InConfigState>());
|
assert!(simulation.has_component::<InConfigState>());
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use azalea_client::{InConfigState, InGameState, local_player::InstanceHolder, test_simulation::*};
|
use azalea_client::{
|
||||||
|
InConfigState, InGameState, local_player::InstanceHolder, test_utils::prelude::*,
|
||||||
|
};
|
||||||
use azalea_core::{position::ChunkPos, resource_location::ResourceLocation};
|
use azalea_core::{position::ChunkPos, resource_location::ResourceLocation};
|
||||||
use azalea_entity::LocalEntity;
|
use azalea_entity::LocalEntity;
|
||||||
use azalea_protocol::packets::{
|
use azalea_protocol::packets::{
|
||||||
|
@ -8,12 +10,11 @@ use azalea_protocol::packets::{
|
||||||
};
|
};
|
||||||
use azalea_registry::{DataRegistry, DimensionType};
|
use azalea_registry::{DataRegistry, DimensionType};
|
||||||
use azalea_world::InstanceName;
|
use azalea_world::InstanceName;
|
||||||
use bevy_log::tracing_subscriber;
|
|
||||||
use simdnbt::owned::{NbtCompound, NbtTag};
|
use simdnbt::owned::{NbtCompound, NbtTag};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_login_to_dimension_with_same_name() {
|
fn test_login_to_dimension_with_same_name() {
|
||||||
let _ = tracing_subscriber::fmt().try_init();
|
init_tracing();
|
||||||
|
|
||||||
generic_test_login_to_dimension_with_same_name(true);
|
generic_test_login_to_dimension_with_same_name(true);
|
||||||
generic_test_login_to_dimension_with_same_name(false);
|
generic_test_login_to_dimension_with_same_name(false);
|
||||||
|
@ -30,8 +31,6 @@ fn generic_test_login_to_dimension_with_same_name(using_respawn: bool) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = tracing_subscriber::fmt::try_init();
|
|
||||||
|
|
||||||
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
||||||
assert!(simulation.has_component::<InConfigState>());
|
assert!(simulation.has_component::<InConfigState>());
|
||||||
assert!(!simulation.has_component::<InGameState>());
|
assert!(!simulation.has_component::<InGameState>());
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
use azalea_client::test_simulation::*;
|
use azalea_client::test_utils::prelude::*;
|
||||||
use azalea_core::{position::ChunkPos, resource_location::ResourceLocation};
|
use azalea_core::{position::ChunkPos, resource_location::ResourceLocation};
|
||||||
use azalea_entity::metadata::Cow;
|
use azalea_entity::metadata::Cow;
|
||||||
use azalea_protocol::packets::{ConnectionProtocol, game::ClientboundMoveEntityRot};
|
use azalea_protocol::packets::{ConnectionProtocol, game::ClientboundMoveEntityRot};
|
||||||
use azalea_registry::{DataRegistry, DimensionType, EntityKind};
|
use azalea_registry::{DataRegistry, DimensionType, EntityKind};
|
||||||
use azalea_world::MinecraftEntityId;
|
use azalea_world::MinecraftEntityId;
|
||||||
use bevy_ecs::query::With;
|
use bevy_ecs::query::With;
|
||||||
use bevy_log::tracing_subscriber;
|
use tracing::Level;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_move_despawned_entity() {
|
fn test_move_despawned_entity() {
|
||||||
let _ = tracing_subscriber::fmt::try_init();
|
init_tracing_with_level(Level::ERROR); // a warning is expected here
|
||||||
|
|
||||||
let mut simulation = Simulation::new(ConnectionProtocol::Game);
|
let mut simulation = Simulation::new(ConnectionProtocol::Game);
|
||||||
simulation.receive_packet(make_basic_login_packet(
|
simulation.receive_packet(make_basic_login_packet(
|
||||||
|
@ -26,7 +26,7 @@ fn test_move_despawned_entity() {
|
||||||
// make sure it's spawned
|
// make sure it's spawned
|
||||||
let mut cow_query = simulation.app.world_mut().query_filtered::<(), With<Cow>>();
|
let mut cow_query = simulation.app.world_mut().query_filtered::<(), With<Cow>>();
|
||||||
let cow_iter = cow_query.iter(simulation.app.world());
|
let cow_iter = cow_query.iter(simulation.app.world());
|
||||||
assert_eq!(cow_iter.count(), 1, "cow should be despawned");
|
assert_eq!(cow_iter.count(), 1, "cow should be spawned");
|
||||||
|
|
||||||
// despawn the cow by receiving a login packet
|
// despawn the cow by receiving a login packet
|
||||||
simulation.receive_packet(make_basic_login_packet(
|
simulation.receive_packet(make_basic_login_packet(
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use azalea_client::{InConfigState, test_simulation::*};
|
use azalea_client::{InConfigState, test_utils::prelude::*};
|
||||||
use azalea_core::{position::Vec3, resource_location::ResourceLocation};
|
use azalea_core::{position::Vec3, resource_location::ResourceLocation};
|
||||||
use azalea_protocol::packets::{
|
use azalea_protocol::packets::{
|
||||||
ConnectionProtocol,
|
ConnectionProtocol,
|
||||||
|
@ -6,12 +6,11 @@ use azalea_protocol::packets::{
|
||||||
};
|
};
|
||||||
use azalea_registry::{DataRegistry, DimensionType, EntityKind};
|
use azalea_registry::{DataRegistry, DimensionType, EntityKind};
|
||||||
use azalea_world::InstanceName;
|
use azalea_world::InstanceName;
|
||||||
use bevy_log::tracing_subscriber;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_receive_spawn_entity_and_start_config_packet() {
|
fn test_receive_spawn_entity_and_start_config_packet() {
|
||||||
let _ = tracing_subscriber::fmt::try_init();
|
init_tracing();
|
||||||
|
|
||||||
let mut simulation = Simulation::new(ConnectionProtocol::Game);
|
let mut simulation = Simulation::new(ConnectionProtocol::Game);
|
||||||
simulation.receive_packet(make_basic_login_packet(
|
simulation.receive_packet(make_basic_login_packet(
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
use azalea_client::{InConfigState, packet::game::SendPacketEvent, test_simulation::*};
|
use azalea_client::{InConfigState, packet::game::SendPacketEvent, test_utils::prelude::*};
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_core::resource_location::ResourceLocation;
|
||||||
use azalea_protocol::packets::{ConnectionProtocol, game::ClientboundStartConfiguration};
|
use azalea_protocol::packets::{ConnectionProtocol, game::ClientboundStartConfiguration};
|
||||||
use azalea_registry::{DataRegistry, DimensionType};
|
use azalea_registry::{DataRegistry, DimensionType};
|
||||||
use azalea_world::InstanceName;
|
use azalea_world::InstanceName;
|
||||||
use bevy_ecs::event::Events;
|
use bevy_ecs::event::Events;
|
||||||
use bevy_log::tracing_subscriber;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_receive_start_config_packet() {
|
fn test_receive_start_config_packet() {
|
||||||
let _ = tracing_subscriber::fmt::try_init();
|
init_tracing();
|
||||||
|
|
||||||
let mut simulation = Simulation::new(ConnectionProtocol::Game);
|
let mut simulation = Simulation::new(ConnectionProtocol::Game);
|
||||||
simulation.receive_packet(make_basic_login_packet(
|
simulation.receive_packet(make_basic_login_packet(
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use azalea_client::{
|
use azalea_client::{
|
||||||
packet::{config::SendConfigPacketEvent, game::SendPacketEvent},
|
packet::{config::SendConfigPacketEvent, game::SendPacketEvent},
|
||||||
test_simulation::*,
|
test_utils::prelude::*,
|
||||||
};
|
};
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_core::resource_location::ResourceLocation;
|
||||||
use azalea_protocol::packets::{
|
use azalea_protocol::packets::{
|
||||||
|
@ -13,13 +13,12 @@ use azalea_protocol::packets::{
|
||||||
game::{self, ServerboundGamePacket},
|
game::{self, ServerboundGamePacket},
|
||||||
};
|
};
|
||||||
use bevy_ecs::observer::Trigger;
|
use bevy_ecs::observer::Trigger;
|
||||||
use bevy_log::tracing_subscriber;
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use simdnbt::owned::{NbtCompound, NbtTag};
|
use simdnbt::owned::{NbtCompound, NbtTag};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reply_to_ping_with_pong() {
|
fn reply_to_ping_with_pong() {
|
||||||
let _ = tracing_subscriber::fmt::try_init();
|
init_tracing();
|
||||||
|
|
||||||
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use azalea_client::{InConfigState, test_simulation::*};
|
use azalea_client::{InConfigState, test_utils::prelude::*};
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_core::resource_location::ResourceLocation;
|
||||||
use azalea_entity::{LocalEntity, metadata::Health};
|
use azalea_entity::{LocalEntity, metadata::Health};
|
||||||
use azalea_protocol::packets::{
|
use azalea_protocol::packets::{
|
||||||
|
@ -7,12 +7,11 @@ use azalea_protocol::packets::{
|
||||||
game::ClientboundSetHealth,
|
game::ClientboundSetHealth,
|
||||||
};
|
};
|
||||||
use azalea_registry::{DataRegistry, DimensionType};
|
use azalea_registry::{DataRegistry, DimensionType};
|
||||||
use bevy_log::tracing_subscriber;
|
|
||||||
use simdnbt::owned::{NbtCompound, NbtTag};
|
use simdnbt::owned::{NbtCompound, NbtTag};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_set_health_before_login() {
|
fn test_set_health_before_login() {
|
||||||
let _ = tracing_subscriber::fmt::try_init();
|
init_tracing();
|
||||||
|
|
||||||
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
||||||
assert!(simulation.has_component::<InConfigState>());
|
assert!(simulation.has_component::<InConfigState>());
|
||||||
|
|
|
@ -28,6 +28,11 @@ pub struct RelativeMovements {
|
||||||
pub delta_z: bool,
|
pub delta_z: bool,
|
||||||
pub rotate_delta: bool,
|
pub rotate_delta: bool,
|
||||||
}
|
}
|
||||||
|
impl RelativeMovements {
|
||||||
|
pub fn all_absolute() -> Self {
|
||||||
|
RelativeMovements::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AzaleaRead for RelativeMovements {
|
impl AzaleaRead for RelativeMovements {
|
||||||
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
|
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue