Skip to content

Commit

Permalink
Fix trigger time tests (#4002)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cocreature authored and mergify[bot] committed Jan 9, 2020
1 parent c5b11aa commit 27fd561
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 8 additions & 8 deletions triggers/tests/daml/Time.daml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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)
)
}
}
Expand Down

0 comments on commit 27fd561

Please sign in to comment.