Resets the connection (and sets partial download to false) if the range is not satisfiable by the server (#795)

This commit is contained in:
Ruben Berenguel
2018-03-12 11:19:57 +01:00
committed by Alexandre Archambault
parent a7605ff900
commit cf365ea27a
2 changed files with 29 additions and 1 deletions
@@ -867,4 +867,30 @@ class CliFetchIntegrationTest extends FlatSpec with CliTestLib {
}
}
"Wrong range partial artifact resolve" should "succeed with retry" in withTempDir("tmp_dir") {
dir => {
def runFetchJunit = {
val fetchOpt = FetchOptions(common = CommonOptions(mode = "force", cacheOptions = CacheOptions(cache = dir.getAbsolutePath)))
val fetch = Fetch(fetchOpt, RemainingArgs(Seq("junit:junit:4.6"), Seq()))
assert(fetch.files0.map(_.getName).toSet
.equals(Set("junit-4.6.jar")))
val junitJarPath = fetch.files0.map(_.getAbsolutePath()).filter(_.contains("junit-4.6.jar"))
.head
val junitJarFile = new File(junitJarPath)
junitJarFile
}
val originalJunitJar: File = runFetchJunit
val originalJunitJarContent = FileUtil.readAllBytes(originalJunitJar)
// Move the jar to partial (but complete) download
val newJunitJar: File = new File(originalJunitJar.getAbsolutePath + ".part")
originalJunitJar.renameTo(newJunitJar)
// Run fetch again and it should pass because of retrying on the partial jar.
val jar = runFetchJunit
assert(FileUtil.readAllBytes(jar).sameElements(originalJunitJarContent))
}
}
}