Skip to content

Commit

Permalink
Synchronize in multi-participant script tests (#11594)
Browse files Browse the repository at this point in the history
* Synchronize in multi-participant script tests

This hopefully fixes the flakiness where the party allocation is not
yet propagated to the other participant.

changelog_begin
changelog_end

* .

changelog_begin
changelog_end
  • Loading branch information
cocreature authored Nov 9, 2021
1 parent dd1b034 commit ac19c8c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
21 changes: 21 additions & 0 deletions daml-script/test/daml/MultiTest.daml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module MultiTest where

import DA.List
import DA.Time
import Daml.Script

template T
Expand Down Expand Up @@ -47,6 +48,12 @@ listKnownPartiesTest = do
parties2 <- listKnownPartiesOn (ParticipantName "two")
p1 <- allocatePartyOn "p1" (ParticipantName "one")
p2 <- allocatePartyOn "p2" (ParticipantName "two")
-- Synchronize by submitting transactions in both directions. This matches
-- what the ledger API test tool uses for synchronization.
proposalCid <- submit p1 $ createCmd (TProposal p1 p2)
waitForCid tries p2 proposalCid
(tCid, _) <- submit p2 $ exerciseCmd proposalCid Accept
waitForCid tries p1 tCid
parties1' <- listKnownPartiesOn (ParticipantName "one")
parties2' <- listKnownPartiesOn (ParticipantName "two")
pure
Expand All @@ -55,3 +62,17 @@ listKnownPartiesTest = do
)
where
toTuple PartyDetails{..} = (displayName, isLocal)

tries : Int
tries = 60


waitForCid : Template t => Int -> Party -> ContractId t -> Script ()
waitForCid tries p cid
| tries <= 0 = abort $ "Cid " <> show cid <> " did not appear"
| otherwise = do
r <- queryContractId p cid
case r of
None -> waitForCid (tries - 1) p cid
Some _ -> pure ()
where delay = seconds 1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.daml.lf.engine.script.ledgerinteraction.ScriptTimeMode
import com.daml.ports.Port
import org.scalatest.Suite

import scala.concurrent.duration.DurationInt
import scala.concurrent.ExecutionContext

trait MultiParticipantFixture
Expand Down Expand Up @@ -84,7 +85,9 @@ trait MultiParticipantFixture
archiveFiles = Seq(darFile),
)
)
} yield (readPortfile(participant1Portfile), readPortfile(participant2Portfile))
} yield (readPortfile(participant1Portfile), readPortfile(participant2Portfile)),
acquisitionTimeout = 1.minute,
releaseTimeout = 1.minute,
)
}

Expand Down

0 comments on commit ac19c8c

Please sign in to comment.