@@ -853,12 +853,20 @@ TEST(TableTest, ApproximateOffsetOfCompressed) {
853853 options.compression = kSnappyCompression ;
854854 c.Finish (options, &keys, &kvmap);
855855
856- ASSERT_TRUE (Between (c.ApproximateOffsetOf (" abc" ), 0 , 0 ));
857- ASSERT_TRUE (Between (c.ApproximateOffsetOf (" k01" ), 0 , 0 ));
858- ASSERT_TRUE (Between (c.ApproximateOffsetOf (" k02" ), 0 , 0 ));
859- ASSERT_TRUE (Between (c.ApproximateOffsetOf (" k03" ), 2000 , 3000 ));
860- ASSERT_TRUE (Between (c.ApproximateOffsetOf (" k04" ), 2000 , 3000 ));
861- ASSERT_TRUE (Between (c.ApproximateOffsetOf (" xyz" ), 4000 , 6000 ));
856+ // Expected upper and lower bounds of space used by compressible strings.
857+ static const int kSlop = 1000 ; // Compressor effectiveness varies.
858+ const int expected = 2500 ; // 10000 * compression ratio (0.25)
859+ const int min_z = expected - kSlop ;
860+ const int max_z = expected + kSlop ;
861+
862+ ASSERT_TRUE (Between (c.ApproximateOffsetOf (" abc" ), 0 , kSlop ));
863+ ASSERT_TRUE (Between (c.ApproximateOffsetOf (" k01" ), 0 , kSlop ));
864+ ASSERT_TRUE (Between (c.ApproximateOffsetOf (" k02" ), 0 , kSlop ));
865+ // Have now emitted a large compressible string, so adjust expected offset.
866+ ASSERT_TRUE (Between (c.ApproximateOffsetOf (" k03" ), min_z, max_z));
867+ ASSERT_TRUE (Between (c.ApproximateOffsetOf (" k04" ), min_z, max_z));
868+ // Have now emitted two large compressible strings, so adjust expected offset.
869+ ASSERT_TRUE (Between (c.ApproximateOffsetOf (" xyz" ), 2 * min_z, 2 * max_z));
862870}
863871
864872} // namespace leveldb
0 commit comments