-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Timer unit tests #91395
Add Timer unit tests #91395
Conversation
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). |
7005b9e
to
eb1c97f
Compare
@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 |
85d473c
to
dc5a390
Compare
tests/scene/test_timer.h
Outdated
Timer *test_timer = memnew(Timer); | ||
|
||
SUBCASE("[Timer] Timer start and stop") { | ||
// @TODO: how do i add the timer to a tree? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen the Node tests do it like this:
SceneTree::get_singleton()->get_root()->add_child(node);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thank you.
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:
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); |
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never wrote proper unit tests for Godot before, so I'm trying to figure it out based on looking at other tests haha. Maybe someone with more of an idea can help you out, e.g. in the godot developers chat...
d959323
to
298538f
Compare
298538f
to
40f8180
Compare
40f8180
to
7a6f845
Compare
@RedMser ive rebased this with latest from master, could you have a look at this PR once again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine, but you should wait for a maintainer to approve the workflow run, so you can see if the tests succeed in the CI/CD as well. Maybe you can ask in the Godot Contributors chat, if you don't want to wait.
Thanks! And congrats for your first merged Godot contribution 🎉 |
Add timer tests
link to #43440