From e8f462fab0a6a52c4f47165be641476e3166c5f3 Mon Sep 17 00:00:00 2001 From: Russell Brown Date: Tue, 7 Aug 2018 12:23:43 +0100 Subject: [PATCH] Fix timezone specific failing test Converts date time to a local now --- src/leveled_iclerk.erl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/leveled_iclerk.erl b/src/leveled_iclerk.erl index f836b60..2424293 100644 --- a/src/leveled_iclerk.erl +++ b/src/leveled_iclerk.erl @@ -710,7 +710,9 @@ schedule_test() -> schedule_test_bycount(4). schedule_test_bycount(N) -> - CurrentTS = {1490,884020,0}, % Actually 30th March 2017 15:27 + LocalTimeAsDateTime = {{2017,3,30},{15,27,0}}, + CurrentTS= local_time_to_now(LocalTimeAsDateTime), + %% CurrentTS = {1490,884020,0}, % Actually 30th March 2017 15:27 SecondsToCompaction0 = schedule_compaction([16], N, CurrentTS), io:format("Seconds to compaction ~w~n", [SecondsToCompaction0]), ?assertMatch(true, SecondsToCompaction0 > 1800), @@ -721,6 +723,11 @@ schedule_test_bycount(N) -> ?assertMatch(true, SecondsToCompaction1 >= 81180), ?assertMatch(true, SecondsToCompaction1 =< 84780). +local_time_to_now(DateTime) -> + [UTC] = calendar:local_time_to_universal_time_dst(DateTime), + Epoch = calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}}), + Seconds = calendar:datetime_to_gregorian_seconds(UTC) - Epoch, + {Seconds div 1000000, Seconds rem 1000000, 0}. simple_score_test() -> Run1 = [#candidate{compaction_perc = 75.0},