CHOP-42. Cleanup and add tests for doAndRelease, doAndClose.

@lockoff.