diff options
author | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-08-04 15:11:42 +0200 |
---|---|---|
committer | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-08-28 17:53:29 +0200 |
commit | 5c5c9dd830ecaa5dc1be80ef8199d7077096b61e (patch) | |
tree | 129553de73b2477c131d6eb8dd771c2f1c5cf282 /tests/auto/corelib/io/qsettings/tst_qsettings.cpp | |
parent | 39a5ed4bdd348d3cd18a08d322b48d85e8d116e8 (diff) |
Main thread-proxy localStorage oprations in native WASM QSettings
localStorage is unavailable on workers. Operations will now get proxied
to the main thread instead.
This - among other benefits - makes tst_QSettings::testThreadSafety
pass.
Task-number: QTBUG-115509
Change-Id: Iebbe5e9f9069948f8728e0a82628cc082b30de12
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'tests/auto/corelib/io/qsettings/tst_qsettings.cpp')
-rw-r--r-- | tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 0661ac17ca..74784fb3c2 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -10,6 +10,7 @@ #include <QtCore/QCoreApplication> #include <QtCore/QDir> +#include <QtCore/QEventLoop> #include <QtCore/QtGlobal> #include <QtCore/QThread> #include <QtCore/QSysInfo> @@ -44,6 +45,7 @@ #if defined(Q_OS_WASM) #include <QtCore/private/qstdweb_p.h> +#include "emscripten/threading.h" #include "emscripten/val.h" #endif @@ -2136,6 +2138,12 @@ void tst_QSettings::testThreadSafety() #if !QT_CONFIG(thread) QSKIP("This test requires threads to be enabled."); #endif // !QT_CONFIG(thread) +#if defined(Q_OS_WASM) + if (!qstdweb::haveJspi()) + QSKIP("Test needs jspi on WASM. Calls are proxied to the main thread from SettingsThreads, " + "which necessitates the use of an event loop to yield to the main loop. Event loops " + "require jspi."); +#endif SettingsThread threads[NumThreads]; int i, j; @@ -2144,6 +2152,19 @@ void tst_QSettings::testThreadSafety() for (i = 0; i < NumThreads; ++i) threads[i].start(i + 1); + +#if defined(Q_OS_WASM) && QT_CONFIG(thread) + QEventLoop loop; + int remaining = NumThreads; + for (int i = 0; i < NumThreads; ++i) { + QObject::connect(&threads[i], &QThread::finished, this, [&remaining, &loop]() { + if (!--remaining) + loop.quit(); + }); + } + loop.exec(); +#endif // defined(Q_OS_WASM) && QT_CONFIG(thread) + for (i = 0; i < NumThreads; ++i) threads[i].wait(); |