From 95e7b53402cc5d189a5336903a59b0fde807e590 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Mon, 12 Sep 2022 17:40:59 +0300 Subject: [PATCH] test_sort: make timeout smarter, wait if failed to create dir Before the change it slept for 0.1 seconds and right after that asserted if `sort` has created the directory. Sometimes `sort` didn't manage to create the directory in 0.1 seconds. So the change is it tries to wait for `timeout` starting with 0.1 seconds, and if directory was not found, it tries 4 more times, each time increasing timeout twice. Once the directory is found it breaks. --- tests/by-util/test_sort.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index ff4c79427..e0bfb6025 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -1124,7 +1124,14 @@ fn test_tmp_files_deleted_on_sigint() { ]); let mut child = ucmd.run_no_wait(); // wait a short amount of time so that `sort` can create a temporary directory. - std::thread::sleep(Duration::from_millis(100)); + let mut timeout = Duration::from_millis(100); + for _ in 0..5 { + std::thread::sleep(timeout); + if read_dir(at.plus("tmp_dir")).unwrap().next().is_some() { + break; + } + timeout *= 2; + } // `sort` should have created a temporary directory. assert!(read_dir(at.plus("tmp_dir")).unwrap().next().is_some()); // kill sort with SIGINT