Skip to content

Tests: Add additional test coverage for LimboHSM::active_state_changed - #470

Merged
limbonaut merged 11 commits into
limbonaut:masterfrom
bennbollay:normalize-active-state-changed
Aug 28, 2026
Merged

limbonaut merged 11 commits into
limbonaut:masterfrom
bennbollay:normalize-active-state-changed

Conversation

@bennbollay

@bennbollay bennbollay commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Docs: Note LimboHSM.EVENT_FINISHED as a way of marking a tree inactive

@bennbollay bennbollay changed the title Normalize LimboHSM active_state_changed emit Only update LimboHSM::active_state through change_active_state Aug 25, 2026

@adamscott adamscott left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My PR seems to go a little bit further than yours in terms of the changing active state logic. If you want to merge mine with yours, be sure to add all the behaviors I added in #469.

Comment thread hsm/limbo_hsm.cpp Outdated
Comment on lines 34 to 44
active = p_active;
is_initiating_update = p_active;
if (p_active) {
active = p_active;
is_initiating_update = p_active;

if (active) {
_enter();
} else {
_exit();

active = p_active;
is_initiating_update = p_active;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've got duplicated code in the two branches.

Also, LimboState::_enter() sets active to true, same but false for LimboState::_exit(), so no need to set manually active = p_active afterwards.

Comment thread hsm/limbo_hsm.cpp
Comment on lines 47 to 67
void LimboHSM::change_active_state(LimboState *p_state) {
ERR_FAIL_NULL(p_state);
ERR_FAIL_COND_MSG(!is_active(), "LimboHSM: Unable to change active state when HSM is not active.");
ERR_FAIL_COND_MSG(p_state->get_parent() != this, "LimboHSM: Unable to perform transition to a state that is not a child of this HSM.");
ERR_FAIL_COND_MSG(p_state && p_state->get_parent() != this, "LimboHSM: Unable to perform transition to a state that is not a child of this HSM.");

if (active_state) {
active_state->_exit();
previous_active = active_state;
}

previous_active = active_state;
active_state = p_state;
active_state->_enter();

if (active_state) {
active_state->_enter();
}

emit_signal(LW_NAME(active_state_changed), active_state, previous_active);

active_state->_clear_cargo();
if (active_state) {
active_state->_clear_cargo();
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would take the helper class I created in #169 instead. It's necessary to be able to call _change_active_state(nullptr) in case of changes in set_active().

Using an helper class was suggested to me by @limbonaut.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ActiveStateUpdatedReturnedValues could be used in lieu of using SIGNAL_WATCH but SIGNAL_WATCH is part of the standard test tooling offered in the engine. It was a new discovery for both @limbonaut and myself fairly recently!

@limbonaut limbonaut left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting, @bennbollay! Since we almost got #469 to the finish line, let’s go with that one. And then we can consider testing improvements too, if you’d like to contribute those.

@bennbollay

bennbollay commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@adamscott Are there additional behavioral changes that are expected that aren't covered by the test cases implemented?

@bennbollay

Copy link
Copy Markdown
Contributor Author

Added additional tests and support for change_active_state(nullptr) as an optional way to mark inactive a LimboHSM. If that's not desired to support, then it's a one-line change to add the ERR_FAIL_COND back in.

@bennbollay bennbollay changed the title Only update LimboHSM::active_state through change_active_state Support LimbhoHSM::change_active_state(nullptr) to set inactive Aug 26, 2026
@bennbollay

Copy link
Copy Markdown
Contributor Author

Alright merged; most everything here now is just test changes, with one behavior change around supporting change_active_state.

If that's not desired, it can easily be reverted back to the current behavior where that is forbidden.

@limbonaut limbonaut left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff! Thanks for submitting this and improving the test coverage. It still needs a bit of work before I can merge it.

If that's not desired, it can easily be reverted back to the current behavior where that is forbidden.

The main concern is that I don't think changing the state to null should be permitted as that would violate our invariant (see code comments).

Comment thread hsm/limbo_hsm.cpp Resolved
Comment thread tests/test_hsm.h Resolved
Comment thread tests/test_hsm.h Resolved
Comment thread tests/test_hsm.h Resolved
@bennbollay bennbollay changed the title Support LimbhoHSM::change_active_state(nullptr) to set inactive Tests: Add additional test coverage for LimboHSM::active_state_changed Aug 27, 2026
@bennbollay

Copy link
Copy Markdown
Contributor Author

Good review, thank you! Changes applied and PR title updated.

@limbonaut limbonaut left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@limbonaut
limbonaut merged commit eb5645f into limbonaut:master Aug 28, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants