| 102 | class GarbageCollectorTest : public TemporaryDirectoryTest {}; |
| 103 | |
| 104 | TEST_F(GarbageCollectorTest, Schedule) |
| 105 | { |
| 106 | GarbageCollector gc("work_dir"); |
| 107 | |
| 108 | // Make some temporary files to gc. |
| 109 | const string& file1 = "file1"; |
| 110 | const string& file2 = "file2"; |
| 111 | const string& file3 = "file3"; |
| 112 | |
| 113 | ASSERT_SOME(os::touch(file1)); |
| 114 | ASSERT_SOME(os::touch(file2)); |
| 115 | ASSERT_SOME(os::touch(file3)); |
| 116 | |
| 117 | ASSERT_TRUE(os::exists(file1)); |
| 118 | ASSERT_TRUE(os::exists(file2)); |
| 119 | ASSERT_TRUE(os::exists(file3)); |
| 120 | |
| 121 | Clock::pause(); |
| 122 | |
| 123 | Future<Nothing> scheduleDispatch1 = |
| 124 | FUTURE_DISPATCH(_, &GarbageCollectorProcess::schedule); |
| 125 | Future<Nothing> scheduleDispatch2 = |
| 126 | FUTURE_DISPATCH(_, &GarbageCollectorProcess::schedule); |
| 127 | Future<Nothing> scheduleDispatch3 = |
| 128 | FUTURE_DISPATCH(_, &GarbageCollectorProcess::schedule); |
| 129 | |
| 130 | // Schedule the gc operations. |
| 131 | Future<Nothing> schedule1 = gc.schedule(Seconds(10), file1); |
| 132 | Future<Nothing> schedule2 = gc.schedule(Seconds(10), file2); |
| 133 | Future<Nothing> schedule3 = gc.schedule(Seconds(15), file3); |
| 134 | |
| 135 | // Ensure the dispatches are completed before advancing the clock. |
| 136 | AWAIT_READY(scheduleDispatch1); |
| 137 | AWAIT_READY(scheduleDispatch2); |
| 138 | AWAIT_READY(scheduleDispatch3); |
| 139 | Clock::settle(); |
| 140 | |
| 141 | JSON::Object metrics = Metrics(); |
| 142 | |
| 143 | ASSERT_EQ(1u, metrics.values.count("gc/path_removals_pending")); |
| 144 | EXPECT_SOME_EQ( |
| 145 | 3u, |
| 146 | metrics.at<JSON::Number>("gc/path_removals_pending")); |
| 147 | |
| 148 | // Advance the clock to trigger the GC of file1 and file2. |
| 149 | Clock::advance(Seconds(10)); |
| 150 | Clock::settle(); |
| 151 | |
| 152 | AWAIT_READY(schedule1); |
| 153 | AWAIT_READY(schedule2); |
| 154 | ASSERT_TRUE(schedule3.isPending()); |
| 155 | |
| 156 | EXPECT_FALSE(os::exists(file1)); |
| 157 | EXPECT_FALSE(os::exists(file2)); |
| 158 | EXPECT_TRUE(os::exists(file3)); |
| 159 | |
| 160 | // Trigger the GC of file3. |
| 161 | Clock::advance(Seconds(5)); |
nothing calls this directly
no test coverage detected