Fix test for races with multiple parallel requests (#3891)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -82,6 +82,7 @@ protected:
|
||||
private:
|
||||
std::optional<std::string> url;
|
||||
std::unique_ptr<AsyncRequest> req;
|
||||
std::atomic<uint64_t> requestGeneration{0};
|
||||
std::shared_ptr<Scheduler> sequencedScheduler;
|
||||
mapbox::base::WeakPtrFactory<Source> weakFactory{this};
|
||||
// Do not add members here, see `WeakPtrFactory`
|
||||
|
||||
@@ -99,10 +99,12 @@ void GeoJSONSource::loadDescription(FileSource& fileSource) {
|
||||
return makeMutable<Impl>(current, std::move(geoJSONData));
|
||||
},
|
||||
/* onImplReady */
|
||||
[this, self = makeWeakPtr(), capturedReq = req.get()](Immutable<Source::Impl> newImpl) {
|
||||
assert(capturedReq);
|
||||
[this, self = makeWeakPtr(), capturedReqGeneration = ++requestGeneration](
|
||||
Immutable<Source::Impl> newImpl) {
|
||||
assert(capturedReqGeneration);
|
||||
if (auto guard = self.lock(); self) {
|
||||
if (capturedReq == req.get()) { // If a new request is being processed, ignore this impl.
|
||||
if (capturedReqGeneration ==
|
||||
requestGeneration) { // If a new request is being processed, ignore this impl.
|
||||
baseImpl = std::move(newImpl);
|
||||
loaded = true;
|
||||
observer->onSourceLoaded(*this);
|
||||
|
||||
Reference in New Issue
Block a user