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

add test retries #368

Merged
merged 1 commit into from
Feb 27, 2024
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
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/CustomResourceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import org.scalatest.matchers.should.Matchers
* CustomResourceSpec tests are supported for k8s versions: 1.19,1.20,1.21
*/

class CustomResourceSpec extends K8SFixture with Eventually with Matchers with Futures with BeforeAndAfterAll with ScalaFutures {
class CustomResourceSpec extends K8SFixture with Eventually with Matchers with Futures with BeforeAndAfterAll with ScalaFutures with TestRetry {
// Tagging the tests in order to exclude them in later CI k8s versions (1.22, 1.23, etc)
object CustomResourceTag extends Tag("CustomResourceTag")

Expand Down
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/CustomResourceV1Spec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import scala.concurrent.duration._
*
* @author David O'Riordan
*/
class CustomResourceV1Spec extends K8SFixture with Eventually with Matchers with ScalaFutures with BeforeAndAfterAll {
class CustomResourceV1Spec extends K8SFixture with Eventually with Matchers with ScalaFutures with BeforeAndAfterAll with TestRetry {

// Convenient aliases for the custom object and list resource types to be passed to the skuber API methods
type TestResource = CustomResource[TestResource.Spec, TestResource.Status]
Expand Down
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/DeploymentSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import scala.language.postfixOps
import scala.util.Try


class DeploymentSpec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures {
class DeploymentSpec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures with TestRetry {


val deploymentName1: String = randomUUID().toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import skuber.apps.v1.Deployment
import scala.concurrent.Future
import scala.concurrent.duration._

class DynamicKubernetesClientImplTest extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures {
class DynamicKubernetesClientImplTest extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures with TestRetry {

val deploymentName1: String = randomUUID().toString
val deploymentName2: String = randomUUID().toString
Expand Down
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/ExecSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.concurrent.duration.{Duration, _}
import scala.concurrent.{Future, Promise}


class ExecSpec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures {
class ExecSpec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures with TestRetry {
def getPodName: String = randomUUID().toString
val namespace1: String = randomUUID().toString
override implicit val patienceConfig: PatienceConfig = PatienceConfig(10.second)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import scala.concurrent.Future
import scala.concurrent.duration._
import skuber.FutureUtil.FutureOps

class HorizontalPodAutoscalerV2Beta1Spec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures {
class HorizontalPodAutoscalerV2Beta1Spec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures with TestRetry {

val horizontalPodAutoscaler1: String = randomUUID().toString
val horizontalPodAutoscaler2: String = randomUUID().toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import java.util.UUID.randomUUID
import scala.concurrent.Future
import scala.concurrent.duration._

class HorizontalPodAutoscalerV2Spec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures {
class HorizontalPodAutoscalerV2Spec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures with TestRetry {
// Tagging the tests in order to exclude them in earlier CI k8s versions (before 1.23)
object HorizontalPodAutoscalerV2Tag extends Tag("HorizontalPodAutoscalerV2Tag")

Expand Down
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/NamespaceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.concurrent.duration._
/**
* @author David O'Riordan
*/
class NamespaceSpec extends K8SFixture with Eventually with Matchers with ScalaFutures with BeforeAndAfterAll {
class NamespaceSpec extends K8SFixture with Eventually with Matchers with ScalaFutures with BeforeAndAfterAll with TestRetry {

def nginxPodName1: String = randomUUID().toString

Expand Down
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/PatchSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import scala.concurrent.Future
import scala.concurrent.duration._


class PatchSpec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures {
class PatchSpec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures with TestRetry {

val pod1: String = randomUUID().toString
val pod2: String = randomUUID().toString
Expand Down
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/PodDisruptionBudgetSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import skuber.policy.v1beta1.PodDisruptionBudget._
import scala.concurrent.Future
import scala.concurrent.duration._

class PodDisruptionBudgetSpec extends K8SFixture with Matchers with BeforeAndAfterAll with ScalaFutures with Eventually {
class PodDisruptionBudgetSpec extends K8SFixture with Matchers with BeforeAndAfterAll with ScalaFutures with Eventually with TestRetry {
behavior of "PodDisruptionBudget"
val budget1: String = randomUUID().toString
val budget2: String = randomUUID().toString
Expand Down
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/PodLogSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import skuber.Pod.LogQueryParams
import skuber.json.format._
import scala.concurrent.duration._

class PodLogSpec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures {
class PodLogSpec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures with TestRetry {
val podName: String = randomUUID().toString

override implicit val patienceConfig: PatienceConfig = PatienceConfig(10.second)
Expand Down
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/PodSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scala.concurrent.duration._
import java.util.UUID.randomUUID
import skuber.FutureUtil.FutureOps

class PodSpec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures {
class PodSpec extends K8SFixture with Eventually with Matchers with BeforeAndAfterAll with ScalaFutures with TestRetry {

val defaultLabels = Map("PodSpec" -> this.suiteName)
override implicit val patienceConfig: PatienceConfig = PatienceConfig(10.second)
Expand Down
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/ServiceAccountSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.util.Random
import LabelSelector.dsl._
import skuber.LabelSelector.IsEqualRequirement

class ServiceAccountSpec extends K8SFixture with Eventually with BeforeAndAfterAll with ScalaFutures with Matchers {
class ServiceAccountSpec extends K8SFixture with Eventually with BeforeAndAfterAll with ScalaFutures with Matchers with TestRetry {

override implicit val patienceConfig: PatienceConfig = PatienceConfig(10.second)

Expand Down
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/ServiceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.util.Random
import LabelSelector.dsl._
import skuber.LabelSelector.IsEqualRequirement

class ServiceSpec extends K8SFixture with Eventually with BeforeAndAfterAll with ScalaFutures with Matchers {
class ServiceSpec extends K8SFixture with Eventually with BeforeAndAfterAll with ScalaFutures with Matchers with TestRetry {

override implicit val patienceConfig: PatienceConfig = PatienceConfig(10.second)

Expand Down
22 changes: 22 additions & 0 deletions client/src/it/scala/skuber/TestRetry.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package skuber

import org.scalatest.{Canceled, Failed, Outcome, TestSuite}
import scala.annotation.tailrec

trait TestRetry extends TestSuite {

//override retries to modify the number of retries
val retries = 3
override def withFixture(test: NoArgTest): Outcome = {
retry(test, retries)
}

@tailrec
private def retry(test: NoArgTest, count: Int): Outcome = {
val outcome = super.withFixture(test)
outcome match {
case Failed(_) | Canceled(_) => if (count == 1) super.withFixture(test) else retry(test, count - 1)
case other => other
}
}
}
2 changes: 1 addition & 1 deletion client/src/it/scala/skuber/WatchContinuouslySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import scala.concurrent.Future
import scala.concurrent.duration._
import scala.language.postfixOps

class WatchContinuouslySpec extends K8SFixture with Eventually with Matchers with ScalaFutures with BeforeAndAfterAll {
class WatchContinuouslySpec extends K8SFixture with Eventually with Matchers with ScalaFutures with BeforeAndAfterAll with TestRetry {
implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = Span(200, Seconds), interval = Span(5, Seconds))

behavior of "WatchContinuously"
Expand Down
Loading