close streams carefully at end of test