Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Test: how to change the timeout and also disable timeout



  • Hiya,

    Using Qt Test for first time. I have the testing framework working well with my tests. However, some of the tests require long running time. They get canceled by Qt Test due to timeout. How can I change the timeout to a very long time since I don't really know how long it will take to run.

    I'm running perft tests to enumerate possible moves from a game position to large depths of up to 23 - 30, the number of nodes can get quite large and time consuming to calculate. So far, I get timeouts at depth of 5 and this is just not going to work unless I can change the timeout or even disable.

    Is it possible to disable the timeout and allow manual cancellation? In some cases, I'd want to let the calculations to run over night.

    Thanks



  • Well, I'm a dufus, there is a way to change it in Qt Creater:

    qt-test-timeout.png

    However, the maximum allowed value is 9999 seconds. Which is about 2.7 hours. I might need a bit longer, I'll let you know. Would be nice to change it to a very long time without having to go through coding gymnastics.

    How much do you know about the Qt test framework, I'm wondering if I can use the initTestCase() function, if this function is outside the timeout checks? If yes, I suppose I could use it to do the long calc stuff and then just check the returned values in the testcases but it seems to kind of defeat the purpose of the framework.


  • Lifetime Qt Champion

    Hi,

    Maybe qWaitFor is what you need.

    Hope it helps



  • I'm not exactly sure how to use this function. How would you modify this test case to use qWaitFor?

    void ChessValidator::perft_startposition()
        {
        QFETCH(QString, fen);
        QFETCH(int, depth);
        QFETCH(qint64, nodes);
        Chess chess;
        qint64 calculated_nodes = chess.Perft(depth);
        QCOMPARE(calculated_nodes, nodes);
        }
    

    I just don't understand how qWaitFor will know when Perft() is done calculating.


  • Lifetime Qt Champion

    Indeed it won't with that design.

    One alternative could be to use QtConcurrent::run to execute that method and the returned QFuture with qWaitFor.



  • Well, I'm a dufus, there is a way to change it in Qt Creater:

    qt-test-timeout.png

    However, the maximum allowed value is 9999 seconds. Which is about 2.7 hours. I might need a bit longer, I'll let you know. Would be nice to change it to a very long time without having to go through coding gymnastics.

    How much do you know about the Qt test framework, I'm wondering if I can use the initTestCase() function, if this function is outside the timeout checks? If yes, I suppose I could use it to do the long calc stuff and then just check the returned values in the testcases but it seems to kind of defeat the purpose of the framework.



  • @SGaist

    Regarding using QtConcurrent::run and QFuture, I'm doubtful it would work because if I read the docs right about Qt Test, the timeout is checking the execution of the testcase, in my case, ChessValidator::perft_startposition(). So even if I spin off a concurrent process and wait for it to return, wouldn't the test case still fail at the timeout period?


Log in to reply