Skip to content

Commit

Permalink
Wrap flaky test in a retry (#5095)
Browse files Browse the repository at this point in the history
* Wrap flaky test in a retry to prevent R test test-model-mleap.R from erroring due to port unavailability

Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
  • Loading branch information
BenWilson2 committed Nov 24, 2021
1 parent d79a816 commit 94db108
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion mlflow/R/mlflow/tests/testthat/test-model-mleap.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,30 @@ context("Model mleap")

library(mleap)

sc <- sparklyr::spark_connect(master = "local", version = "2.4.5")
for (i in 0:4){
tryCatch(
expr = {
config <- sparklyr::spark_config()
config$sparklyr.gateway.port <- httpuv::randomPort()
sc <- sparklyr::spark_connect(master = "local", version = "2.4.5", config=config)
},
error = function(e){
if (i == 4){
stop("Exhausted retries in getting SparkContext. Aborting.")
}
message("An error occured while getting a SparkContext:")
print(e)
sleep_duration = (2 * i) + 1
message(sprintf("\nSleeping for %s seconds and retrying...", sleep_duration))
Sys.sleep(sleep_duration)
},
warning = function(w){
message("A warning occurred:")
print(w)
}
)
}

testthat_model_dir <- basename(tempfile("model_"))

teardown({
Expand Down

0 comments on commit 94db108

Please sign in to comment.