<table><tr><td style="">mwolff added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D18567">View Revision</a></tr></table><br /><div><div><blockquote style="border-left: 3px solid #8C98B8;
          color: #6B748C;
          font-style: italic;
          margin: 4px 0 12px 0;
          padding: 8px 12px;
          background-color: #F8F9FC;">
<div style="font-style: normal;
          padding-bottom: 4px;">In <a href="https://phabricator.kde.org/D18567#411767" style="background-color: #e7e7e7;
          border-color: #e7e7e7;
          border-radius: 3px;
          padding: 0 4px;
          font-weight: bold;
          color: black;text-decoration: none;">D18567#411767</a>, <a href="https://phabricator.kde.org/p/thomassc/" style="
              border-color: #f1f7ff;
              color: #19558d;
              background-color: #f1f7ff;
                border: 1px solid transparent;
                border-radius: 3px;
                font-weight: bold;
                padding: 0 4px;">@thomassc</a> wrote:</div>
<div style="margin: 0;
          padding: 0;
          border: 0;
          color: rgb(107, 116, 140);"><p>Regarding waiting for the background parser on <tt style="background: #ebebeb; font-size: 13px;">TestFile</tt> destruction, I didn't find a way to query whether a parse job is running or to wait for it, if it was started externally, using existing code (but I'm also not familiar with the codebase). As an alternative, one can do <tt style="background: #ebebeb; font-size: 13px;">Q_ASSERT(ICore::self()->languageController()->backgroundParser()->isIdle());</tt> in the test cleanup function to ensure that the tests don't leave the background parser running. This might also be a good idea to ensure that the tests don't influence each other in that way.</p></div>
</blockquote>

<p>One idea: In <tt style="background: #ebebeb; font-size: 13px;">~TestFile</tt> do these things:</p>

<p>a) close and discard the document, if it's opened currently<br />
b) <tt style="background: #ebebeb; font-size: 13px;">BackgroundParser::removeDocument</tt><br />
c) if <tt style="background: #ebebeb; font-size: 13px;">BackgroundParser::parseJobForDocument</tt> returns non-null, await the <tt style="background: #ebebeb; font-size: 13px;">parseJobFinished</tt> signal for that url with some timeout. You can do that e.g. via:</p>

<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">if (backgroundParser->parseJobForDocument(url))
{
    bool finished = false;
    connect(backgroundParser, &BackgroundParser::parseJobFinished, this, [this, &finished](const IndexedString& finishedUrl) {
        if (finishedUrl == url)
            finished = true;
    };
    QTRY_VERIFY(finished);
}</pre></div>



<blockquote style="border-left: 3px solid #a7b5bf; color: #464c5c; font-style: italic; margin: 4px 0 12px 0; padding: 4px 12px; background-color: #f8f9fc;"><p>Regarding document handling, I'm not sure whether it's worth adding a specific test class for the few cases here. I found that in test_buddies.cpp, the test cleanup function does <tt style="background: #ebebeb; font-size: 13px;">m_documentController->closeAllDocuments();</tt>. I tried this for the duchain test, but this caused a crash when this actually tried to close the open documents, which I wasn't motivated to debug. Alternatively, one can do <tt style="background: #ebebeb; font-size: 13px;">Q_ASSERT(ICore::self()->documentController()->openDocuments().isEmpty());</tt> similarly to the case above to ensure that the tests clean up after themselves. Would you be fine with that?</p></blockquote>

<p>Right, so we could just do that in <tt style="background: #ebebeb; font-size: 13px;">~TestFile</tt> maybe? Anyhow, ignore this for now if it's too much trouble.</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R32 KDevelop</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D18567">https://phabricator.kde.org/D18567</a></div></div><br /><div><strong>To: </strong>thomassc, KDevelop, mwolff<br /><strong>Cc: </strong>mwolff, kdevelop-devel, gennad, glebaccon, antismap, iodelay, alexeymin, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd<br /></div>