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

Side by Side Diff: test/FilterEngine.cpp

Issue 29361562: Issue 3594 - remove circular references JsEngine-JsValue-JsEngine (Closed)
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:
View unified diff | Download patch
OLDNEW
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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 documentUrls1.push_back("http://example.de"); 528 documentUrls1.push_back("http://example.de");
527 529
528 ASSERT_TRUE(filterEngine->IsElemhideWhitelisted( 530 ASSERT_TRUE(filterEngine->IsElemhideWhitelisted(
529 "http://example.com", 531 "http://example.com",
530 documentUrls1)); 532 documentUrls1));
531 533
532 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted( 534 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted(
533 "http://example.co.uk", 535 "http://example.co.uk",
534 documentUrls1)); 536 documentUrls1));
535 } 537 }
538
539 TEST(NewFilterEngineTest, MemoryLeak_NoCircularReferences)
540 {
541 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine;
542 {
543 auto jsEngine = AdblockPlus::JsEngine::New();
544 weakJsEngine = jsEngine;
545 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem()));
546 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest()));
547 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem()));
548 auto filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)) ;
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 }
560 EXPECT_FALSE(weakJsEngine.lock());
561 }
OLDNEW
« src/JsValue.cpp ('K') | « test/BaseJsTest.cpp ('k') | test/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld