How to use next method of io.kotest.assertions.until.Interval class

Best Kotest code snippet using io.kotest.assertions.until.Interval.next

eventually.kt

Source:eventually.kt Github

copy

Full Screen

...104 throw e105 }106 }107 times++108 lastInterval = config.interval.next(times)109 val delayMark = TimeSource.Monotonic.markNow()110 delay(lastInterval)111 lastDelayPeriod = delayMark.elapsedNow()112 }113 errorCollector.setCollectionMode(originalAssertionMode)114 val message = StringBuilder().apply {115 appendLine("Eventually block failed after ${config.duration}; attempted $times time(s); ${config.interval} delay between attempts")116 if (predicateFailedTimes > 0) {117 appendLine("The provided predicate failed $predicateFailedTimes times")118 }119 if (firstError != null) {120 appendLine("The first error was caused by: ${firstError.message}")121 appendLine(firstError.stackTraceToString())122 }...

Full Screen

Full Screen

InventoryConsumerTest.kt

Source:InventoryConsumerTest.kt Github

copy

Full Screen

1package org.learning.demo.app.consumer2import io.kotest.assertions.timing.EventuallyConfig3import io.kotest.assertions.timing.continually4import io.kotest.assertions.timing.eventually5import io.kotest.assertions.until.FixedInterval6import io.kotest.assertions.until.fixed7import io.kotest.matchers.shouldBe8import kotlinx.coroutines.runBlocking9import org.junit.jupiter.api.BeforeEach10import org.junit.jupiter.api.Test11import org.learning.demo.IntegrationTest12import org.learning.demo.app.repository.InventoryProduct13import org.learning.demo.app.repository.ProductRepository14import org.learning.demo.lib.kafka.KafkaMessage15import org.learning.demo.lib.kafka.producer.KafkaProducer16import org.learning.demo.lib.kafka.repository.ProcessedMessageAudit17import org.learning.demo.lib.kafka.repository.ProcessedMessageAuditRepository18import org.learning.demo.util.assertNextWith19import org.springframework.beans.factory.annotation.Autowired20import java.time.LocalDateTime21import kotlin.time.Duration.Companion.seconds22import kotlin.time.DurationUnit23import kotlin.time.toDuration24@IntegrationTest25class InventoryConsumerTest(26 @Autowired private val kafkaProducer: KafkaProducer,27 @Autowired private val productRepository: ProductRepository,28 @Autowired private val processedMessageAuditRepository: ProcessedMessageAuditRepository,29) {30 @BeforeEach31 fun setUp() {32 processedMessageAuditRepository.deleteAll().block()33 }34 @Test35 fun `should update count of remain products on consuming order created event`() {36 productRepository.saveAll(37 listOf(38 InventoryProduct("P-001", 20),39 InventoryProduct("P-002", 12),40 InventoryProduct("P-003", 12),41 )42 ).blockLast()43 kafkaProducer.produce(44 "order",45 KafkaMessage(46 eventId = "ev-00-11",47 eventName = "order-created",48 createdTime = "2020-01-01",49 partitionKey = "123",50 identifiers = mapOf(),51 payload = mapOf(52 "orderId" to "001",53 "totalPrice" to 234.56,54 "products" to setOf(55 mapOf(56 "productCode" to "P-001",57 "quantity" to 12,58 "price" to 345.3259 ),60 mapOf(61 "productCode" to "P-002",62 "quantity" to 12,63 "price" to 345.3264 ),65 )66 )67 )68 ).block()69 runBlocking {70 eventually(71 EventuallyConfig(72 duration = 5.toDuration(DurationUnit.SECONDS),73 interval = FixedInterval(100.toDuration(DurationUnit.MILLISECONDS))74 )75 ) {76 assertNextWith(productRepository.findByProductCode("P-001")) {77 it.remainingQuantity shouldBe 878 }79 assertNextWith(productRepository.findByProductCode("P-002")) {80 it.remainingQuantity shouldBe 081 }82 assertNextWith(productRepository.findByProductCode("P-003")) {83 it.remainingQuantity shouldBe 1284 }85 }86 }87 }88 @Test89 fun `should not process duplicate message`() {90 processedMessageAuditRepository.save(91 ProcessedMessageAudit(92 eventId = "001_order-created",93 processedAt = LocalDateTime.now(),94 consumerGroupId = "inventory-consumer-group"95 )96 ).block()97 productRepository.saveAll(98 listOf(99 InventoryProduct("P-001", 20),100 InventoryProduct("P-002", 12),101 InventoryProduct("P-003", 12),102 )103 ).blockLast()104 kafkaProducer.produce(105 "order",106 KafkaMessage(107 eventId = "ev-00-11",108 eventName = "order-created",109 createdTime = "2020-01-01",110 partitionKey = "123",111 identifiers = mapOf(),112 payload = mapOf(113 "orderId" to "001",114 "totalPrice" to 234.56,115 "products" to setOf(116 mapOf(117 "productCode" to "P-001",118 "quantity" to 12,119 "price" to 345.32120 ),121 mapOf(122 "productCode" to "P-002",123 "quantity" to 12,124 "price" to 345.32125 ),126 )127 )128 )129 ).block()130 runBlocking {131 continually(5.seconds, 1.seconds.fixed()) {132 assertNextWith(productRepository.findByProductCode("P-001")) {133 it.remainingQuantity shouldBe 20134 }135 assertNextWith(productRepository.findByProductCode("P-002")) {136 it.remainingQuantity shouldBe 12137 }138 assertNextWith(productRepository.findByProductCode("P-003")) {139 it.remainingQuantity shouldBe 12140 }141 }142 }143 }144}...

Full Screen

Full Screen

KafkaConsumerTest.kt

Source:KafkaConsumerTest.kt Github

copy

Full Screen

1package org.learning.demo.lib.kafka.consumer2import io.kotest.assertions.timing.EventuallyConfig3import io.kotest.assertions.timing.eventually4import io.kotest.assertions.until.FixedInterval5import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder6import io.kotest.matchers.collections.shouldHaveSize7import kotlinx.coroutines.runBlocking8import org.junit.jupiter.api.BeforeEach9import org.junit.jupiter.api.Test10import org.learning.demo.IntegrationTest11import org.learning.demo.lib.kafka.KafkaMessage12import org.learning.demo.lib.kafka.producer.KafkaProducer13import org.learning.demo.lib.kafka.repository.ProcessedMessageAudit14import org.learning.demo.lib.kafka.repository.ProcessedMessageAuditRepository15import org.learning.demo.util.assertNextWith16import org.springframework.beans.factory.annotation.Autowired17import java.time.LocalDateTime18import kotlin.time.DurationUnit19import kotlin.time.toDuration20@IntegrationTest21class KafkaConsumerTest(22 @Autowired private val kafkaProducer: KafkaProducer,23 @Autowired private val dummyKafkaConsumer: DummyKafkaConsumer,24 @Autowired private val processedMessageAuditRepository: ProcessedMessageAuditRepository,25) {26 @BeforeEach27 fun setUp() {28 processedMessageAuditRepository.deleteAll().block()29 }30 private val message = KafkaMessage(31 eventId = "EB-001",32 eventName = "consumer-event",33 createdTime = "2020-01-01",34 partitionKey = "12",35 identifiers = mapOf(36 "key1" to "val1"37 ),38 payload = mapOf(39 "message" to "hello"40 )41 )42 @Test43 fun `should consume new message only`() {44 processedMessageAuditRepository.save(45 ProcessedMessageAudit(46 eventId = "EB-000",47 processedAt = LocalDateTime.now(),48 consumerGroupId = "kafka-tryout-consumer-group"49 )50 ).block()51 kafkaProducer52 .produce(topic = "integration-test", message = message)53 .flatMap {54 kafkaProducer.produce(topic = "integration-test-v2", message.copy(eventId = "EB-000"))55 }56 .flatMap {57 kafkaProducer.produce(topic = "integration-test-v2", message.copy(eventId = "EB-002"))58 }59 .block()60 runBlocking {61 eventually(62 EventuallyConfig(63 duration = 10.toDuration(DurationUnit.SECONDS),64 interval = FixedInterval(1.toDuration(DurationUnit.SECONDS))65 )66 ) {67 val messages = dummyKafkaConsumer.getAllMessages()68 messages shouldHaveSize 269 messages shouldContainExactlyInAnyOrder listOf(70 Triple("integration-test", emptyMap(), message),71 Triple("integration-test-v2", emptyMap(), message.copy(eventId = "EB-002")),72 )73 }74 }75 }76 @Test77 fun `should save audit of processed message`() {78 processedMessageAuditRepository.save(79 ProcessedMessageAudit(80 eventId = "EB-000",81 processedAt = LocalDateTime.now(),82 consumerGroupId = "kafka-tryout-consumer-group"83 )84 ).block()85 kafkaProducer86 .produce(topic = "integration-test", message = message)87 .flatMap {88 kafkaProducer.produce(topic = "integration-test-v2", message.copy(eventId = "EB-002"))89 }90 .block()91 runBlocking {92 eventually(93 EventuallyConfig(94 duration = 10.toDuration(DurationUnit.SECONDS),95 interval = FixedInterval(1.toDuration(DurationUnit.SECONDS))96 )97 ) {98 assertNextWith(processedMessageAuditRepository.findAll().collectList()) {99 it.map { r -> r.eventId } shouldContainExactlyInAnyOrder listOf("EB-000", "EB-001", "EB-002")100 }101 }102 }103 }104}...

Full Screen

Full Screen

ExponentialIntervalTest.kt

Source:ExponentialIntervalTest.kt Github

copy

Full Screen

...12import kotlin.time.Duration.Companion.milliseconds13import kotlin.time.Duration.Companion.seconds14class ExponentialIntervalTest : FunSpec() {15 init {16 test("exponential interval should have a reasonable default next") {17 val identity = 2.seconds18 assertSoftly(identity.exponential()) {19 next(0) shouldBe identity * 120 next(1) shouldBe identity * 221 next(2) shouldBe identity * 422 }23 assertSoftly(identity.exponential(factor = 3.0)) {24 next(0) shouldBe identity * 125 next(1) shouldBe identity * 326 next(2) shouldBe identity * 927 }28 }29 test("exponential interval should have a reasonable default max") {30 val max = ExponentialInterval.defaultMax31 val default = 25.milliseconds.exponential()32 val unbounded = 25.milliseconds.exponential(max = null)33 val first = 034 val last = 2035 unbounded.next(first) shouldBeLessThan max36 unbounded.next(last) shouldBeGreaterThan max37 for (i in first..last) {38 val u = unbounded.next(i)39 val d = default.next(i)40 if (u < max) {41 d shouldBe u42 } else {43 d shouldBe max44 u shouldBeGreaterThan max45 }46 }47 }48 test("exponential interval should respect user specified max") {49 val base = 25.milliseconds50 val n = 551 val max = base * ExponentialInterval.defaultFactor.pow(n)52 val bounded = base.exponential(max = max)53 val unbounded = base.exponential(max = null)54 val first = 055 val last = 2056 unbounded.next(first) shouldBeLessThan max57 unbounded.next(last) shouldBeGreaterThan max58 for (i in first..last) {59 val u = unbounded.next(i)60 val b = bounded.next(i)61 if (u < max) {62 b shouldBe u63 i shouldBeLessThan n64 } else {65 i shouldBeGreaterThanOrEqualTo n66 b shouldBe max67 u shouldBeGreaterThanOrEqualTo max68 }69 }70 }71 }72}...

Full Screen

Full Screen

continually.kt

Source:continually.kt Github

copy

Full Screen

...38 e39 )40 }41 times++42 delay(interval.next(times))43 }44 return result45 }46}47@Deprecated("Use continually with an interval, using Duration based poll is deprecated",48 ReplaceWith("continually(duration, poll.fixed(), f = f)", "io.kotest.assertions.until.fixed")49)50suspend fun <T> continually(duration: Duration, poll: Duration, f: suspend () -> T) =51 continually(duration, poll.fixed(), f = f)52suspend fun <T> continually(duration: Duration, interval: Interval = Duration.milliseconds(10).fixed(), f: suspend () -> T) =53 Continually<T>(duration, interval).invoke(f)...

