Commit eccac77e authored by Nikita Sirgienko's avatar Nikita Sirgienko

[Julia] Add support of expression queue and tests for this feature

parent 8abe3104
......@@ -38,7 +38,7 @@ void JuliaExpression::evaluate()
setStatus(Cantor::Expression::Computing);
auto juliaSession = static_cast<JuliaSession *>(session());
juliaSession->runExpression(this);
juliaSession->enqueueExpression(this);
}
QString JuliaExpression::internalCommand()
......
......@@ -43,7 +43,6 @@ JuliaSession::JuliaSession(Cantor::Backend *backend)
: Session(backend)
, m_process(nullptr)
, m_interface(nullptr)
, m_currentExpression(nullptr)
, m_variableModel(new JuliaVariableModel(this))
, m_needUpdate(false)
{
......@@ -129,15 +128,18 @@ void JuliaSession::logout()
void JuliaSession::interrupt()
{
if (expressionQueue().isEmpty())
return;
if (m_process->pid()) {
m_process->kill();
}
for (Cantor::Expression *e : m_runningExpressions) {
e->interrupt();
}
qDebug()<<"interrupting " << expressionQueue().first()->command();
foreach (Cantor::Expression* expression, expressionQueue())
expression->setStatus(Cantor::Expression::Interrupted);
expressionQueue().clear();
m_runningExpressions.clear();
changeStatus(Cantor::Session::Done);
}
......@@ -148,8 +150,6 @@ Cantor::Expression *JuliaSession::evaluateExpression(
{
JuliaExpression *expr = new JuliaExpression(this, internal);
changeStatus(Cantor::Session::Running);
expr->setFinishingBehavior(behave);
expr->setCommand(cmd);
expr->evaluate();
......@@ -186,23 +186,28 @@ void JuliaSession::runJuliaCommandAsync(const QString &command)
void JuliaSession::onResultReady()
{
m_currentExpression->finalize();
m_needUpdate |= !m_currentExpression->isInternal();
m_runningExpressions.removeAll(m_currentExpression);
JuliaExpression* expr = static_cast<JuliaExpression*>(expressionQueue().takeFirst());
expr->finalize();
m_needUpdate |= !expr->isInternal();
if(m_needUpdate)
if (expressionQueue().isEmpty())
{
m_variableModel->update();
m_needUpdate = false;
if(m_needUpdate)
{
m_variableModel->update();
m_needUpdate = false;
}
changeStatus(Cantor::Session::Done);
}
changeStatus(Cantor::Session::Done);
else
runFirstExpression();
}
void JuliaSession::runExpression(JuliaExpression *expr)
void JuliaSession::runFirstExpression()
{
m_runningExpressions.append(expr);
m_currentExpression = expr;
Cantor::Expression* expr = expressionQueue().first();
expr->setStatus(Cantor::Expression::Computing);
runJuliaCommandAsync(expr->internalCommand());
}
......
......@@ -104,10 +104,6 @@ private:
KProcess *m_process; //< process to run JuliaServer inside
QDBusInterface *m_interface; //< interface to JuliaServer
/// Expressions running at the moment
QList<JuliaExpression *> m_runningExpressions;
JuliaExpression *m_currentExpression; //< current expression
/// Variable management model
JuliaVariableModel *m_variableModel;
bool m_needUpdate;
......@@ -118,12 +114,7 @@ private:
friend JuliaExpression;
friend JuliaCompletionObject;
/**
* Runs Julia expression
*
* @param expression expression to run
*/
void runExpression(JuliaExpression *expression);
void runFirstExpression() override;
/**
* Runs Julia piece of code in synchronous mode
......
......@@ -286,5 +286,25 @@ void TestJulia::testComplexAutocompletion()
}
}
void TestJulia::testExpressionQueue()
{
Cantor::Expression* e1=session()->evaluateExpression(QLatin1String("0+1"));
Cantor::Expression* e2=session()->evaluateExpression(QLatin1String("1+1"));
QVERIFY(session()->status() == Cantor::Session::Running);
Cantor::Expression* e3=evalExp(QLatin1String("1+2"));
QVERIFY(e1!=nullptr);
QVERIFY(e2!=nullptr);
QVERIFY(e3!=nullptr);
QVERIFY(e1->result());
QVERIFY(e2->result());
QVERIFY(e3->result());
QCOMPARE(cleanOutput(e1->result()->toHtml()), QLatin1String("1"));
QCOMPARE(cleanOutput(e2->result()->toHtml()), QLatin1String("2"));
QCOMPARE(cleanOutput(e3->result()->toHtml()), QLatin1String("3"));
}
QTEST_MAIN(TestJulia)
......@@ -80,6 +80,8 @@ private Q_SLOTS:
void testAutoCompletion();
void testComplexAutocompletion();
void testExpressionQueue();
private:
QString backendName() override;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment