Skip to content

Add functional test framework#56

Merged
SerhiiNahornyi merged 11 commits intomasterfrom
add-functional-test-framework
May 23, 2022
Merged

Add functional test framework#56
SerhiiNahornyi merged 11 commits intomasterfrom
add-functional-test-framework

Conversation

@hupaloo
Copy link
Copy Markdown
Contributor

@hupaloo hupaloo commented Mar 21, 2022

Created test framework to cover existing functionality of Prebid Cache with tests written in Kotlin

@SerhiiNahornyi SerhiiNahornyi changed the title Add functional test framework in Kotlin Add functional test framework Mar 21, 2022
Copy link
Copy Markdown
Collaborator

@And1sS And1sS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round.

@hupaloo hupaloo requested review from And1sS and mtuchkova March 21, 2022 14:50
@hupaloo hupaloo added the tests functional Kotlin tests label Mar 29, 2022
And1sS
And1sS previously approved these changes May 4, 2022
@Net-burst Net-burst force-pushed the add-functional-test-framework branch from f3f41ed to 1e1b7f4 Compare May 4, 2022 12:57
Net-burst
Net-burst previously approved these changes May 5, 2022
Copy link
Copy Markdown
Collaborator

@Net-burst Net-burst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +73 to +74
val xmlPayloadTransfer = PayloadTransfer.getDefaultXmlPayloadTransfer()
xmlPayloadTransfer.key = uuid
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about to use apply? Also, please, check for similar occurences.

val xmlPayloadTransfer = PayloadTransfer.getDefaultXmlPayloadTransfer().apply { key = uuid }

val uuid = getRandomUuid()
val xmlPayloadTransfer = PayloadTransfer.getDefaultXmlPayloadTransfer()
xmlPayloadTransfer.key = uuid
val requestObject = RequestObject(listOf(xmlPayloadTransfer))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about to add static constructor method to RequestObject which accept vararg of PayloadTransfer?

fun of(vararg puts: PayloadTransfer): RequestObject =
    RequestObject(puts = puts.asList())

Than you can don't use every time listOf(...)

Comment on lines +15 to +19
fun getPrebidCacheApi(config: Map<String, String> = prebidCacheConfig.getBaseRedisConfig("false")): PrebidCacheApi {
val prebidCacheContainer =
ContainerDependencies.prebidCacheContainerPool.getPrebidCacheContainer(config)
return PrebidCacheApi(prebidCacheContainer.host, prebidCacheContainer.getHostPort())
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about to replace method body with this approach?

ContainerDependencies.prebidCacheContainerPool.getPrebidCacheContainer(config)
    .let { container -> PrebidCacheApi(container.host, container.getHostPort()) }

webCacheContainerClient.getProxyCacheHostRecordedRequestCount() shouldBe initialProxyCacheHostRequestCount + 1

val proxyCacheHostRequest = webCacheContainerClient.getProxyCacheHostRecordedRequests()!!.last()
proxyCacheHostRequest.queryStringParameters?.containsEntry("uuid", requestUuid)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do there need to be some assertion?

secondaryCacheRecordedRequests?.size shouldBe 1

// and: Request contained secondaryCache=yes query parameter
secondaryCacheRecordedRequests!!.first().queryStringParameters?.containsEntry("secondaryCache", "yes")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do there need to be some assertion?

Comment on lines +11 to +13
var type: MediaType,
var key: String? = null,
var value: String,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fields with default values are usually listed after other fields.


companion object {
private val MAX_CONTAINER_COUNT: Int = (System.getProperty("max.containers.count") ?: "3").toInt()
private val prebidCacheContainerMap: MutableMap<Map<String, String>, PrebidCacheContainer> = mutableMapOf()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this property need to be static?

private const val FIXED_EXPOSED_APPLICATION_PORT = 49100
private const val FIXED_EXPOSED_DEBUG_PORT = 49101

private val USE_FIXED_PORTS = (System.getProperty("useFixedContainerPorts") ?: "false").toBoolean()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.getProperty("useFixedContainerPorts")?.toBoolean() ?: false

Comment on lines +7 to +11
fun getRandomString(length: Int = 16): String {
val allowedChars = ('A'..'Z') + ('a'..'z') + ('0'..'9')
return (1..length).map { allowedChars.random() }
.joinToString("")
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this approach?

List(length) { ALLOWED_CHARS.random() }.joinToString("")

Copy link
Copy Markdown
Collaborator

@Net-burst Net-burst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SerhiiNahornyi SerhiiNahornyi merged commit 76512c0 into master May 23, 2022
@SerhiiNahornyi SerhiiNahornyi deleted the add-functional-test-framework branch May 23, 2022 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests functional Kotlin tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants