-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor tests Current integration tests categorization doesn't scale well for the amount of tests cases we have. I made the following changes to address it: 1. Split `init_replication` test into `removals`, `insertion`, `spawn` and `despawn`. 2. Split insertion and removal test with multiple components into separate tests. 3. Thanks to code coverage I found a missing test case for spawning an entity from a mapped component, added.
- Loading branch information
Showing
6 changed files
with
950 additions
and
654 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
use bevy::prelude::*; | ||
use bevy_replicon::{ | ||
client::client_mapper::ServerEntityMap, prelude::*, test_app::ServerTestAppExt, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[test] | ||
fn single() { | ||
let mut server_app = App::new(); | ||
let mut client_app = App::new(); | ||
for app in [&mut server_app, &mut client_app] { | ||
app.add_plugins(( | ||
MinimalPlugins, | ||
RepliconPlugins.set(ServerPlugin { | ||
tick_policy: TickPolicy::EveryFrame, | ||
..Default::default() | ||
}), | ||
)); | ||
} | ||
|
||
server_app.connect_client(&mut client_app); | ||
|
||
let server_entity = server_app.world.spawn(Replication).id(); | ||
let client_entity = client_app.world.spawn(Replication).id(); | ||
|
||
client_app | ||
.world | ||
.resource_mut::<ServerEntityMap>() | ||
.insert(server_entity, client_entity); | ||
|
||
server_app.world.despawn(server_entity); | ||
|
||
server_app.update(); | ||
server_app.exchange_with_client(&mut client_app); | ||
client_app.update(); | ||
|
||
assert!(client_app.world.entities().is_empty()); | ||
|
||
let entity_map = client_app.world.resource::<ServerEntityMap>(); | ||
assert!(entity_map.to_client().is_empty()); | ||
assert!(entity_map.to_server().is_empty()); | ||
} | ||
|
||
#[test] | ||
fn with_heirarchy() { | ||
let mut server_app = App::new(); | ||
let mut client_app = App::new(); | ||
for app in [&mut server_app, &mut client_app] { | ||
app.add_plugins(( | ||
MinimalPlugins, | ||
RepliconPlugins.set(ServerPlugin { | ||
tick_policy: TickPolicy::EveryFrame, | ||
..Default::default() | ||
}), | ||
)); | ||
} | ||
|
||
server_app.connect_client(&mut client_app); | ||
|
||
let server_child_entity = server_app.world.spawn(Replication).id(); | ||
let server_entity = server_app | ||
.world | ||
.spawn(Replication) | ||
.push_children(&[server_child_entity]) | ||
.id(); | ||
|
||
let client_child_entity = client_app.world.spawn(Replication).id(); | ||
let client_entity = client_app | ||
.world | ||
.spawn(Replication) | ||
.push_children(&[client_child_entity]) | ||
.id(); | ||
|
||
let mut entity_map = client_app.world.resource_mut::<ServerEntityMap>(); | ||
entity_map.insert(server_entity, client_entity); | ||
entity_map.insert(server_child_entity, client_child_entity); | ||
|
||
server_app.world.despawn(server_entity); | ||
server_app.world.despawn(server_child_entity); | ||
|
||
server_app.update(); | ||
server_app.exchange_with_client(&mut client_app); | ||
client_app.update(); | ||
|
||
server_app.world.despawn(server_entity); | ||
server_app.world.despawn(server_child_entity); | ||
|
||
assert!(client_app.world.entities().is_empty()); | ||
} | ||
|
||
#[test] | ||
fn after_spawn() { | ||
let mut server_app = App::new(); | ||
let mut client_app = App::new(); | ||
for app in [&mut server_app, &mut client_app] { | ||
app.add_plugins(( | ||
MinimalPlugins, | ||
RepliconPlugins.set(ServerPlugin { | ||
tick_policy: TickPolicy::EveryFrame, | ||
..Default::default() | ||
}), | ||
)) | ||
.replicate::<DummyComponent>(); | ||
} | ||
|
||
server_app.connect_client(&mut client_app); | ||
|
||
// Insert and remove `Replication` to trigger spawn and despawn for client at the same time. | ||
server_app | ||
.world | ||
.spawn((Replication, DummyComponent)) | ||
.remove::<Replication>(); | ||
|
||
server_app.update(); | ||
server_app.exchange_with_client(&mut client_app); | ||
client_app.update(); | ||
|
||
assert!(client_app.world.entities().is_empty()); | ||
} | ||
|
||
#[derive(Component, Deserialize, Serialize)] | ||
struct DummyComponent; |
Oops, something went wrong.