Skip to content

Commit

Permalink
Wait for ABTest deletion in TestSuite
Browse files Browse the repository at this point in the history
  • Loading branch information
q-litzler committed May 15, 2019
1 parent 620ecf5 commit c4bf77f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/commonTest/kotlin/suite/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal fun compareVariant(actual: ResponseVariant, expected: Variant) {
}
}

internal suspend fun cleanABTest(suffix: String, now: Boolean = false) {
internal suspend fun cleanABTest(clientSearch: ClientSearch, suffix: String, now: Boolean = false) {
val regex = Regex("kotlin-(.*)-$username-$suffix")

clientAnalytics.browseAllABTests().forEach {
Expand All @@ -42,7 +42,11 @@ internal suspend fun cleanABTest(suffix: String, now: Boolean = false) {
val difference = Time.getCurrentTimeMillis() - DateFormat.parse(date)

if (difference >= dayInMillis || now) {
clientAnalytics.deleteABTest(abTest.abTestID)
val deletion = clientAnalytics.deleteABTest(abTest.abTestID)

clientSearch.initIndex(deletion.indexName).apply {
deletion.wait()
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/commonTest/kotlin/suite/TestSuiteAATest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.algolia.search.model.search.Query
import com.algolia.search.model.task.TaskStatus
import com.algolia.search.serialize.KeyObjectID
import dayInMillis
import kotlinx.coroutines.delay
import kotlinx.serialization.json.json
import runBlocking
import shouldEqual
Expand Down Expand Up @@ -41,7 +40,7 @@ internal class TestSuiteAATest {
@BeforeTest
fun clean() {
runBlocking {
cleanABTest(suffix)
cleanABTest(clientAdmin1, suffix)
cleanIndex(clientAdmin1, suffix)
}
}
Expand All @@ -54,7 +53,6 @@ internal class TestSuiteAATest {
val response = clientAnalytics.addABTest(abTest)

response.wait() shouldEqual TaskStatus.Published
delay(2000L)
clientAnalytics.getABTest(response.abTestID).let {
it.name shouldEqual abTest.name
it.endAt shouldEqual abTest.endAt
Expand Down
2 changes: 1 addition & 1 deletion src/commonTest/kotlin/suite/TestSuiteABTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal class TestSuiteABTest {
@BeforeTest
fun clean() {
runBlocking {
cleanABTest(suffix)
cleanABTest(clientAdmin1, suffix)
cleanIndex(clientAdmin1, suffix)
}
}
Expand Down

0 comments on commit c4bf77f

Please sign in to comment.