You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
If two different test classes take a snapshot with the same sha, and "maxParallelForks" is set so that the tests can run in parallel, it is possible to encounter a race condition where the image does not exist at the end of the test.
Steps to Reproduce
This copies the writeAtomically function from HtmlReportWriter and shows how using it to write a string to a file reproduces the issue. If you run this, occasionally it will print "false", indicating that the expected file does not exist.
fun main(): Unit = runBlocking(Dispatchers.IO) {
val file = File("test.txt")
(1..1000).map {
async {
file.writeAtomically("Hello, World!")
}
}.awaitAll()
println(file.exists())
}
private fun File.writeAtomically(msg: String) {
val tmpFile = File(parentFile, "$name.tmp")
tmpFile.writeText(msg)
delete()
tmpFile.renameTo(this)
}
Expected behavior
Tests can safely be run in parallel, and produce the correct image file output.
I believe this can be fixed by changing val tmpFile = File(parentFile, "$name.tmp") to val tmpFile = File(parentFile, "$name-${UUID.randomUUID()}.tmp") so that the tmp files do not collide
The text was updated successfully, but these errors were encountered:
Description
If two different test classes take a snapshot with the same sha, and "maxParallelForks" is set so that the tests can run in parallel, it is possible to encounter a race condition where the image does not exist at the end of the test.
Steps to Reproduce
This copies the
writeAtomically
function from HtmlReportWriter and shows how using it to write a string to a file reproduces the issue. If you run this, occasionally it will print "false", indicating that the expected file does not exist.Expected behavior
Tests can safely be run in parallel, and produce the correct image file output.
I believe this can be fixed by changing
val tmpFile = File(parentFile, "$name.tmp")
toval tmpFile = File(parentFile, "$name-${UUID.randomUUID()}.tmp")
so that the tmp files do not collideThe text was updated successfully, but these errors were encountered: