Changeset View
Changeset View
Standalone View
Standalone View
autotests/server/dbdeadlockcatchertest.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2019 David Faure <faure@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or modify it | ||||
5 | under the terms of the GNU Library General Public License as published by | ||||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||||
7 | option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||||
12 | License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||||
17 | 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include <QObject> | ||||
21 | #include <QTest> | ||||
22 | #include <QSqlQuery> | ||||
23 | | ||||
24 | #include "storage/dbdeadlockcatcher.h" | ||||
25 | | ||||
26 | #include <aktest.h> | ||||
27 | | ||||
28 | using namespace Akonadi::Server; | ||||
29 | | ||||
30 | class DbDeadlockCatcherTest : public QObject | ||||
31 | { | ||||
32 | Q_OBJECT | ||||
33 | | ||||
34 | private: | ||||
35 | int m_myFuncCalled = 0; | ||||
36 | void myFunc(int maxRecursion) | ||||
37 | { | ||||
38 | ++m_myFuncCalled; | ||||
39 | if (m_myFuncCalled <= maxRecursion) | ||||
40 | throw DbDeadlockException(QSqlQuery()); | ||||
41 | } | ||||
42 | | ||||
43 | private Q_SLOTS: | ||||
44 | void testRecurseOnce() | ||||
45 | { | ||||
46 | m_myFuncCalled = 0; | ||||
47 | DbDeadlockCatcher catcher([this](){ myFunc(1); }); | ||||
48 | QCOMPARE(m_myFuncCalled, 2); | ||||
49 | } | ||||
50 | | ||||
51 | void testRecurseTwice() | ||||
52 | { | ||||
53 | m_myFuncCalled = 0; | ||||
54 | DbDeadlockCatcher catcher([this](){ myFunc(2); }); | ||||
55 | QCOMPARE(m_myFuncCalled, 3); | ||||
56 | } | ||||
57 | | ||||
58 | void testHitRecursionLimit() | ||||
59 | { | ||||
60 | m_myFuncCalled = 0; | ||||
61 | QVERIFY_EXCEPTION_THROWN( | ||||
62 | DbDeadlockCatcher catcher([this](){ myFunc(10); }), | ||||
63 | DbDeadlockException); | ||||
64 | QCOMPARE(m_myFuncCalled, 6); | ||||
65 | } | ||||
66 | }; | ||||
67 | | ||||
68 | AKTEST_MAIN(DbDeadlockCatcherTest) | ||||
69 | | ||||
70 | #include "dbdeadlockcatchertest.moc" |