fix bugs in the cursor StringOperations test
authorAdam Simpkins <simpkins@fb.com>
Sun, 24 Nov 2013 23:07:33 +0000 (15:07 -0800)
committerJordan DeLong <jdelong@fb.com>
Fri, 20 Dec 2013 21:02:34 +0000 (13:02 -0800)
commitefc30713168057144e45a0bdea094d1025c6e9cc
treee50f293b49c1b040d014043fb5bb1520dcc22229
parentf5cac66e7afed78ae6ad79d1648a779ec31542e7
fix bugs in the cursor StringOperations test

Summary:
The IOBuf.StringOperations test contained two buggy tests.  According to
the comments, they were intended to test a string spanning multiple
buffers.  They created a chain of two buffers, but used Appender to
write the string, which only writes in the final buffer in the chain.

Additionally, the test didn't request enough space in the final buffer
for the string data, and didn't allow Appender to grow the buffer.  (The
code also didn't check the return value from pushAtMost() to see if it
actually wrote all of the string data.)  The test only passed because
IOBuf would normally allocate more capacity than the caller requested.

I fixed the tests to request sufficient capacity for the string data,
and use push() rather than pushAtMost() to ensure that all data was
written correctly.  I also added two new tests which actually test with
strings spanning multiple buffers.

Test Plan:
Ran this test with some changes to IOBuf that cause it to only allocate
the requested capacity in some cases, and verified that the
StringOperations test pass now.

(The changes I was testing with use goodMallocSize() to determine the
allocation size even for small internal buffers.  When not using
jemalloc, goodMallocSize() returns the original size, so it only
allocates the capacity requested by the caller.)

Reviewed By: pgriess@fb.com

FB internal diff: D1072283
folly/io/test/IOBufCursorTest.cpp