godot
godot copied to clipboard
Add timer tests
Add timer tests link to #43440
The Timer start/stop test case is currently failing because it is not part of a scene tree, is there a test scene tree that i need to add it to, or should i make a scene tree in cpp and add it to it?
Thanks for your PR, CI failed, use the clang-format tool to prevent such errors (just an advice) (see https://docs.godotengine.org/en/latest/contributing/development/code_style_guidelines.html#using-clang-format-locally). Also, commits need to be squashed (see https://docs.godotengine.org/en/latest/contributing/workflow/pr_workflow.html#modifying-a-pull-request).
Thanks for your PR, CI failed, use the clang-format tool to prevent such errors (just an advice) (see https://docs.godotengine.org/en/latest/contributing/development/code_style_guidelines.html#using-clang-format-locally). Also, commits need to be squashed (see https://docs.godotengine.org/en/latest/contributing/workflow/pr_workflow.html#modifying-a-pull-request).
@Chaosus ive managed to fix the clangfmt issue and squashed the commits, the only thing that remains is to fix the start/stop tests requiring a scene tree
You might want to test the main functionality of timer: the timeout signal. But do so with a short wait time, so it does not take long for the test to complete:
- Measure current time using Time singleton.
- Start a one-shot timer with wait time 0.1 seconds.
- On timeout, measure time again using Time singleton.
- Ensure the difference between timestamps is at least 0.1 seconds (might be longer, but never shorter).
Could also check e.g. if timer is no longer running after timeout (or if it's not a one-shot timer, ensure that it is still running).
You might want to test the main functionality of timer: the timeout signal. But do so with a short wait time, so it does not take long for the test to complete:
* Measure current time using Time singleton. * Start a one-shot timer with wait time 0.1 seconds. * On timeout, measure time again using Time singleton. * Ensure the difference between timestamps is at least 0.1 seconds (might be longer, but never shorter).Could also check e.g. if timer is no longer running after timeout (or if it's not a one-shot timer, ensure that it is still running).
to update the timer, do i also have to manually process the scene tree like so?
SceneTree::get_singleton()->process(0.1); SceneTree::get_singleton()->physics_process(0.1);
to update the timer, do i also have to manually process the scene tree like so?
I do see calls to that function in the Node tests, so yeah I think so. Also you might want to test process and physics_process separately, depending on which process callback the Timer is set to (so only tick one of the two, not both at once).
@RedMser I tried getting the timeout signal to be called by manually calling process on the scene tree, but the callback doesnt seem to be getting called. Do you know why that might be?
@RedMser ive rebased this with latest from master, could you have a look at this PR once again.
Thanks! And congrats for your first merged Godot contribution :tada: