File 0003-Use-timer.tc-1-to-measure-time-diff-in-tests-9113.patch of Package elixir
From c0c5a486f95b54c176d1a46a2f01407a51f19a6b Mon Sep 17 00:00:00 2001
From: Fernando Tapia Rico <fertapric@gmail.com>
Date: Tue, 4 Jun 2019 11:44:44 +0200
Subject: [PATCH] Use :timer.tc/1 to measure time diff in tests (#9113)
---
lib/elixir/test/elixir/stream_test.exs | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/lib/elixir/test/elixir/stream_test.exs b/lib/elixir/test/elixir/stream_test.exs
index 08126df22..246d7f220 100644
--- a/lib/elixir/test/elixir/stream_test.exs
+++ b/lib/elixir/test/elixir/stream_test.exs
@@ -494,9 +494,11 @@ test "flat_map/2 properly halts both inner and outer stream when inner stream is
test "interval/1" do
stream = Stream.interval(10)
- now = :os.timestamp()
- assert Enum.take(stream, 5) == [0, 1, 2, 3, 4]
- assert :timer.now_diff(:os.timestamp(), now) >= 50000
+
+ {time_us, value} = :timer.tc(fn -> Enum.take(stream, 5) end)
+
+ assert value == [0, 1, 2, 3, 4]
+ assert time_us >= 50000
end
test "into/2 and run/1" do
@@ -1052,13 +1054,15 @@ test "take_while/2" do
test "timer/1" do
stream = Stream.timer(10)
- now = :os.timestamp()
- assert Enum.to_list(stream) == [0]
+
+ {time_us, value} = :timer.tc(fn -> Enum.to_list(stream) end)
+
+ assert value == [0]
# We check for >= 5000 (us) instead of >= 10000 (us)
# because the resolution on Windows system is not high
# enough and we would get a difference of 9000 from
# time to time. So a value halfway is good enough.
- assert :timer.now_diff(:os.timestamp(), now) >= 5000
+ assert time_us >= 5000
end
test "unfold/2" do
--
2.26.2