improved test

- fixed testPermanentDeleteFile sometimes failed
- speed optimization
- reformat code

cc @schiesbn @DeepDiver1975