Skip to content

Commit

Permalink
Query number of items to wait for
Browse files Browse the repository at this point in the history
  • Loading branch information
eikek committed Jul 12, 2023
1 parent 2981c53 commit 6082513
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package io.renku.graph.acceptancetests.flows

import cats.data.NonEmptyList
import cats.effect.unsafe.IORuntime
import cats.syntax.all._
import io.renku.events.CategoryName
import io.renku.generators.Generators.Implicits._
import io.renku.graph.acceptancetests.data
Expand Down Expand Up @@ -74,7 +75,9 @@ trait TSProvisioning
sleep((5 seconds).toMillis)
}

`wait for events to be processed`(project.id, accessToken, commitIds.size)
val items = eventLogClient.getEvents(project.id.asLeft).unsafeRunSync().size

`wait for events to be processed`(project.id, accessToken, math.min(0, items))
}

def `wait for events to be processed`(
Expand All @@ -87,7 +90,7 @@ trait TSProvisioning
response.status shouldBe Ok
response.jsonBody.hcursor.downField("activated").as[Boolean].value shouldBe true
response.jsonBody.hcursor.downField("progress").downField("percentage").as[Double].value shouldBe 100d
response.jsonBody.hcursor.downField("progress").downField("total").as[Int].value shouldBe expectedDone
response.jsonBody.hcursor.downField("progress").downField("total").as[Int].value should be >= expectedDone
}

def `check hook cannot be found`(projectId: projects.GitLabId, accessToken: AccessToken): Assertion = eventually {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.scalatest.time.{Minutes, Second, Span}
trait AcceptanceTestPatience extends AbstractPatienceConfiguration {

implicit override val patienceConfig: PatienceConfig = PatienceConfig(
timeout = scaled(Span(4, Minutes)),
timeout = scaled(Span(6, Minutes)),
interval = scaled(Span(1, Second))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import cats.syntax.all._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.string.Url
import io.circe.Json
import io.circe.generic.semiauto.deriveDecoder
import io.circe.{Decoder, Json}
import io.circe.literal._
import io.renku.control.Throttler
import io.renku.graph.acceptancetests.tooling.ServiceClient.ClientResponse
import io.renku.graph.model.events.{EventId, EventStatus}
import io.renku.graph.model.projects
import io.renku.http.client.{AccessToken, BasicAuthCredentials, RestClient}
import io.renku.http.tinytypes.TinyTypeURIEncoder._
Expand Down Expand Up @@ -120,6 +122,21 @@ object KnowledgeGraphClient {
}

object EventLogClient {
final case class ProjectEvent(
id: EventId,
project: ProjectEvent.Project,
status: EventStatus
)
object ProjectEvent {
import io.renku.tinytypes.json.TinyTypeDecoders._

final case class Project(id: projects.GitLabId, path: projects.Path)
object Project {
implicit val jsonDecoder: Decoder[Project] = deriveDecoder
}

implicit val jsonDecoder: Decoder[ProjectEvent] = deriveDecoder
}

def apply()(implicit logger: Logger[IO]): EventLogClient = new EventLogClient

Expand All @@ -138,6 +155,19 @@ object EventLogClient {
} yield ()
}.unsafeRunSync()

def getEvents(project: Either[projects.GitLabId, projects.Path]): IO[List[ProjectEvent]] =
for {
uri <- validateUri(s"$baseUrl/events").map(uri =>
project.fold(id => uri.withQueryParam("project-id", id.value),
path => uri.withQueryParam("project-path", path.value)
)
)
req = request(Method.GET, uri)
r <- send(req) { case (Status.Ok, _, resp) =>
resp.as[List[ProjectEvent]]
}
} yield r

private def createRequest(uri: Uri, event: Json) =
request(Method.POST, uri).withMultipartBuilder
.addPart("event", event)
Expand Down

0 comments on commit 6082513

Please sign in to comment.