Skip to content

Commit

Permalink
Merge branch 'branches/rudder/8.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
clarktsiory committed Oct 9, 2024
2 parents 5a34a2c + 673b8c1 commit b2e6dbb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ case class EditorTechniqueError(

sealed trait CompilationStatus
case object CompilationStatusAllSuccess extends CompilationStatus
case class CompilationStatusErrors(techniquesInError: NonEmptyChunk[EditorTechniqueError]) extends CompilationStatus
case class CompilationStatusErrors(techniquesInError: NonEmptyChunk[EditorTechniqueError]) extends CompilationStatus {
def ++(other: CompilationStatusErrors): CompilationStatusErrors = CompilationStatusErrors(
this.techniquesInError ++ other.techniquesInError
)
}

/**
* Get latest global techniques compilation results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import org.specs2.specification.BeforeAfterAll
import zio.Chunk
import zio.NonEmptyChunk
import zio.ZIO
import zio.*
import zio.syntax.*

@RunWith(classOf[JUnitRunner])
class TestTechniqueCompilationCache extends Specification with BeforeAfterAll {

sequential

/*
* Reading things
*/
Expand Down Expand Up @@ -141,8 +141,15 @@ class TestTechniqueCompilationCache extends Specification with BeforeAfterAll {
)
}

val msgLock = Semaphore.make(1).runNow
// sync with actor
private val mockActor = new MockLiftActor
private val mockActor = new MockLiftActor {
override def !(param: Any): Unit = msgLock
.withPermit(
super.!(param).succeed
)
.runNow
}
private val writeCache = TechniqueCompilationErrorsActorSync.make(mockActor, compilationStatusService).runNow

// create output test files for each technique
Expand All @@ -154,11 +161,29 @@ class TestTechniqueCompilationCache extends Specification with BeforeAfterAll {
.runNow
}

val expectedListOfOutputs: List[EditorTechniqueCompilationResult] = List(
val expectedListOfOutputs: List[EditorTechniqueCompilationResult] = List(
EditorTechniqueCompilationResult(technique1.id, technique1.version, technique1.name, CompilationResult.Error("tech1 error")),
EditorTechniqueCompilationResult(technique2.id, technique2.version, technique2.name, CompilationResult.Success),
EditorTechniqueCompilationResult(technique3.id, technique3.version, technique3.name, CompilationResult.Error("tech3 error"))
)
val expectedCompilationStatus: CompilationStatusErrors = {
CompilationStatusErrors(
NonEmptyChunk(
EditorTechniqueError(
technique1.id,
technique1.version,
technique1.name,
"tech1 error"
),
EditorTechniqueError(
technique3.id,
technique3.version,
technique3.name,
"tech3 error"
)
)
)
}

override def afterAll(): Unit = {
compilationDir.delete()
Expand All @@ -172,42 +197,32 @@ class TestTechniqueCompilationCache extends Specification with BeforeAfterAll {

"Error repository" should {
"Correctly build the status" in {
writeCache.updateStatus(expectedListOfOutputs).runNow must beEqualTo(
CompilationStatusErrors(
NonEmptyChunk(
EditorTechniqueError(
technique1.id,
technique1.version,
technique1.name,
"tech1 error"
),
EditorTechniqueError(
technique3.id,
technique3.version,
technique3.name,
"tech3 error"
)
)
)
)
writeCache.updateStatus(expectedListOfOutputs).runNow must beEqualTo(expectedCompilationStatus)
}

"sync with UI" in {
(writeCache.syncOne(expectedListOfOutputs.head) *> IOResult.attempt(
mockActor hasReceivedMessage_? (UpdateCompilationStatus(
CompilationStatusErrors(
NonEmptyChunk(
EditorTechniqueError(
technique1.id,
technique1.version,
technique1.name,
"tech1 error"
)
)
val newError = {
EditorTechniqueCompilationResult(
BundleName("new tech"),
technique1.version,
"new tech",
CompilationResult.Error("new tech error")
)
}
val expectedStatus = CompilationStatusErrors(
NonEmptyChunk(
EditorTechniqueError(
newError.id,
newError.version,
newError.name,
"new tech error"
)
))
)).runNow

)
)
(writeCache.syncOne(newError) *> // println(mockActor.messages.head).succeed *>
msgLock.withPermit(
(mockActor hasReceivedMessage_? UpdateCompilationStatus(expectedCompilationStatus ++ expectedStatus)).succeed
)).runNow must beTrue and (mockActor.messageCount must beEqualTo(1))
}
}
}

0 comments on commit b2e6dbb

Please sign in to comment.