QTestLib: Disable App Nap on macOS
App Nap may cause stalls or timer delays during test runs. Change-Id: I828282d12127918439a9a2a4f7d7be6cac457b42 Task-number: QTBUG-61499 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
8b8578a155
commit
1497e5853b
@ -1728,6 +1728,9 @@ void QTest::qInit(QObject *testObject, int argc, char **argv)
|
|||||||
|
|
||||||
// Don't restore saved window state for auto tests.
|
// Don't restore saved window state for auto tests.
|
||||||
QTestPrivate::disableWindowRestore();
|
QTestPrivate::disableWindowRestore();
|
||||||
|
|
||||||
|
// Disable App Nap which may cause tests to stall.
|
||||||
|
QTestPrivate::AppNapDisabler appNapDisabler;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(Q_OS_MACX)
|
#if defined(Q_OS_MACX)
|
||||||
|
@ -54,6 +54,33 @@ namespace QTestPrivate {
|
|||||||
void disableWindowRestore() {
|
void disableWindowRestore() {
|
||||||
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"ApplePersistenceIgnoreState"];
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"ApplePersistenceIgnoreState"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! \internal
|
||||||
|
\class AppNapDisabler
|
||||||
|
\brief Disables App Nap by registereing a bacground activity.
|
||||||
|
|
||||||
|
App Nap remains disabled as long as the AppNapDisabler instance
|
||||||
|
exists.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! \internal
|
||||||
|
Creates an AppNapDisabler instance and starts a NSActivityBackground activity.
|
||||||
|
*/
|
||||||
|
AppNapDisabler::AppNapDisabler()
|
||||||
|
{
|
||||||
|
m_activity = [[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityBackground
|
||||||
|
reason:@"Qt Auto Test"];
|
||||||
|
[m_activity retain];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \internal
|
||||||
|
Destroys the AppNapDisabler instance and ends the NSActivityBackground activity.
|
||||||
|
*/
|
||||||
|
AppNapDisabler::~AppNapDisabler()
|
||||||
|
{
|
||||||
|
[[NSProcessInfo processInfo] endActivity:m_activity];
|
||||||
|
[m_activity release];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -58,6 +58,17 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
namespace QTestPrivate {
|
namespace QTestPrivate {
|
||||||
void disableWindowRestore();
|
void disableWindowRestore();
|
||||||
|
|
||||||
|
class AppNapDisabler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AppNapDisabler();
|
||||||
|
~AppNapDisabler();
|
||||||
|
AppNapDisabler(const AppNapDisabler&) = delete;
|
||||||
|
AppNapDisabler& operator=(const AppNapDisabler&) = delete;
|
||||||
|
private:
|
||||||
|
id m_activity;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user