-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Don't crash on null test executions * Use 60s timeout on requests by default * Add executeWithRetry * Add ftl.http package * Use TimeoutHttpRequestInitializer in mock code path
- Loading branch information
1 parent
cba181e
commit 86a530f
Showing
8 changed files
with
61 additions
and
17 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
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,21 @@ | ||
package ftl.http | ||
|
||
import com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest | ||
import java.io.IOException | ||
|
||
// Only use on calls that don't change state. | ||
// Fetching status is safe to retry on timeout. Creating a matrix is not. | ||
fun <T> AbstractGoogleJsonClientRequest<T>.executeWithRetry(): T { | ||
var lastErr: IOException? = null | ||
|
||
for (i in 1..10) { | ||
try { | ||
return this.execute() | ||
} catch (err: IOException) { | ||
lastErr = err | ||
System.err.println("Request failed, retrying ${i}x $err") | ||
} | ||
} | ||
|
||
throw IOException("Request failed", lastErr) | ||
} |
14 changes: 14 additions & 0 deletions
14
test_runner/src/main/kotlin/ftl/http/TimeoutHttpRequestInitializer.kt
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,14 @@ | ||
package ftl.http | ||
|
||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential | ||
import com.google.api.client.http.HttpRequest | ||
import com.google.api.client.http.HttpRequestInitializer | ||
|
||
class TimeoutHttpRequestInitializer(private val googleCredential: GoogleCredential) : HttpRequestInitializer { | ||
override fun initialize(request: HttpRequest?) { | ||
googleCredential.initialize(request) | ||
// timeout in milliseconds. wait 60s instead of default 20s | ||
request?.connectTimeout = 60 * 1000 | ||
request?.readTimeout = 60 * 1000 | ||
} | ||
} |
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