Full Screen

Full Screen

OrderServiceIntegrationTest.kt

Source:OrderServiceIntegrationTest.kt Github

copy

Full Screen

1package org.learning.demo.app.service2import io.kotest.assertions.timing.EventuallyConfig3import io.kotest.assertions.timing.eventually4import io.kotest.assertions.until.FixedInterval5import io.kotest.matchers.collections.shouldHaveSize6import io.kotest.matchers.maps.shouldContainAll7import kotlinx.coroutines.runBlocking8import org.junit.jupiter.api.BeforeEach9import org.junit.jupiter.api.Test10import org.learning.demo.IntegrationTest11import org.learning.demo.app.domain.Product12import org.learning.demo.app.view.CartView13import org.learning.demo.util.EmbeddedKafkaConsumer14import org.springframework.beans.factory.annotation.Autowired15import java.math.BigDecimal16import kotlin.time.DurationUnit17import kotlin.time.toDuration18@IntegrationTest19class OrderServiceIntegrationTest(20 @Autowired private val orderService: OrderService,21 @Autowired private val embeddedKafkaConsumer: EmbeddedKafkaConsumer22) {23 @BeforeEach24 fun setUp() {25 embeddedKafkaConsumer.clearTopic("order")26 }27 @Test28 fun `should raise order created event on order creation`() {29 val product = Product(productCode = "P-0022", quantity = 3, price = BigDecimal("20.34"))30 orderService.createOrderFrom(CartView(id = "C-002", products = setOf(product))).block()31 runBlocking {32 eventually(33 EventuallyConfig(34 duration = 5.toDuration(DurationUnit.SECONDS),35 interval = FixedInterval(1.toDuration(DurationUnit.SECONDS))36 )37 ) {38 val messages = embeddedKafkaConsumer.readNextMessage("order", "order-created")39 messages shouldHaveSize 140 messages.first().payload shouldContainAll mapOf(41 "products" to listOf(42 mapOf(43 "productCode" to "P-0022",44 "quantity" to 3,45 "price" to 20.34,46 )47 ),48 "totalPrice" to 61.02,49 "eventName" to "order-created"50 )51 }52 }53 }54}...

Full Screen

Full Screen

FibonacciIntervalTest.kt

Source:FibonacciIntervalTest.kt Github

copy

Full Screen

...23 val default = 10.minutes.fibonacci()24 val unbounded = 10.minutes.fibonacci(null)25 val first = 026 val last = 2027 unbounded.next(first) shouldBeLessThan max28 unbounded.next(last) shouldBeGreaterThan max29 for (i in first..last) {30 val u = unbounded.next(i)31 val d = default.next(i)32 if (u < max) {33 d shouldBe u34 } else {35 d shouldBe max36 u shouldBeGreaterThan max37 }38 }39 }40 test("fibonacci interval should respect user specified max") {41 val max = FibonacciInterval.defaultMax.plus(15.minutes)42 val bounded = 10.minutes.fibonacci(max)43 val unbounded = 10.minutes.fibonacci(null)44 val first = 045 val last = 2046 unbounded.next(first) shouldBeLessThan max47 unbounded.next(last) shouldBeGreaterThan max48 for (i in first..last) {49 val u = unbounded.next(i)50 val b = bounded.next(i)51 if (u < max) {52 b shouldBe u53 } else {54 b shouldBe max55 u shouldBeGreaterThan max56 }57 }58 }59 }60}...

Full Screen

Full Screen

Interval.kt

