Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/FilterEngine.cpp

Issue 29361562: Issue 3594 - remove circular references JsEngine-JsValue-JsEngine (Closed)
Left Patch Set: address comments Created Nov. 25, 2016, 12:02 p.m.
Right Patch Set: temporary workaround for race condition Created Dec. 1, 2016, 10:26 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "BaseJsTest.h" 18 #include "BaseJsTest.h"
19 #include <thread>
20 #include <chrono>
19 21
20 namespace 22 namespace
21 { 23 {
22 typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; 24 typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr;
23 25
24 class VeryLazyFileSystem : public LazyFileSystem 26 class VeryLazyFileSystem : public LazyFileSystem
25 { 27 {
26 public: 28 public:
27 StatResult Stat(const std::string& path) const 29 StatResult Stat(const std::string& path) const
28 { 30 {
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 { 540 {
539 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine; 541 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine;
540 { 542 {
541 auto jsEngine = AdblockPlus::JsEngine::New(); 543 auto jsEngine = AdblockPlus::JsEngine::New();
542 weakJsEngine = jsEngine; 544 weakJsEngine = jsEngine;
543 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem())); 545 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem()));
544 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest())); 546 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest()));
545 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem())); 547 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem()));
546 auto filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)) ; 548 auto filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)) ;
547 } 549 }
550 {
551 // It's a hack to figure current race condition out (better than nothing):
552 // IO or timer thread still can aquire a strong reference to JsEngine right
553 // before destroying filterEngine holding JsEngine and keep it for some
554 // time, so here we need to give it a reasonable amount of time to finish
555 // the current operation.
556 uint16_t attempts = 10;
557 while (attempts-- > 0 && weakJsEngine.lock())
558 std::this_thread::sleep_for(std::chrono::milliseconds(500));
559 }
548 EXPECT_FALSE(weakJsEngine.lock()); 560 EXPECT_FALSE(weakJsEngine.lock());
549 } 561 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld