-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make staging repository operations retry on failure (#17)
* Make staging repository operations retry on failure * Minimize diff * Keep the former HttpClientUtil.create signature So that it still throws when something goes wrong, and users aren't surprised with the new behavior of createResponse * Increase duration between attempts via exponential smoothing * Fix package name * fixup Increase duration between attempts via exponential smoothing * fixup Fix package name --------- Co-authored-by: Alexandre Archambault <alexandre.archambault@gmail.com>
- Loading branch information
1 parent
8a69105
commit 0c9373d
Showing
4 changed files
with
114 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package coursier.publish.util | ||
|
||
import scala.math.Numeric.Implicits | ||
|
||
final case class EmaRetryParams( | ||
attempts: Int, | ||
initialWaitDurationMs: Long, | ||
factor: Float | ||
) { | ||
def update(value: Long): Long = | ||
math.ceil(value * factor.toDouble).toLong | ||
} |
63 changes: 63 additions & 0 deletions
63
publish/test/src/coursier/publish/sonatype/SonatypeTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package coursier.publish.sonatype | ||
|
||
import coursier.publish.util.EmaRetryParams | ||
import sttp.client3.testing.SttpBackendStub | ||
|
||
import utest._ | ||
|
||
object SonatypeTests extends TestSuite { | ||
val tests = Tests { | ||
test("Retry sonatype repository actions") { | ||
var count = 0 | ||
val mockBackend = SttpBackendStub.synchronous | ||
.whenRequestMatches { _ => count += 1; count < 6 } | ||
.thenRespondServerError() | ||
.whenRequestMatches(_ => count >= 6) | ||
.thenRespondOk() | ||
|
||
{ | ||
val sonatypeApi20 = SonatypeApi( | ||
mockBackend, | ||
base = "https://oss.sonatype.org", | ||
authentication = None, | ||
verbosity = 0, | ||
retryOnTimeout = 1, | ||
stagingRepoRetryParams = EmaRetryParams(20, 100L, 1.0f) | ||
) | ||
|
||
sonatypeApi20.sendPromoteStagingRepositoryRequest( | ||
SonatypeApi.Profile("id", "name", "uri"), | ||
"repo", | ||
"description" | ||
) | ||
|
||
assert(count == 6) | ||
} | ||
|
||
count = 0 | ||
|
||
{ | ||
val sonatypeApi3 = SonatypeApi( | ||
mockBackend, | ||
base = "https://oss.sonatype.org", | ||
authentication = None, | ||
verbosity = 0, | ||
retryOnTimeout = 1 | ||
) | ||
|
||
try sonatypeApi3.sendPromoteStagingRepositoryRequest( | ||
SonatypeApi.Profile("id", "name", "uri"), | ||
"repo", | ||
"description" | ||
) | ||
catch { | ||
case e: Exception | ||
if e.getMessage == "Failed to get uri/promote (http status: 500, response: Internal server error)" => | ||
case _: Throwable => assert(false) | ||
} | ||
|
||
assert(count == 3) | ||
} | ||
} | ||
} | ||
} |