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

Side by Side Diff: test/SchedulerTest.cpp

Issue 29367507: Issue #3595 - Add an actual scheduler; use joined threads for file system
Patch Set: Created Dec. 14, 2016, 5:38 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« src/Scheduler.cpp ('K') | « test/BaseJsTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 #include "BaseJsTest.h"
19 #include "../src/Scheduler.h"
20
21 TEST(OperationRunner, Instance)
22 {
23 OperationRunner runner;
24 }
25
26 TEST(OperationRunner, RunOneThing)
27 {
28 int counter = 0;
29 {
30 OperationRunner runner;
31 runner.Run([&]() {++counter; });
32 }
33 // Runner is out of scope, so all operations must have completed
34 EXPECT_EQ(1, counter);
35 }
36
37 TEST(SingleUseWorker, Instance)
38 {
39 SingleUseWorker w;
40 }
41
42 TEST(SingleUseWorker, RunWithExplicitJoin)
43 {
44 int counter = 0;
45 SingleUseWorker w;
46 EXPECT_EQ(0, counter);
47 w.Run([&]() {++counter; });
48 w.Join();
49 EXPECT_EQ(1, counter);
50 }
51
52 TEST(SingleUseWorker, RunWithImplicitJoinInDestructor)
53 {
54 int counter = 0;
55 {
56 SingleUseWorker w;
57 EXPECT_EQ(0, counter);
58 w.Run([&]() {++counter; });
59 }
60 EXPECT_EQ(1, counter);
61 }
62
63 TEST(Scheduler, Instance)
64 {
65 SchedulerT<SingleUseWorker> s;
66 }
67
68 TEST(Scheduler, RunOnce)
69 {
70 int counter = 0;
71 SchedulerT<SingleUseWorker> s;
72 EXPECT_EQ(0, counter);
73 s.Run([&]() {++counter; });
74 s.JoinAll();
75 EXPECT_EQ(1, counter);
76 }
77
78 TEST(Scheduler, RunTwice)
79 {
80 int counter = 0;
81 SchedulerT<SingleUseWorker> s;
82 s.Run([&]() {++counter; });
83 s.JoinAll();
84 s.Run([&]() {++counter; });
85 s.JoinAll();
86 EXPECT_EQ(2, counter);
87 }
88
89 TEST(Scheduler, RunMany)
90 {
91 std::mutex m;
92 int counter = 0;
93 SchedulerT<SingleUseWorker> s;
94 auto f = [&]() {
95 std::unique_lock<std::mutex> ul(m);
96 ++counter;
97 };
98 const int n = 100;
99 for (int j = 0; j < n; ++j)
100 {
101 auto g = f;
sergei 2017/01/20 13:08:14 why do we need g?
Eric 2017/03/30 17:16:59 It's explicitly a copy of f. Perhaps unnecessary,
102 s.Run(g);
103 }
104 ASSERT_NO_THROW(s.JoinAll());
105 EXPECT_EQ(n, counter);
106 }
OLDNEW
« src/Scheduler.cpp ('K') | « test/BaseJsTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld