MCPcopy Create free account
hub / github.com/apache/brpc / TEST_F

Function TEST_F

test/file_watcher_unittest.cpp:34–76  ·  view source on GitHub ↗

gejun: check basic functions of butil::FileWatcher

Source from the content-addressed store, hash-verified

32
33//! gejun: check basic functions of butil::FileWatcher
34TEST_F(FileWatcherTest, random_op) {
35 srand (time(0));
36
37 butil::FileWatcher fw;
38 EXPECT_EQ (0, fw.init("dummy_file"));
39
40 for (int i=0; i<30; ++i) {
41 if (rand() % 2) {
42 const butil::FileWatcher::Change ret = fw.check_and_consume();
43 switch (ret) {
44 case butil::FileWatcher::UPDATED:
45 LOG(INFO) << fw.filepath() << " is updated";
46 break;
47 case butil::FileWatcher::CREATED:
48 LOG(INFO) << fw.filepath() << " is created";
49 break;
50 case butil::FileWatcher::DELETED:
51 LOG(INFO) << fw.filepath() << " is deleted";
52 break;
53 case butil::FileWatcher::UNCHANGED:
54 LOG(INFO) << fw.filepath() << " does not change or still not exist";
55 break;
56 }
57 }
58
59 switch (rand() % 2) {
60 case 0:
61 ASSERT_EQ(0, system("touch dummy_file"));
62 LOG(INFO) << "action: touch dummy_file";
63 break;
64 case 1:
65 ASSERT_EQ(0, system("rm -f dummy_file"));
66 LOG(INFO) << "action: rm -f dummy_file";
67 break;
68 case 2:
69 LOG(INFO) << "action: (nothing)";
70 break;
71 }
72
73 usleep (10000);
74 }
75 ASSERT_EQ(0, system("rm -f dummy_file"));
76}
77
78} // namespace

Callers

nothing calls this directly

Calls 3

check_and_consumeMethod · 0.80
filepathMethod · 0.80
initMethod · 0.45

Tested by

no test coverage detected