added flush that waits for io to finish

updated tests as well to use flush instead of setTimeout