Skip to content

Commit 42a6ef2

Browse files
committed
test with waitUntil
1 parent 3778af4 commit 42a6ef2

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/test/kotlin/org/prebid/cache/functional/SecondaryCacheSpec.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class SecondaryCacheSpec : ShouldSpec({
3434
specPrebidCacheConfig = BaseSpec.prebidCacheConfig.getBaseAerospikeConfig(true) +
3535
BaseSpec.prebidCacheConfig.getSecondaryCacheConfig(webCacheContainerUri)
3636
prebidCacheApi = BaseSpec.getPrebidCacheApi(specPrebidCacheConfig)
37-
val requestObject = RequestObject.getDefaultJsonRequestObject().apply { puts[0].key = getRandomUuid() }
38-
prebidCacheApi.postCache(requestObject, "no")
3937
}
4038

4139
afterSpec {

src/test/kotlin/org/prebid/cache/functional/testcontainers/client/WebCacheContainerClient.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ class WebCacheContainerClient(mockServerHost: String, mockServerPort: Int) {
4040
.withBody(body, mediaType)
4141
)
4242

43-
fun getSecondaryCacheRecordedRequests(uuidKey: String): Array<out HttpRequest>? =
44-
mockServerClient.retrieveRecordedRequests(getSecondaryCacheRequest(uuidKey))
43+
fun getSecondaryCacheRecordedRequests(uuidKey: String): Array<out HttpRequest>? {
44+
val secondaryCacheRequest = getSecondaryCacheRequest(uuidKey)
45+
waitUntil({ mockServerClient.retrieveRecordedRequests(secondaryCacheRequest)?.isNotEmpty() == true })
46+
return mockServerClient.retrieveRecordedRequests(secondaryCacheRequest)
47+
}
4548

4649
fun initSecondaryCacheResponse(): Array<out Expectation>? =
4750
mockServerClient.`when`(getSecondaryCacheRequest())
@@ -59,4 +62,15 @@ class WebCacheContainerClient(mockServerHost: String, mockServerPort: Int) {
5962
request().withMethod(POST.name())
6063
.withPath("/$WEB_CACHE_PATH")
6164
.withBody(jsonPath("\$.puts[?(@.key == '$uuidKey')]"))
65+
66+
private fun waitUntil(closure: () -> Boolean, timeoutMs: Long = 5000, pollInterval: Long = 100) {
67+
val startTime = System.currentTimeMillis()
68+
while (System.currentTimeMillis() - startTime <= timeoutMs) {
69+
if (closure()) {
70+
return
71+
}
72+
Thread.sleep(pollInterval)
73+
}
74+
throw IllegalStateException("Condition was not fulfilled within $timeoutMs ms.")
75+
}
6276
}

0 commit comments

Comments
 (0)