Skip to content

Commit 9009a5c

Browse files
authored
Sync PagePinMediumTest (#752)
sync with private
1 parent 80b4544 commit 9009a5c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

test/buffer/buffer_pool_manager_test.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ TEST(BufferPoolManagerTest, DISABLED_PagePinMediumTest) {
169169
snprintf(page0.GetDataMut(), BUSTUB_PAGE_SIZE, "Hello");
170170
EXPECT_EQ(0, strcmp(page0.GetDataMut(), "Hello"));
171171

172+
page0.Drop();
173+
172174
// Create a vector of unique pointers to page guards, which prevents the guards from getting destructed.
173-
std::deque<WritePageGuard> pages;
174-
pages.push_back(std::move(page0));
175+
std::vector<WritePageGuard> pages;
175176

176177
// Scenario: We should be able to create new pages until we fill up the buffer pool.
177-
for (size_t i = 1; i < FRAMES; i++) {
178+
for (size_t i = 0; i < FRAMES; i++) {
178179
auto pid = bpm->NewPage();
179180
auto page = bpm->WritePage(pid);
180181
pages.push_back(std::move(page));
@@ -187,17 +188,17 @@ TEST(BufferPoolManagerTest, DISABLED_PagePinMediumTest) {
187188
}
188189

189190
// Scenario: Once the buffer pool is full, we should not be able to create any new pages.
190-
for (size_t i = 0; i < 10; i++) {
191+
for (size_t i = 0; i < FRAMES; i++) {
191192
auto pid = bpm->NewPage();
192193
auto fail = bpm->CheckedWritePage(pid);
193194
ASSERT_FALSE(fail.has_value());
194195
}
195196

196197
// Scenario: Drop the first 5 pages to unpin them.
197-
for (size_t i = 0; i < 5; i++) {
198+
for (size_t i = 0; i < FRAMES / 2; i++) {
198199
page_id_t pid = pages[0].GetPageId();
199200
EXPECT_EQ(1, bpm->GetPinCount(pid));
200-
pages.pop_front();
201+
pages.erase(pages.begin());
201202
EXPECT_EQ(0, bpm->GetPinCount(pid));
202203
}
203204

@@ -207,9 +208,9 @@ TEST(BufferPoolManagerTest, DISABLED_PagePinMediumTest) {
207208
EXPECT_EQ(1, bpm->GetPinCount(pid));
208209
}
209210

210-
// Scenario: After unpinning pages {0, 1, 2, 3, 4}, we should be able to create 4 new pages and bring them into
211-
// memory. Bringing those 4 pages into memory should evict the first 4 pages {0, 1, 2, 3} because of LRU.
212-
for (size_t i = 0; i < 4; i++) {
211+
// Scenario: After unpinning pages {1, 2, 3, 4, 5}, we should be able to create 4 new pages and bring them into
212+
// memory. Bringing those 4 pages into memory should evict the first 4 pages {1, 2, 3, 4} because of LRU.
213+
for (size_t i = 0; i < ((FRAMES / 2) - 1); i++) {
213214
auto pid = bpm->NewPage();
214215
auto page = bpm->WritePage(pid);
215216
pages.push_back(std::move(page));

0 commit comments

Comments
 (0)