Skip to content

Commit

Permalink
Relax the block count check on deallocation in env_test
Browse files Browse the repository at this point in the history
It seems that on some FS we get more blocks than we ask for. This is
already handled when checking the allocated number of blocks, but
after the file is closed it checks for an exact number of blocks,
which fails on my machine.

I changed the test to add one full page to the size, then calculate
the expected number of blocks and check if the actual number of blocks
is less or equal to that.
  • Loading branch information
lalinsky committed Nov 14, 2014
1 parent f822129 commit 746cfaa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions util/env_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ TEST(EnvPosixTest, AllocateTest) {
// allocate 100 MB
size_t kPreallocateSize = 100 * 1024 * 1024;
size_t kBlockSize = 512;
size_t kPageSize = 4096;
std::string data(1024 * 1024, 'a');
wfile->SetPreallocationBlockSize(kPreallocateSize);
ASSERT_OK(wfile->Append(Slice(data)));
Expand All @@ -565,16 +566,17 @@ TEST(EnvPosixTest, AllocateTest) {
// we only require that number of allocated blocks is at least what we expect.
// It looks like some FS give us more blocks that we asked for. That's fine.
// It might be worth investigating further.
auto st_blocks = f_stat.st_blocks;
ASSERT_LE((unsigned int)(kPreallocateSize / kBlockSize), st_blocks);
ASSERT_LE((unsigned int)(kPreallocateSize / kBlockSize), f_stat.st_blocks);

// close the file, should deallocate the blocks
wfile.reset();

stat(fname.c_str(), &f_stat);
ASSERT_EQ((unsigned int)data.size(), f_stat.st_size);
// verify that preallocated blocks were deallocated on file close
ASSERT_EQ((f_stat.st_size + kBlockSize - 1) / kBlockSize, (unsigned int)f_stat.st_blocks);
// Because the FS might give us more blocks, we add a full page to the size
// and expect the number of blocks to be less or equal to that.
ASSERT_GE((f_stat.st_size + kPageSize + kBlockSize - 1) / kBlockSize, (unsigned int)f_stat.st_blocks);
}
#endif // ROCKSDB_FALLOCATE_PRESENT

Expand Down

0 comments on commit 746cfaa

Please sign in to comment.