Skip to content

Commit

Permalink
Fix critical bug with default timeouts in 'startProcess' and 'startCo…
Browse files Browse the repository at this point in the history
…mmand'
  • Loading branch information
kochetkovma committed Nov 26, 2020
1 parent a76dba9 commit 12e7f18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/ru/iopump/koproc/extension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var koprocDefaultStartCommandTimeoutSec = 10L
*
* @return [KoprocCall]
*/
fun String.startProcess(config: KoprocConfig.() -> Unit = { KoprocConfig(koprocDefaultStartProcessTimeoutSec) }): KoprocCall {
fun String.startProcess(config: KoprocConfig.() -> Unit = { timeoutSec = koprocDefaultStartProcessTimeoutSec }): KoprocCall {
val cfg = KoprocConfig().apply(config)

val processBuilder = ProcessBuilder(*this.split.toTypedArray())
Expand All @@ -42,7 +42,7 @@ fun String.startProcess(config: KoprocConfig.() -> Unit = { KoprocConfig(koprocD
*
* @return [KoprocResult]
*/
fun String.startCommand(config: KoprocConfig.() -> Unit = { KoprocConfig(koprocDefaultStartCommandTimeoutSec) }): KoprocResult =
fun String.startCommand(config: KoprocConfig.() -> Unit = { timeoutSec = koprocDefaultStartCommandTimeoutSec }): KoprocResult =
this.startProcess(config).result

private val String.split
Expand Down
9 changes: 9 additions & 0 deletions src/test/kotlin/ru/iopump/koproc/ExtensionKtIT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,14 @@ class ExtensionKtIT : StringSpec() {
it.throwOnAnyFailure()
}
}

"Default timeout [bug in 1.1.0]" {
koprocDefaultStartCommandTimeoutSec = 1
val jarPath = Paths.get(this::class.java.getResource("/koproc-sample.jar").toURI())
"java -jar $jarPath".startCommand()

koprocDefaultStartProcessTimeoutSec = 1
"java -jar $jarPath".startProcess().result
}
}
}

0 comments on commit 12e7f18

Please sign in to comment.