Skip to content

Commit

Permalink
tests: extract data to variable and remove ts
Browse files Browse the repository at this point in the history
Timestamp (`ts`) cannot be subject of this unit tests due to flaky
nature of the test.
  • Loading branch information
wzieba committed Oct 25, 2023
1 parent 57c4da2 commit df99e84
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ internal class EngagementManagerTest {
private val parentTimer = Timer()
private val baseEvent: Event = mutableMapOf(
"action" to "heartbeat",
"data" to mutableMapOf<String, Any>(
"os" to "android",
"parsely_site_uuid" to "e8857cbe-5ace-44f4-a85e-7e7475f675c5",
"os_version" to "34",
"manufacturer" to "Google",
"ts" to 1697638552181
)
"data" to testData
)

@Before
Expand Down Expand Up @@ -84,10 +78,7 @@ internal class EngagementManagerTest {
assertThat(data).hasEntrySatisfying("ts") { timestamp ->
timestamp as Long
assertThat(timestamp).withTimestamp()
}.containsEntry("os", "android")
.containsEntry("parsely_site_uuid", "e8857cbe-5ace-44f4-a85e-7e7475f675c5")
.containsEntry("os_version", "34")
.containsEntry("manufacturer", "Google")
}.containsAllEntriesOf(testData)
}
}

Expand Down Expand Up @@ -153,10 +144,18 @@ internal class EngagementManagerTest {

private fun sleep(millis: Long) = Thread.sleep(millis + THREAD_SLEEPING_THRESHOLD)

companion object {
private const val DEFAULT_INTERVAL_MILLIS = 100L
private companion object {
const val DEFAULT_INTERVAL_MILLIS = 100L

// Additional time to wait to ensure that the timer has fired
private const val THREAD_SLEEPING_THRESHOLD = 50L
const val THREAD_SLEEPING_THRESHOLD = 50L

const val TEST_UUID = "123e4567-e89b-12d3-a456-426614174000"
val testData = mutableMapOf<String, Any>(
"os" to "android",
"parsely_site_uuid" to "e8857cbe-5ace-44f4-a85e-7e7475f675c5",
"os_version" to "34",
"manufacturer" to "Google",
)
}
}

0 comments on commit df99e84

Please sign in to comment.