test/source/a11y/accessibletestbase.cxx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
New commits: commit ab0681dadc15b569027c5ce637441ea95eae1631 Author: Colomban Wendling <cwendl...@hypra.fr> AuthorDate: Tue Jan 24 18:07:52 2023 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Fri Mar 3 09:58:06 2023 +0000 test: Fail earlier if we don't get WindowActivate events Instead of waiting for the CI itself to timeout after 45 minutes, or for an interactive caller to kill us sometime, don't wait more than 60 seconds for a WindowActivate event to show up. This should not happen in the working code paths, but can help when something's going wrong. Currently, this could help macos jobs to fail sooner. Change-Id: Iabce82b31440c14fd16478f1e574ce376027441c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146099 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/test/source/a11y/accessibletestbase.cxx b/test/source/a11y/accessibletestbase.cxx index 47a77e864932..857df519f136 100644 --- a/test/source/a11y/accessibletestbase.cxx +++ b/test/source/a11y/accessibletestbase.cxx @@ -283,12 +283,14 @@ test::AccessibleTestBase::awaitDialog(const std::u16string_view name, std::u16string_view msName; std::function<void(Dialog&)> mCallback; bool mbAutoClose; + Timer maTimeoutTimer; public: virtual ~ListenerHelper() { Application::SetDialogCancelMode(miPreviousDialogCancelMode); Application::RemoveEventListener(mLink); + maTimeoutTimer.Stop(); } ListenerHelper(const std::u16string_view& name, std::function<void(Dialog&)> callback, @@ -297,15 +299,38 @@ test::AccessibleTestBase::awaitDialog(const std::u16string_view name, , msName(name) , mCallback(callback) , mbAutoClose(bAutoClose) + , maTimeoutTimer("workaround timer if we don't catch WindowActivate") { mLink = LINK(this, ListenerHelper, eventListener); Application::AddEventListener(mLink); + maTimeoutTimer.SetInvokeHandler(LINK(this, ListenerHelper, timeoutTimerHandler)); + maTimeoutTimer.SetTimeout(60000); + maTimeoutTimer.Start(); + miPreviousDialogCancelMode = Application::GetDialogCancelMode(); Application::SetDialogCancelMode(DialogCancelMode::Off); } private: + // mimic IMPL_LINK inline + static void LinkStubtimeoutTimerHandler(void* instance, Timer* timer) + { + static_cast<ListenerHelper*>(instance)->timeoutTimerHandler(timer); + } + + void timeoutTimerHandler(Timer*) + { + std::cerr << "timeout waiting for dialog '" << OUString(msName) << "' to show up" + << std::endl; + + assert(mbWaitingForDialog); + + // This is not very nice, but it should help fail earlier if we never catch the dialog + // yet we're in a sub-loop and waitEndDialog() didn't have a chance to run yet. + throw new css::uno::RuntimeException("Timeout waiting for dialog"); + } + // mimic IMPL_LINK inline static void LinkStubeventListener(void* instance, VclSimpleEvent& event) { @@ -328,6 +353,8 @@ test::AccessibleTestBase::awaitDialog(const std::u16string_view name, // remove ourselves, we don't want to run again Application::RemoveEventListener(mLink); + maTimeoutTimer.ClearInvokeHandler(); + maTimeoutTimer.Stop(); /* bind the dialog before checking its name so auto-close can kick in if anything * fails/throws */