diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-07 12:04:47 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-07 12:04:47 +0100 |
commit | 4ecb10d3b1294d03578c28467c0f3759b3496e0b (patch) | |
tree | d8110a1109a0510746e9083b3272dda872dfe4a2 /tests/clientapitest.cpp | |
parent | 88a0c750a80e6efb207877cac73144266e62d5ff (diff) | |
download | sink-4ecb10d3b1294d03578c28467c0f3759b3496e0b.tar.gz sink-4ecb10d3b1294d03578c28467c0f3759b3496e0b.zip |
Resolved potential deadlock
When trying to reply to a mail from kube we ran into a deadlock.
The initial result callback is called from the main thread, and that can
thus directly lead to destruction of the emitter.
Diffstat (limited to 'tests/clientapitest.cpp')
-rw-r--r-- | tests/clientapitest.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index da52afb..3955ebd 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp | |||
@@ -12,6 +12,12 @@ | |||
12 | #include "asyncutils.h" | 12 | #include "asyncutils.h" |
13 | 13 | ||
14 | template <typename T> | 14 | template <typename T> |
15 | struct Result { | ||
16 | QSharedPointer<T> parent; | ||
17 | bool fetchedAll; | ||
18 | }; | ||
19 | |||
20 | template <typename T> | ||
15 | class TestDummyResourceFacade : public Sink::StoreFacade<T> | 21 | class TestDummyResourceFacade : public Sink::StoreFacade<T> |
16 | { | 22 | { |
17 | public: | 23 | public: |
@@ -68,7 +74,7 @@ public: | |||
68 | auto emitter = resultProvider->emitter(); | 74 | auto emitter = resultProvider->emitter(); |
69 | 75 | ||
70 | resultProvider->setFetcher([query, resultProvider, this, ctx](const typename T::Ptr &parent) { | 76 | resultProvider->setFetcher([query, resultProvider, this, ctx](const typename T::Ptr &parent) { |
71 | async::run<int>([=] { | 77 | async::run<Result<T>>([=] { |
72 | if (parent) { | 78 | if (parent) { |
73 | SinkTraceCtx(ctx) << "Running the fetcher " << parent->identifier(); | 79 | SinkTraceCtx(ctx) << "Running the fetcher " << parent->identifier(); |
74 | } else { | 80 | } else { |
@@ -90,14 +96,16 @@ public: | |||
90 | SinkTraceCtx(ctx) << "Aborting early after " << count << "results."; | 96 | SinkTraceCtx(ctx) << "Aborting early after " << count << "results."; |
91 | offset = i + 1; | 97 | offset = i + 1; |
92 | bool fetchedAll = (i + 1 >= results.size()); | 98 | bool fetchedAll = (i + 1 >= results.size()); |
93 | resultProvider->initialResultSetComplete(parent, fetchedAll); | 99 | return Result<T>{parent, fetchedAll}; |
94 | return 0; | ||
95 | } | 100 | } |
96 | } | 101 | } |
97 | } | 102 | } |
98 | resultProvider->initialResultSetComplete(parent, true); | 103 | return Result<T>{parent, true}; |
99 | return 0; | 104 | }, runAsync) |
100 | }, runAsync).exec(); | 105 | .then([=] (const Result<T> &r) { |
106 | resultProvider->initialResultSetComplete(r.parent, r.fetchedAll); | ||
107 | }) | ||
108 | .exec(); | ||
101 | }); | 109 | }); |
102 | auto job = KAsync::start([query, resultProvider]() {}); | 110 | auto job = KAsync::start([query, resultProvider]() {}); |
103 | mResultProvider = resultProvider.data(); | 111 | mResultProvider = resultProvider.data(); |