mirror of
https://github.com/InsanusMokrassar/krontab.git
synced 2024-11-26 03:58:50 +00:00
new buildSchedule function and tests for string parsing
This commit is contained in:
parent
c9243d7968
commit
d8ed07da98
@ -13,7 +13,11 @@
|
|||||||
* Kotlin `1.3.70` -> `1.3.72`
|
* Kotlin `1.3.70` -> `1.3.72`
|
||||||
* Coroutines `1.3.5` -> `1.3.7`
|
* Coroutines `1.3.5` -> `1.3.7`
|
||||||
* Klock `1.10.0` -> `1.11.3`
|
* Klock `1.10.0` -> `1.11.3`
|
||||||
|
* A lot of KDocs added and fixed
|
||||||
* `EverySecondScheduler` changed its building logic - now it is lazy with builder using
|
* `EverySecondScheduler` changed its building logic - now it is lazy with builder using
|
||||||
|
* `KronScheduler#doOnce` was optimized: now it will be explicitly called once and return result of its calculations
|
||||||
|
* `KronScheduler#doWhile` was rewritten to use `KronScheduler#doOnce` for calculations of `block` result
|
||||||
|
* New `buildSchedule(String)` function as a shortcut for `createSimpleScheduler(String)`
|
||||||
|
|
||||||
### 0.2.2
|
### 0.2.2
|
||||||
|
|
||||||
|
@ -50,4 +50,9 @@ fun createSimpleScheduler(incoming: String): KronScheduler {
|
|||||||
return createKronScheduler(
|
return createKronScheduler(
|
||||||
secondsParsed, minutesParsed, hoursParsed, dayOfMonthParsed, monthParsed
|
secondsParsed, minutesParsed, hoursParsed, dayOfMonthParsed, monthParsed
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
fun buildSchedule(incoming: String): KronScheduler = createSimpleScheduler(incoming)
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.insanusmokrassar.krontab.utils
|
||||||
|
|
||||||
|
import com.insanusmokrassar.krontab.buildSchedule
|
||||||
|
import com.insanusmokrassar.krontab.builder.buildSchedule
|
||||||
|
import com.insanusmokrassar.krontab.createSimpleScheduler
|
||||||
|
import com.soywiz.klock.DateTime
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.flow.collect
|
||||||
|
import kotlinx.coroutines.flow.takeWhile
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
@ExperimentalCoroutinesApi
|
||||||
|
@FlowPreview
|
||||||
|
class StringParseTest {
|
||||||
|
@Test
|
||||||
|
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnString() {
|
||||||
|
val kronScheduler = buildSchedule("*/1 * * * *")
|
||||||
|
|
||||||
|
val flow = kronScheduler.asFlow()
|
||||||
|
|
||||||
|
runTest {
|
||||||
|
val mustBeCollected = 10
|
||||||
|
var collected = 0
|
||||||
|
flow.takeWhile {
|
||||||
|
collected < mustBeCollected
|
||||||
|
}.collect {
|
||||||
|
collected++
|
||||||
|
}
|
||||||
|
assertEquals(mustBeCollected, collected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testThatFlowIsCorrectlyWorkEverySecondWithMuchOfEmittersBuiltOnString() {
|
||||||
|
val kronScheduler = buildSchedule("*/1 * * * *")
|
||||||
|
|
||||||
|
val flow = kronScheduler.asFlow()
|
||||||
|
|
||||||
|
runTest {
|
||||||
|
val testsCount = 10
|
||||||
|
val failJob = it.createFailJob((testsCount * 2) * 1000L)
|
||||||
|
val mustBeCollected = 10
|
||||||
|
val answers = (0 until testsCount).map { _ ->
|
||||||
|
it.async {
|
||||||
|
var collected = 0
|
||||||
|
flow.takeWhile {
|
||||||
|
collected < mustBeCollected
|
||||||
|
}.collect {
|
||||||
|
collected++
|
||||||
|
}
|
||||||
|
collected
|
||||||
|
}
|
||||||
|
}.awaitAll()
|
||||||
|
|
||||||
|
failJob.cancel()
|
||||||
|
|
||||||
|
answers.forEach {
|
||||||
|
assertEquals(mustBeCollected, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user