You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Use of this software is governed by the Business Source License 1.1 included in the file licenses/BSL.txt.
4
+
*
5
+
* As of the Change Date specified in that file, in accordance with the Business Source License, use of this software will be governed by the Apache License, version 2.0.
6
+
*/
7
+
8
+
#include<folly/futures/Future.h>
9
+
#include<gtest/gtest.h>
10
+
11
+
/**
12
+
* We rely on folly::window continuing to process the collection even after one of the futures throws.
13
+
*
14
+
* Since this is not clearly tested in Folly itself, we have this regression test in case they break it in future.
15
+
*
16
+
* At time of writing, the symbol size calculation APIs `test_symbol_sizes.py` rely on this.
17
+
*/
18
+
TEST(Window, ContinuesOnException) {
19
+
usingnamespacefolly;
20
+
std::vector<int> ints(1000);
21
+
for (int i = 0; i < 1000; i++) {
22
+
ints.push_back(i);
23
+
}
24
+
25
+
std::vector<Promise<int>> ps(1000);
26
+
27
+
auto res = reduce(
28
+
window(
29
+
ints,
30
+
[&ps](int i) {
31
+
if (i % 4 == 0) {
32
+
throwstd::runtime_error("exception should not kill process");
33
+
}
34
+
return ps[i].getFuture();
35
+
},
36
+
2),
37
+
0,
38
+
[](int sum, const Try<int>& b) {
39
+
sum += b.hasException<std::exception>() ? 0 : 1;
40
+
return sum;
41
+
});
42
+
43
+
for (auto& p : ps) {
44
+
p.setValue(0);
45
+
}
46
+
47
+
// 100 / 4 = 250 of the futures threw, 750 completed successfully
0 commit comments