Skip to content
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

Wait for JS thread to shutdown with graceful timeout #788

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions tests/trikPyRunnerTests/trikPyRunnerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ int TrikPyRunnerTest::run(const QString &script)
if (!e.isEmpty()) {
rc = EXIT_SCRIPT_ERROR;
std::cerr << qPrintable(e) << std::endl;
}
}
QCoreApplication::processEvents(); // for stdout messages
l.exit(rc);
}, Qt::QueuedConnection ) ; // prevent `exit` before `exec` via QueuedConnection
mStdOut.clear();
Expand All @@ -74,7 +75,8 @@ int TrikPyRunnerTest::runDirectCommandAndWaitForQuit(const QString &script)
{
QEventLoop l;
QObject::connect(&*mScriptRunner, &trikScriptRunner::TrikScriptRunnerInterface::completed
, &l, [&l](const QString &e) {
, &l, [&l](const QString &e) {
QCoreApplication::processEvents(); // dispatch events for print/stdout
l.exit(e.isEmpty() ? EXIT_SCRIPT_SUCCESS
: (qDebug() << e, EXIT_SCRIPT_ERROR));
}, Qt::QueuedConnection ) ; // prevent `exit` before `exec` via QueuedConnection
Expand Down Expand Up @@ -160,7 +162,7 @@ TEST_F(TrikPyRunnerTest, scriptWait)
ASSERT_EQ(err, EXIT_SCRIPT_SUCCESS);
err = runDirectCommandAndWaitForQuit("print('Elapsed %d ms with expected %d ms' % (elapsed, timeout));");
ASSERT_EQ(err, EXIT_SCRIPT_SUCCESS);
err = runDirectCommandAndWaitForQuit("pass #assert(abs(elapsed-timeout) < 5)");
err = runDirectCommandAndWaitForQuit("assert(abs(elapsed-timeout) < 5)");
ASSERT_EQ(err, EXIT_SCRIPT_SUCCESS);
}

Expand Down
7 changes: 7 additions & 0 deletions trikScriptRunner/src/trikScriptRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,18 @@ void TrikScriptRunner::run(const QString &script, ScriptType stype, const QStrin
abortAll(); // FIXME: or fetchRunner(stype)->abort()? or abort(/*last*/)?

fetchRunner(stype)->run(script, fileName);

for(QEventLoop l; l.processEvents(); ) {
// Enforce events dispatch before return, f.e. handling of stdout messages
}
}

void TrikScriptRunner::runDirectCommand(const QString &command)
{
fetchRunner(mLastRunner)->runDirectCommand(command);
for(QEventLoop l; l.processEvents();) {
// Enforce events dispatch before return, f.e. handling of stdout messages
}
}

void TrikScriptRunner::abort()
Expand Down
Loading