Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add provider suite test for thread safety of provider getFeatures()
Hammers providers by iterating through features from multiple threads
- Loading branch information
1 parent
c2e0775
commit 741afdc
Showing
8 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgstestutils.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
%ModuleHeaderCode | ||
#include "qgstestutils.h" | ||
%End | ||
|
||
|
||
namespace QgsTestUtils | ||
{ | ||
|
||
bool testProviderIteratorThreadSafety( QgsVectorDataProvider *provider, const QgsFeatureRequest &request = QgsFeatureRequest() ); | ||
%Docstring | ||
Runs a thready safety test on iterators from a vector data ``provider``, by concurrently | ||
requesting features from the provider. | ||
|
||
This method returns true... or it segfaults. | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgstestutils.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/*************************************************************************** | ||
qgstestutils.cpp | ||
-------------------- | ||
begin : January 2018 | ||
copyright : (C) 2018 by Nyall Dawson | ||
email : nyall.dawson@gmail.com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgstestutils.h" | ||
#include "qgsvectordataprovider.h" | ||
#include "qgsconnectionpool.h" | ||
#include <QtConcurrentMap> | ||
///@cond PRIVATE | ||
/// | ||
|
||
static void getFeaturesForProvider( QPair< QgsVectorDataProvider *, QgsFeatureRequest > pair ) | ||
{ | ||
QgsFeatureIterator it = pair.first->getFeatures( pair.second ); | ||
QgsFeature f; | ||
while ( it.nextFeature( f ) ) | ||
{ | ||
|
||
} | ||
} | ||
|
||
bool QgsTestUtils::testProviderIteratorThreadSafety( QgsVectorDataProvider *provider, const QgsFeatureRequest &request ) | ||
{ | ||
constexpr int JOBS_TO_RUN = 100; | ||
QList< QPair< QgsVectorDataProvider *, QgsFeatureRequest > > jobs; | ||
jobs.reserve( JOBS_TO_RUN ); | ||
for ( int i = 0; i < JOBS_TO_RUN; ++i ) | ||
{ | ||
jobs.append( qMakePair( provider, request ) ); | ||
} | ||
|
||
//freaking hammmer the provider with a ton of concurrent requests. | ||
//thread unsafe providers... you better be ready!!!! | ||
QtConcurrent::blockingMap( jobs, getFeaturesForProvider ); | ||
|
||
return true; | ||
} | ||
|
||
|
||
///@endcond |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*************************************************************************** | ||
qgstestutils.h | ||
--------------------- | ||
begin : January 2018 | ||
copyright : (C) 2018 by Nyall Dawson | ||
email : nyall.dawson@gmail.com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSTESTUTILS_H | ||
#define QGSTESTUTILS_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgis.h" | ||
#include "qgsfeaturerequest.h" | ||
|
||
class QgsVectorDataProvider; | ||
|
||
#ifdef SIP_RUN | ||
% ModuleHeaderCode | ||
#include "qgstestutils.h" | ||
% End | ||
#endif | ||
|
||
///@cond PRIVATE | ||
|
||
// Used only for utilities required for the QGIS Python unit tests - not stable or public API | ||
namespace QgsTestUtils | ||
{ | ||
|
||
/** | ||
* Runs a thready safety test on iterators from a vector data \a provider, by concurrently | ||
* requesting features from the provider. | ||
* | ||
* This method returns true... or it segfaults. | ||
*/ | ||
CORE_EXPORT bool testProviderIteratorThreadSafety( QgsVectorDataProvider *provider, const QgsFeatureRequest &request = QgsFeatureRequest() ); | ||
|
||
}; | ||
|
||
///@endcond | ||
#endif //QGSTESTUTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.