Skip to content

Commit

Permalink
Merge pull request #104 from guardian/wait-for-state-to-settle-before…
Browse files Browse the repository at this point in the history
…-testing-if-it-does-not-change

Wait for state to settle before testing that it doesn't change
  • Loading branch information
rtyley committed Jun 13, 2023
2 parents ad29deb + a61a2b1 commit f566d6f
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions test/lib/Helpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ trait Helpers extends PlaySpec with OneAppPerSuiteWithComponents with Inspectors
case class RepoPR(pr: PullRequest) {
val githubRepo = pr.baseRepo

def currentPR(): PullRequest = githubRepo.pullRequests.get(pr.number).futureValue
def currentPR(): PullRequest = {
def fetchPR(): PullRequest = githubRepo.pullRequests.get(pr.number).futureValue

eventually {
val pr = fetchPR()
Thread.sleep(1000)
fetchPR() mustEqual pr
pr
}
}

def listComments(): Seq[Comment] = pr.comments2.list().all().futureValue

Expand Down Expand Up @@ -132,12 +141,11 @@ trait Helpers extends PlaySpec with OneAppPerSuiteWithComponents with Inspectors
}

def scanShouldNotChange[S](issueState: PullRequest => S)(implicit repoPR: RepoPR): Unit = {
val issueBeforeScan = repoPR.currentPR()
val beforeState = issueState(issueBeforeScan)
val beforeState = issueState(repoPR.currentPR())

for (check <- 1 to 3) {
whenReady(repoPR.scheduler.scan()) { s =>
issueState(repoPR.currentPR()) must equal(beforeState)
for (_ <- 1 to 3) { // Scan repo several times...
whenReady(repoPR.scheduler.scan()) { _ =>
issueState(repoPR.currentPR()) mustEqual beforeState // ... nothing should change
}
}
}
Expand Down

0 comments on commit f566d6f

Please sign in to comment.