proxygen
ThreadedRepeatingFunctionRunnerTest.cpp File Reference

Go to the source code of this file.

Classes

class  Foo
 
struct  FooLongSleep
 

Functions

 TEST (TestThreadedRepeatingFunctionRunner, HandleBackgroundLoop)
 
 TEST (TestThreadedRepeatingFunctionRunner, HandleLongSleepingThread)
 

Function Documentation

TEST ( TestThreadedRepeatingFunctionRunner  ,
HandleBackgroundLoop   
)

Definition at line 58 of file ThreadedRepeatingFunctionRunnerTest.cpp.

References data, EXPECT_EQ, and f.

58  {
59  std::atomic<int> data(0);
60  {
61  Foo f(data);
62  EXPECT_EQ(0, data.load());
63  f.start(); // Runs increment thread in background
64  while (data.load() == 0) {
65  /* sleep override */ this_thread::sleep_for(chrono::milliseconds(10));
66  }
67  }
68  // The increment thread should have been destroyed
69  auto prev_val = data.load();
70  /* sleep override */ this_thread::sleep_for(chrono::milliseconds(100));
71  EXPECT_EQ(data.load(), prev_val);
72 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
TEST ( TestThreadedRepeatingFunctionRunner  ,
HandleLongSleepingThread   
)

Definition at line 74 of file ThreadedRepeatingFunctionRunnerTest.cpp.

References data, EXPECT_EQ, f, and FooLongSleep::start().

74  {
75  std::atomic<int> data(0);
76  {
78  EXPECT_EQ(0, data.load());
79  f.start();
80  while (data.load() == 0) {
81  /* sleep override */ this_thread::sleep_for(chrono::milliseconds(10));
82  }
83  EXPECT_EQ(1, data.load());
84  }
85  // Foo should have been destroyed, which stopped the thread!
86  EXPECT_EQ(-1, data.load());
87 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43