-
Hello, I am currently unit testing an application developed with:
I have noticed one of my test is flakky. After some investigation, it seems my startup systems are not always run before the start of the main schedule. #[test]
fn test_nominal_tc_execution() {
let mut app = App::new();
app.add_plugins(MinimalPlugins)
.add_startup_system(initialize_cmd_register)
// Standard system
.add_system(new_cycle.in_base_set(CoreSet::First))
.add_system(execute_command);
/* Generate test data */
/* Run one cycle */
app.update();
/* Check test results */
Are there any specific steps I need to take to guarantee system schedule rodering in a unit testing context? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Startup systems should always be executed first, and commands should be applied after startup systems. Can you open an issue with a failing unit test written on main? Does this always happen, or is it nondeterministic? |
Beta Was this translation helpful? Give feedback.
-
This is undeterministic. For more context,
If I stop registering #[test]
fn test_nominal_tc_execution() {
let mut app = App::new();
app.add_plugins(MinimalPlugins)
// Commented !
//.add_startup_system(initialize_cmd_register)
// Standard system
.add_system(new_cycle.in_base_set(CoreSet::First))
.add_system(execute_command);
// Run "sysuem" manually
initialize_cmd_register(&mut app.world)
/* Generate test data */
/* Run one cycle */
app.update(); I will try to produce an minimal test case this evening. |
Beta Was this translation helpful? Give feedback.
-
I found the issue, this is not a Bevy bug. In my production unit test, I failed to add the proper dependencies between my startup systems so their execution order was nondeterministic. Using the above example to illustrate the issue, sometimes This does not happen in production and in the example because I added Sorry for the noise |
Beta Was this translation helpful? Give feedback.
I found the issue, this is not a Bevy bug.
In my production unit test, I failed to add the proper dependencies between my startup systems so their execution order was nondeterministic. Using the above example to illustrate the issue, sometimes
fwk::initialize_registry_systems
would run beforecmd::register_systems
. So, the former would try to initialize all systems in the register, but it does not contain any yet...This does not happen in production and in the example because I added
initialize_cmd_system_register
to theStartupSet::PostStartup
set. When writing the unit test, I forgot to do it.Sorry for the noise