Skip to content

Commit

Permalink
Merge pull request #491 from scireum/feature/smo/migrateBackgorundLoo…
Browse files Browse the repository at this point in the history
…pTest

jUnit: Migrates BackgroundLoop Tests to Kotlin
  • Loading branch information
MOOOOOSER authored Sep 14, 2023
2 parents 68cbae4 + 1643c8e commit a4ca0d8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 41 deletions.
41 changes: 0 additions & 41 deletions src/test/java/sirius/kernel/async/BackgroundLoopSpec.groovy

This file was deleted.

42 changes: 42 additions & 0 deletions src/test/kotlin/sirius/kernel/async/BackgroundLoopTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - info@scireum.de
*/

package sirius.kernel.async

import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import sirius.kernel.NightlyTest
import sirius.kernel.SiriusExtension
import sirius.kernel.commons.Wait
import kotlin.test.assertTrue

@NightlyTest
@ExtendWith(SiriusExtension::class)
class BackgroundLoopSpec {
@Test
fun `BackgroundLoop limits to max frequency`() {
val currentCounter = FastTestLoop.counter.toInt()
Wait.seconds(10.0)
val delta = FastTestLoop.counter.toInt() - currentCounter
//the background loop executed enough calls (should be 10 but we're a bit tolerant here)
assertTrue { delta >= 8 }
//the background loop was limited not to execute too often (should be 10 but we're a bit tolerant here)
assertTrue { delta <= 12 }
}

@Test
fun `BackgroundLoop executes as fast as possible if loop is slow`() {
val currentCounter = SlowTestLoop.counter.toInt()
Wait.seconds(10.0)
val delta = SlowTestLoop.counter.toInt() - currentCounter
//the background loop executed enough calls (should be 5 but we're a bit tolerant here)
assertTrue { delta >= 3 }
//the background loop was limited not to execute too often (should be 5 but we're a bit tolerant here)
assertTrue { delta <= 6 }
}
}

0 comments on commit a4ca0d8

Please sign in to comment.