D20264: Add test for "Auto Reload Document" option

loh tar noreply at phabricator.kde.org
Sun Apr 21 10:18:37 BST 2019


loh.tar added a comment.


  @dhaumann asked elsewhere
  
  > Instead of waiting so long, we could alternatively also have a while loop waiting up to 20 times for 50ms. This way, the test would be faster if possible.
  
  Like this?
  
    diff --git a/autotests/src/katedocument_test.cpp b/autotests/src/katedocument_test.cpp
    index 4be9d7c3..e24a8ad9 100644
    --- a/autotests/src/katedocument_test.cpp
    +++ b/autotests/src/katedocument_test.cpp
    @@ -655,14 +655,23 @@ void KateDocumentTest::testAutoReload()
        // without to wait before it doesn't work here. It mostly fails with 500,
        // it tend to work with 600, but is not guarantied to work even with 800
        QTest::qWait(1000);
    +    // No idea how to do some slice test here
    
        stream << "\nTest";
        stream.flush();
    
    -     // Hardcoded delay m_modOnHdTimer in DocumentPrivate
    +    // Try not to waste more time than needed, but we need to wait
    +    const int timeSlice = 50;
    +    // Hardcoded delay m_modOnHdTimer in DocumentPrivate
        // + min val with which it looks working reliable here
    -    QTest::qWait(200 + 800);
    -    QCOMPARE(doc.text(), "Hello\nTest");
    +    const int totalPatience = 200 + 800;
    +
    +    QString refTxT = ("Hello\nTest");
    +    for (int w = 0; w <= totalPatience; w += timeSlice) {
    +        QTest::qWait(timeSlice);
    +        if (doc.text() == refTxT) break;
    +    }
    +    QCOMPARE(doc.text(), refTxT);
        // ...stay in the last line after reload!
        QCOMPARE(view->cursorPosition().line(), doc.documentEnd().line());
    
    @@ -674,8 +683,12 @@ void KateDocumentTest::testAutoReload()
        stream.flush();
        file.close();
    
    -    QTest::qWait(200 + 800);
    -    QCOMPARE(doc.text(), "Hello\nTest\nWorld!");
    +    refTxT = ("Hello\nTest\nWorld!");
    +    for (int w = 0; w <= totalPatience; w += timeSlice) {
    +        QTest::qWait(timeSlice);
    +        if (doc.text() == refTxT) break;
    +    }
    +    QCOMPARE(doc.text(), refTxT);
        // ...and ensure we have not move around
        QCOMPARE(view->cursorPosition(), c);
    }
  
  No Patch
  
    Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 3152ms
  
  With Patch
  
    Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 2619ms
    533ms saved
  
  But it can still fail now :-(
  
    Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 3127ms
  
  also with increased waiting times
  
    Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 3787ms
    Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 4802ms
  
  Does maybe the check "if (doc.text() == " disturbs the nice waiting?
  Playing with longer slice shows an effect around a 500ms slice, but then we have no benefit
  
    Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 3147ms

REPOSITORY
  R39 KTextEditor

REVISION DETAIL
  https://phabricator.kde.org/D20264

To: loh.tar, dhaumann, cullmann
Cc: cullmann, kwrite-devel, kde-frameworks-devel, #ktexteditor, domson, michaelh, ngraham, bruns, demsking, sars, dhaumann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kwrite-devel/attachments/20190421/6f98bf4f/attachment-0001.html>


More information about the KWrite-Devel mailing list