Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Synchronize on target instead of origin when copying #2552

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/src/main/scala/bloop/io/ParallelOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ object ParallelOps {
}
}
} finally {
takenByOtherCopyProcess.remove(originFile)
takenByOtherCopyProcess.remove(targetFile)
// Complete successfully to unblock other tasks
p.success(())
}
Expand All @@ -223,7 +223,7 @@ object ParallelOps {

def acquireFile: MonixTask[Unit] = {
val currentPromise = Promise[Unit]()
val promiseInMap = takenByOtherCopyProcess.putIfAbsent(originFile, currentPromise)
val promiseInMap = takenByOtherCopyProcess.putIfAbsent(targetFile, currentPromise)
if (promiseInMap == null) {
triggerCopy(currentPromise)
} else {
Expand Down
73 changes: 73 additions & 0 deletions backend/src/test/scala/bloop/io/ParallelOpsSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package bloop.io

import java.nio.file.Files
import bloop.io.ParallelOps.CopyMode
import org.junit.Test
import bloop.logging.RecordingLogger
import bloop.task.Task
import monix.execution.Scheduler
import java.nio.file.StandardOpenOption
import scala.concurrent.duration._
import scala.concurrent.Await

class ParallelOpsSuite {

private def createRandomDirectory() = {

val from = Files.createTempDirectory("parallel")
val inputFile = from.resolve("text.scala")
val text = "random\n" * 100
Files.write(inputFile, text.getBytes, StandardOpenOption.CREATE, StandardOpenOption.APPEND)
}
@Test
def runMultipleCopies() = {

val from = createRandomDirectory()
val to = Files.createTempDirectory("parallel")

val config =
ParallelOps.CopyConfiguration(5, CopyMode.ReplaceExisting, Set.empty, Set.empty)
val logger = new RecordingLogger()

val tasks =
for (_ <- 0 to 100)
yield ParallelOps
.copyDirectories(config)(
from,
to,
Scheduler.Implicits.global,
enableCancellation = false,
logger
)

val result = Task.gatherUnordered(tasks).runAsync(Scheduler.Implicits.global)
val res = Await.result(result, 15.seconds)
assert(res.size == 101)
}

@Test
def runMultipleCopiesFromDifferentSource() = {

val to = Files.createTempDirectory("parallel")

val config =
ParallelOps.CopyConfiguration(100, CopyMode.ReplaceExisting, Set.empty, Set.empty)
val logger = new RecordingLogger()

val tasks =
for (_ <- 0 to 100)
yield ParallelOps
.copyDirectories(config)(
createRandomDirectory(),
to,
Scheduler.Implicits.global,
enableCancellation = false,
logger
)

val result = Task.gatherUnordered(tasks).runAsync(Scheduler.Implicits.global)
val res = Await.result(result, 15.seconds)
assert(res.size == 101)
}

}
Loading