Tests: dump all thread stacks on failure

Sometimes when a test fails, its logs are not necessarily sufficient to determine what threads were doing at the time ... this change will dump all threads whenever there is a failure either in the main test case itself, or in the cleanup we do after the test succeeds.