'Test case is failing after upgrading the spring boot version from 2.1.x to 2.6.x

Test case is failing with following Exception : after upgrading the Springboot version from 2.1.x to 2.6.x

org.awaitility.core.ConditionTimeoutException: Condition with lambda expression in com.timer.Relax that uses kotlin.jvm.functions.Function0 was not fulfilled within 20 seconds.
at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:165)
at org.awaitility.core.CallableCondition.await(CallableCondition.java:78)
at org.awaitility.core.CallableCondition.await(CallableCondition.java:26)
at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:895)
at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:864)
at com.timer.Relax.until(Relax.kt:14)

code snipet:

object Relax {
  private const val INCLUSION_TIMEOUT = 20L

  fun until(runnable: () -> Unit) {
    await()
        .pollInterval(1, TimeUnit.SECONDS)
        .atMost(INCLUSION_TIMEOUT, TimeUnit.SECONDS)
        .until(callable(runnable))
  }

  private fun callable(runnable: () -> Unit): Callable<Boolean> {
    return Callable {
      try {
        runnable.invoke()
        true
      } catch (throwable: Throwable) {
        false
      }
    }
  }
}


Solution 1:[1]

You code works for me as expected:

class SO72046468 {

    @Test
    fun `verify awaitility good`() {
        Relax.until { println("Hi Jimmy!") }
    }

    @Test
    fun `verify awaitility bad`() {
        Relax.until { throw RuntimeException("intentional") }
    }

    object Relax {

        private const val INCLUSION_TIMEOUT = 3L

        fun until(runnable: () -> Unit) {
            await()
                .pollInterval(1, TimeUnit.SECONDS)
                .atMost(INCLUSION_TIMEOUT, TimeUnit.SECONDS)
                .until(callable(runnable))
        }

        private fun callable(runnable: () -> Unit): Callable<Boolean> {
            return Callable {
                try {
                    runnable.invoke()
                    true
                } catch (throwable: Throwable) {
                    false
                }
            }
        }
    }

}

Kotlin 1.6.10 and Awaitility 4.2.0. And yes: JUnit 5.8.2.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Artem Bilan