From 27fd561af6d63853667e65b479157da6736694bb Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Thu, 9 Jan 2020 17:53:43 +0100 Subject: [PATCH] Fix trigger time tests (#4002) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These have failed quite a few times on Windows and occasionally also on MacOS. This test, first fixes a small issue where the tests were actually using the times from completions instead of only the timings from creations. (that technically shouldn’t be an issue but it’s at least confusing since the error claims to test creations). In addition to that, this PR changes the condition to allow for the times to be equal since especially on Windows we don’t seem to have a very high resolution and the tests are remarkably quick so sometimes the times can be identical. I’ve slightly rephrased the condition since I got confused by the fact that we test for the negated condition. changelog_begin changelog_end --- triggers/tests/daml/Time.daml | 16 ++++++++-------- .../daml/lf/engine/trigger/test/TestMain.scala | 9 +++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/triggers/tests/daml/Time.daml b/triggers/tests/daml/Time.daml index 2fab9678c55a..1cf306abf700 100644 --- a/triggers/tests/daml/Time.daml +++ b/triggers/tests/daml/Time.daml @@ -11,14 +11,14 @@ test = Trigger { initialState = \party _ _ -> ((False, []), [Commands (CommandId "a") [createCmd (T party)]]) , update = \time msg (done, ts) -> - let - cmds = case (done, msg) of - (False, MTransaction (Transaction _ _ [CreatedEvent (fromCreated @T -> Some (_, _, t))])) -> - [Commands (CommandId "b") [createCmd t]] - _ -> [] - newState = (True, time :: ts) - in - (newState, cmds) + case msg of + MTransaction (Transaction _ _ events) -> + let cmds = case (done, events) of + (False, [CreatedEvent (fromCreated @T -> Some (_, _, t))]) -> [Commands (CommandId "b") [createCmd t]] + _ -> [] + newState = (True, time :: ts) + in (newState, cmds) + _ -> ((done, ts), []) , registeredTemplates = AllInDar } diff --git a/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/TestMain.scala b/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/TestMain.scala index 199da8051683..17d619eaefaf 100644 --- a/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/TestMain.scala +++ b/triggers/tests/src/test/scala/com/digitalasset/daml/lf/engine/trigger/test/TestMain.scala @@ -945,8 +945,9 @@ case class TimeTests(dar: Dar[(PackageId, Package)], runner: TestRunner) { case TimeProviderType.Static => TestRunner.assertEqual(timeA, timeB, "static times") case _ => - if (timeA <= timeB) { - Left(s"Second create should have happened after first") + // Given the limited resolution it can happen that timeA == timeB + if (!(timeA >= timeB)) { + Left(s"Second create at $timeA should have happened after first $timeB") } else { Right(()) } @@ -977,8 +978,8 @@ case class TimeTests(dar: Dar[(PackageId, Package)], runner: TestRunner) { test( "Time", "test", - // 2 creates - NumMessages(2) + // 2 creates and 2 completions + NumMessages(4) ) } }