Merge pull request #395 from lalinsky/fix-env-test

Relax the block count check on deallocation in env_test
main
Siying Dong 10 years ago
commit 136b8583bf
  1. 8
      util/env_test.cc

@ -552,6 +552,7 @@ TEST(EnvPosixTest, AllocateTest) {
// allocate 100 MB // allocate 100 MB
size_t kPreallocateSize = 100 * 1024 * 1024; size_t kPreallocateSize = 100 * 1024 * 1024;
size_t kBlockSize = 512; size_t kBlockSize = 512;
size_t kPageSize = 4096;
std::string data(1024 * 1024, 'a'); std::string data(1024 * 1024, 'a');
wfile->SetPreallocationBlockSize(kPreallocateSize); wfile->SetPreallocationBlockSize(kPreallocateSize);
ASSERT_OK(wfile->Append(Slice(data))); ASSERT_OK(wfile->Append(Slice(data)));
@ -565,8 +566,7 @@ TEST(EnvPosixTest, AllocateTest) {
// we only require that number of allocated blocks is at least what we expect. // 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 looks like some FS give us more blocks that we asked for. That's fine.
// It might be worth investigating further. // It might be worth investigating further.
auto st_blocks = f_stat.st_blocks; ASSERT_LE((unsigned int)(kPreallocateSize / kBlockSize), f_stat.st_blocks);
ASSERT_LE((unsigned int)(kPreallocateSize / kBlockSize), st_blocks);
// close the file, should deallocate the blocks // close the file, should deallocate the blocks
wfile.reset(); wfile.reset();
@ -574,7 +574,9 @@ TEST(EnvPosixTest, AllocateTest) {
stat(fname.c_str(), &f_stat); stat(fname.c_str(), &f_stat);
ASSERT_EQ((unsigned int)data.size(), f_stat.st_size); ASSERT_EQ((unsigned int)data.size(), f_stat.st_size);
// verify that preallocated blocks were deallocated on file close // 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 #endif // ROCKSDB_FALLOCATE_PRESENT

Loading…
Cancel
Save