Skip to content

Commit

Permalink
add file lock test
Browse files Browse the repository at this point in the history
Signed-off-by: imanushin <[email protected]>
  • Loading branch information
imanushin committed Dec 11, 2023
1 parent cb858c4 commit 319fc43
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ spekDsl = { module = "org.spekframework.spek2:spek-dsl-jvm", version.ref = "spek
spekRunner = { module = "org.spekframework.spek2:spek-runner-junit5", version.ref = "spek" }
junitEngine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junit = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
coroutinesCore = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version = "1.7.3" }


[plugins]
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.23.0" }
Expand Down
1 change: 1 addition & 0 deletions helm-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {

testImplementation(libs.okHttpMockWebServer)

testImplementation(libs.coroutinesCore)
testImplementation(libs.unbrokenDomeTestUtils)
testImplementation(libs.bundles.defaultTests)
testRuntimeOnly(libs.junitEngine)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.citi.gradle.plugins.helm.util

import io.kotest.matchers.equals.shouldBeEqual
import java.io.File
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir

internal class FileLockTest {
@TempDir
private lateinit var tempFolder: File

private lateinit var fileToLock: File

@BeforeEach
fun setup() {
tempFolder.mkdirs()
fileToLock = File(tempFolder, "text.txt")
fileToLock.createNewFile()
}

@Test
@Disabled
fun twoFunctionsArentAbleToUpdateFile() {
runBlocking {
val thread2IsReady = CompletableDeferred<Unit>()

val taskIndices = 0..99

val parallelTasks = taskIndices.map { taskIndex ->
async {
withLockFile(fileToLock) {
// don't start until all tasks have been created
runBlocking {
thread2IsReady.await()
}

taskIndex
}
}
}

thread2IsReady.complete(Unit)

val taskResults = parallelTasks.awaitAll().toSet()

taskResults shouldBeEqual taskIndices.toSet()
}
}
}

0 comments on commit 319fc43

Please sign in to comment.