libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 81121eacf6f30d7f97a226a4b9e19238e31f5ef5
parent a2900c23ce84e549ef84fe70670234c62931108b
Author: Antoine A <>
Date:   Fri,  6 Oct 2023 09:39:11 +0000

Improve timing tests for /taler-wire-gateway/history

Diffstat:
Mbank/src/main/kotlin/tech/libeufin/bank/Database.kt | 3+++
Mbank/src/test/kotlin/TalerApiTest.kt | 36++++++++++++++++++++++--------------
Mbank/src/test/kotlin/helpers.kt | 8++++++++
3 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Database.kt b/bank/src/main/kotlin/tech/libeufin/bank/Database.kt @@ -945,6 +945,9 @@ class Database(private val dbConfig: String, private val bankCurrency: String) { } conn.execSQLUpdate("UNLISTEN $channel"); + conn.getNotifications(); // Clear pending notifications + + conn.close() return items.toList(); } diff --git a/bank/src/test/kotlin/TalerApiTest.kt b/bank/src/test/kotlin/TalerApiTest.kt @@ -282,24 +282,28 @@ class TalerApiTest { }.assertHistory(5) // Check no useless polling - client.get("/accounts/bar/taler-wire-gateway/history/incoming?delta=-6&start=20&long_poll_ms=6000000") { - basicAuth("bar", "secret") - }.assertHistory(5) + assertTime(1000) { + client.get("/accounts/bar/taler-wire-gateway/history/incoming?delta=-6&start=20&long_poll_ms=1000") { + basicAuth("bar", "secret") + }.assertHistory(5) + } // Check polling end client.get("/accounts/bar/taler-wire-gateway/history/incoming?delta=6&long_poll_ms=60") { basicAuth("bar", "secret") }.assertHistory(5) - // Check polling succedd + // Check polling succeed runBlocking { launch { delay(200) db.bankTransactionCreate(genTx(randShortHashCode().encoded)).assertSuccess() } - client.get("/accounts/bar/taler-wire-gateway/history/incoming?delta=-6&long_poll_ms=6000000") { - basicAuth("bar", "secret") - }.assertHistory(6) + assertTime(1000) { + client.get("/accounts/bar/taler-wire-gateway/history/incoming?delta=-6&long_poll_ms=1000") { + basicAuth("bar", "secret") + }.assertHistory(6) + } } // Check polling timeout @@ -405,24 +409,28 @@ class TalerApiTest { }.assertHistory(5) // Check no useless polling - client.get("/accounts/bar/taler-wire-gateway/history/outgoing?delta=-6&start=20&long_poll_ms=6000000") { - basicAuth("bar", "secret") - }.assertHistory(5) + assertTime(3000) { + client.get("/accounts/bar/taler-wire-gateway/history/outgoing?delta=-6&start=20&long_poll_ms=3000") { + basicAuth("bar", "secret") + }.assertHistory(5) + } // Check polling end client.get("/accounts/bar/taler-wire-gateway/history/outgoing?delta=6&long_poll_ms=60") { basicAuth("bar", "secret") }.assertHistory(5) - // Check polling succedd + // Check polling succeed runBlocking { launch { delay(200) transfer(db, 2, bankAccountFoo) } - client.get("/accounts/bar/taler-wire-gateway/history/outgoing?delta=-6&long_poll_ms=6000000") { - basicAuth("bar", "secret") - }.assertHistory(6) + assertTime(3000) { + client.get("/accounts/bar/taler-wire-gateway/history/outgoing?delta=-6&long_poll_ms=3000") { + basicAuth("bar", "secret") + }.assertHistory(6) + } } // Check polling timeout diff --git a/bank/src/test/kotlin/helpers.kt b/bank/src/test/kotlin/helpers.kt @@ -24,6 +24,14 @@ fun BankTransactionResult.assertSuccess() { assertEquals(BankTransactionResult.SUCCESS, this) } +suspend fun assertTime(ms: Int, lambda: suspend () -> Unit) { + val start = System.currentTimeMillis() + lambda() + val end = System.currentTimeMillis() + val time = end - start + assert(time < ms) { "Expected to last at most $ms ms, lasted $time" } +} + /* ----- Body helper ----- */ inline fun <reified B> HttpRequestBuilder.jsonBody(b: B, deflate: Boolean = false) {