Source:Interval.kt Github

copy

Full Screen

...4 * A [Interval] determines how often Kotest will invoke the predicate function for an [until] block.5 */6interface Interval {7 /**8 * Returns the next delay as a [Duration].9 *10 * @param count The number of times the condition has been polled (evaluated) so far.11 * Always a positive integer.12 *13 * @return The duration of the next poll interval14 */15 fun next(count: Int): Duration16}...

Full Screen

Full Screen

next

Using AI Code Generation

copy

Full Screen

1val interval = Interval(100, 1000)2val interval = Interval(100, 1000)3val interval = Interval(100, 1000)4val interval = Interval(100, 1000)5val interval = Interval(100, 1000)6val interval = Interval(100, 1000)7val interval = Interval(100, 1000)8val interval = Interval(100, 1000)9val interval = Interval(100, 1000)10val interval = Interval(100, 1000)11val interval = Interval(100, 1000)12val interval = Interval(100, 1000)13val interval = Interval(100, 1000)

Full Screen

Full Screen

next

Using AI Code Generation

copy

Full Screen

1val interval = io.kotest.assertions.until.Interval(100, 5000)2val result = io.kotest.assertions.until.until(interval) {3}4val result = io.kotest.assertions.until.until(io.kotest.assertions.until.Interval(100, 5000)) {5}6val result = io.kotest.assertions.until.until(100, 5000) {7}8val result = io.kotest.assertions.until.until(100, 5000, 1000) {9}10val result = io.kotest.assertions.until.until(5000) {11}12val result = io.kotest.assertions.until.until(1000) {13}14val result = io.kotest.assertions.until.until(100) {15}16val result = io.kotest.assertions.until.until(100, 5000) {17}18val result = io.kotest.assertions.until.until(100, 5000, 1000) {19}20val result = io.kotest.assertions.until.until(100, 5000, 1000, 100) {21}22val result = io.kotest.assertions.until.until(100, 5000, 1000, 100, 1000) {23}

Full Screen

Full Screen

next

Using AI Code Generation

copy

Full Screen

1val interval = Interval(100, 1000)2val result = interval.until("Hello") {3}4println(result)5val interval = Interval(100, 1000)6val result = interval.until(1) {7}8println(result)9val interval = Interval(100, 1000)10val result = interval.until(1) {11}12println(result)13val interval = Interval(100, 1000)14val result = interval.until(1) {15}16println(result)17val interval = Interval(100, 1000)18val result = interval.until(1) {19}20println(result)21val interval = Interval(100, 1000)22val result = interval.until(1) {23}24println(result)25val interval = Interval(100, 1000)26val result = interval.until(1) {27}28println(result)29val interval = Interval(100, 1000)30val result = interval.until(1) {31}32println(result)33val interval = Interval(100, 1000)34val result = interval.until(1) {35}36println(result)37val interval = Interval(100, 1000)38val result = interval.until(1) {39}40println(result)41val interval = Interval(100, 1000)42val result = interval.until(1) {43}44println(result)

Full Screen

Full Screen

next

Using AI Code Generation

copy

Full Screen

1val interval = Interval(100, DurationUnit.MILLISECONDS)2val isTrue = until(interval) { condition }3val isFalse = until(interval) { !condition }4val isTrue = until(interval) { condition }5val isFalse = until(interval) { !condition }6val interval = Interval(100, DurationUnit.MILLISECONDS)7val isTrue = until(interval) { condition }8val isFalse = until(interval) { !condition }9val isTrue = until(interval) { condition }10val isFalse = until(interval) { !condition }11val interval = Interval(100, DurationUnit.MILLISECONDS)12val isTrue = until(interval) { condition }13val isFalse = until(interval) { !condition }14val interval = Interval(100, DurationUnit.MILLISECONDS)15val isTrue = until(interval) { condition }16val isFalse = until(interval) { !condition }17val interval = Interval(100, DurationUnit.MILLISECONDS)18val isTrue = until(interval) { condition }19val isFalse = until(interval) { !condition }20val interval = Interval(100, DurationUnit.MILLISECONDS)21val isTrue = until(interval) { condition }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Interval

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful