15 #include <boost/thread.hpp>
16 #include <gtest/gtest.h>
18 #include <sys/resource.h>
32 limit.rlim_cur = limit.rlim_max = 0;
33 setrlimit(RLIMIT_CORE, &limit);
48 TEST(PromiseTest, BasicTest) {
50 thread promise_setter(
RunThread, &promise);
52 DCHECK_EQ(promise.
Get(), 100);
55 TEST(PromiseTest, TimeoutTest) {
57 bool timed_out =
true;
59 thread promise_setter(
RunThread, &fulfilled_promise);
60 DCHECK_EQ(fulfilled_promise.
Get(10000, &timed_out), 100);
61 DCHECK_EQ(timed_out,
false);
64 int64_t start_time, end_time;
68 timedout_promise.
Get(1000, &timed_out);
69 DCHECK_EQ(timed_out,
true);
71 DCHECK_GE(end_time - start_time, 1000);
74 TEST(PromiseDeathTest, RepeatedSetTest) {
81 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
84 ASSERT_DEATH(promise.
Set(150),
"Called Set\\(\\.\\.\\) twice on the same Promise");
89 int main(
int argc,
char **argv) {
90 google::InitGoogleLogging(argv[0]);
91 ::testing::InitGoogleTest(&argc, argv);
92 return RUN_ALL_TESTS();
void RunThread(Promise< int64_t > *promise)
int main(int argc, char **argv)
int64_t MonotonicMillis()