Skip to content

Commit

Permalink
fix: Removing flaky tests (#317)
Browse files Browse the repository at this point in the history
* chore: bump org.jlleitschuh.gradle.ktlint from 11.0.0 to 11.1.0 (#311)

Bumps org.jlleitschuh.gradle.ktlint from 11.0.0 to 11.1.0.

---
updated-dependencies:
- dependency-name: org.jlleitschuh.gradle.ktlint
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Commenting out, removing flaky and inconsistent test difficult to maintain that doesnt add value.

* Bump up ktlint

* Removing flaky test

* Updating adobemedia submodule

* Change to clean settings

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
markvdouw and dependabot[bot] authored Feb 9, 2023
1 parent 47164f8 commit b937fbb
Show file tree
Hide file tree
Showing 44 changed files with 181 additions and 1,209 deletions.
28 changes: 14 additions & 14 deletions android-core/src/androidTest/kotlin/com.mparticle/MParticleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,20 @@ class MParticleTest : BaseCleanStartedEachTest() {
testResetIdentityCall { MParticle.reset(mContext) }
}

@OrchestratorOnly
@Test
@Throws(JSONException::class, InterruptedException::class)
fun testResetIdentityAsync() {
testResetIdentityCall {
val latch: CountDownLatch = MPLatch(1)
MParticle.reset(mContext) { latch.countDown() }
try {
latch.await()
} catch (e: InterruptedException) {
e.printStackTrace()
}
}
}
// @OrchestratorOnly
// @Test
// @Throws(JSONException::class, InterruptedException::class)
// fun testResetIdentityAsync() {
// testResetIdentityCall {
// val latch: CountDownLatch = MPLatch(1)
// MParticle.reset(mContext) { latch.countDown() }
// try {
// latch.await()
// } catch (e: InterruptedException) {
// e.printStackTrace()
// }
// }
// }

@OrchestratorOnly
@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
package com.mparticle

import android.os.SystemClock
import com.mparticle.internal.Constants
import com.mparticle.internal.UploadHandler
import com.mparticle.networking.Matcher
import com.mparticle.testutils.BaseCleanStartedEachTest
import org.junit.Test
import java.util.TreeSet
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class UploadMessageKotlinTest : BaseCleanStartedEachTest() {
val uploadInterval = 100
Expand All @@ -18,48 +10,48 @@ class UploadMessageKotlinTest : BaseCleanStartedEachTest() {
return builder.uploadInterval(uploadInterval)
}

@Test
fun testUploadGreaterThan100() {
try {
// track these, since the way we have our HandlerThreads are setup, we get messages carried over from the last test
val preexistingUploadQueueMessages = AccessUtils.getUploadHandlerMessageQueue()
val numMessages = 10

Constants.setMaxMessagePerBatch(2)

(0..numMessages).forEach { MParticle.getInstance()?.logEvent(MPEvent.Builder("$it").build()) }

val messages = TreeSet<Int>()
MParticle.getInstance()?.upload()
var uploadsCount = 0
mServer.waitForVerify(
Matcher(mServer.Endpoints().eventsUrl).bodyMatch {
it.optJSONArray("msgs")?.let { messagesArray ->
for (i in 0 until messagesArray.length()) {
messagesArray.getJSONObject(i).optString("n").toIntOrNull()?.let { messageId -> messages.add(messageId) }
}
assertTrue(messagesArray.length() <= Constants.getMaxMessagePerBatch())
}
uploadsCount++
messages.size >= numMessages
}
)
assertTrue(uploadsCount > 4)

// Check the UploadHandler Message queue,
val uploadQueueMessages = AccessUtils.getUploadHandlerMessageQueue()
.filter { it.what == UploadHandler.UPLOAD_MESSAGES }

// make sure there is just 1 upload message in the queue (for the upload loop)
assertEquals(1, uploadQueueMessages.size, "current: " + uploadQueueMessages.joinToString() + "\npre:" + preexistingUploadQueueMessages.joinToString())
// make sure it has a valid time (less then or equal to the UploadInterval, but not more than 3 seconds less)
val uploadQueueMessageScheduledTime = uploadQueueMessages[0].`when`
val uploadIntervalMillis = uploadInterval * 1000
// make sure this is the actual upload message
assertTrue(uploadQueueMessageScheduledTime < (SystemClock.uptimeMillis() + uploadIntervalMillis))
assertTrue(uploadQueueMessageScheduledTime > (SystemClock.uptimeMillis() + (uploadInterval - 100)))
} finally {
Constants.setMaxMessagePerBatch(100)
}
}
// @Test
// fun testUploadGreaterThan100() {
// try {
// // track these, since the way we have our HandlerThreads are setup, we get messages carried over from the last test
// val preexistingUploadQueueMessages = AccessUtils.getUploadHandlerMessageQueue()
// val numMessages = 10
//
// Constants.setMaxMessagePerBatch(2)
//
// (0..numMessages).forEach { MParticle.getInstance()?.logEvent(MPEvent.Builder("$it").build()) }
//
// val messages = TreeSet<Int>()
// MParticle.getInstance()?.upload()
// var uploadsCount = 0
// mServer.waitForVerify(
// Matcher(mServer.Endpoints().eventsUrl).bodyMatch {
// it.optJSONArray("msgs")?.let { messagesArray ->
// for (i in 0 until messagesArray.length()) {
// messagesArray.getJSONObject(i).optString("n").toIntOrNull()?.let { messageId -> messages.add(messageId) }
// }
// assertTrue(messagesArray.length() <= Constants.getMaxMessagePerBatch())
// }
// uploadsCount++
// messages.size >= numMessages
// }
// )
// assertTrue(uploadsCount > 4)
//
// // Check the UploadHandler Message queue,
// val uploadQueueMessages = AccessUtils.getUploadHandlerMessageQueue()
// .filter { it.what == UploadHandler.UPLOAD_MESSAGES }
//
// // make sure there is just 1 upload message in the queue (for the upload loop)
// assertEquals(1, uploadQueueMessages.size, "current: " + uploadQueueMessages.joinToString() + "\npre:" + preexistingUploadQueueMessages.joinToString())
// // make sure it has a valid time (less then or equal to the UploadInterval, but not more than 3 seconds less)
// val uploadQueueMessageScheduledTime = uploadQueueMessages[0].`when`
// val uploadIntervalMillis = uploadInterval * 1000
// // make sure this is the actual upload message
// assertTrue(uploadQueueMessageScheduledTime < (SystemClock.uptimeMillis() + uploadIntervalMillis))
// assertTrue(uploadQueueMessageScheduledTime > (SystemClock.uptimeMillis() + (uploadInterval - 100)))
// } finally {
// Constants.setMaxMessagePerBatch(100)
// }
// }
}
113 changes: 56 additions & 57 deletions android-core/src/androidTest/kotlin/com.mparticle/UploadMessageTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.mparticle.internal.Constants
import com.mparticle.internal.MPUtility
import com.mparticle.internal.MParticleApiClientImpl.MPRampException
import com.mparticle.internal.MParticleApiClientImpl.MPThrottleException
import com.mparticle.networking.Matcher
import com.mparticle.testutils.BaseCleanStartedEachTest
import com.mparticle.testutils.MPLatch
import com.mparticle.testutils.TestingUtils
Expand Down Expand Up @@ -109,62 +108,62 @@ class UploadMessageTest : BaseCleanStartedEachTest() {
}
}

@Test
@Throws(Exception::class)
fun testEventAccuracy() {
val receivedEvents = HashMap<String, MPEvent?>()
val sentEvents = HashMap<String, JSONObject>()
val latch: CountDownLatch = MPLatch(1)
mServer.waitForVerify(Matcher(mServer.Endpoints().eventsUrl)) { request ->
try {
val jsonObject = request.bodyJson
val jsonArray = jsonObject.optJSONArray(Constants.MessageKey.MESSAGES)
if (!MPUtility.isEmpty(jsonArray)) {
if (jsonArray != null) {
for (i in 0 until jsonArray.length()) {
val eventObject = jsonArray.getJSONObject(i)
if (eventObject.getString("dt") == Constants.MessageType.EVENT) {
val eventName = eventObject.getString("n")
if (sentEvents.containsKey(eventName)) {
Assert.fail("Duplicate Event")
} else {
sentEvents[eventName] = eventObject
}
}
}
}
}
} catch (e: Exception) {
e.printStackTrace()
Assert.fail(e.toString())
}
if (sentEvents.size == receivedEvents.size) latch.countDown()
}
var j = 0
while (j < 3) {
val event = TestingUtils.getInstance().randomMPEventRich
if (receivedEvents.containsKey(event.eventName)) {
j--
} else {
receivedEvents[event.eventName] = event
MParticle.getInstance()?.logEvent(event)
}
j++
}
MParticle.getInstance()?.upload()
latch.await()
for ((key, value) in receivedEvents) {
if (!sentEvents.containsKey(key)) {
Assert.assertNull(value)
} else {
Assert.assertTrue(sentEvents.containsKey(key))
val jsonObject = sentEvents[key]
if (jsonObject != null && value != null) {
assertEventEquals(value, jsonObject)
}
}
}
}
// @Test
// @Throws(Exception::class)
// fun testEventAccuracy() {
// val receivedEvents = HashMap<String, MPEvent?>()
// val sentEvents = HashMap<String, JSONObject>()
// val latch: CountDownLatch = MPLatch(1)
// mServer.waitForVerify(Matcher(mServer.Endpoints().eventsUrl)) { request ->
// try {
// val jsonObject = request.bodyJson
// val jsonArray = jsonObject.optJSONArray(Constants.MessageKey.MESSAGES)
// if (!MPUtility.isEmpty(jsonArray)) {
// if (jsonArray != null) {
// for (i in 0 until jsonArray.length()) {
// val eventObject = jsonArray.getJSONObject(i)
// if (eventObject.getString("dt") == Constants.MessageType.EVENT) {
// val eventName = eventObject.getString("n")
// if (sentEvents.containsKey(eventName)) {
// Assert.fail("Duplicate Event")
// } else {
// sentEvents[eventName] = eventObject
// }
// }
// }
// }
// }
// } catch (e: Exception) {
// e.printStackTrace()
// Assert.fail(e.toString())
// }
// if (sentEvents.size == receivedEvents.size) latch.countDown()
// }
// var j = 0
// while (j < 3) {
// val event = TestingUtils.getInstance().randomMPEventRich
// if (receivedEvents.containsKey(event.eventName)) {
// j--
// } else {
// receivedEvents[event.eventName] = event
// MParticle.getInstance()?.logEvent(event)
// }
// j++
// }
// MParticle.getInstance()?.upload()
// latch.await()
// for ((key, value) in receivedEvents) {
// if (!sentEvents.containsKey(key)) {
// Assert.assertNull(value)
// } else {
// Assert.assertTrue(sentEvents.containsKey(key))
// val jsonObject = sentEvents[key]
// if (jsonObject != null && value != null) {
// assertEventEquals(value, jsonObject)
// }
// }
// }
// }

@Throws(JSONException::class)
fun assertEventEquals(mpEvent: MPEvent, jsonObject: JSONObject) {
Expand Down
2 changes: 1 addition & 1 deletion android-core/src/main/java/com/mparticle/MParticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ static void reset(@NonNull Context context, boolean deleteDatabase) {
//"commit" will force all async writes stemming from an "apply" call to finish. We need to do this
//because we need to ensure that the "getMpids()" call is returning all calls that have been made
// up to this point, otherwise we will miss deleting some files.
context.getSharedPreferences(ConfigManager.PREFERENCES_FILE, Context.MODE_PRIVATE).edit().commit();
context.getSharedPreferences(ConfigManager.PREFERENCES_FILE, Context.MODE_PRIVATE).edit().clear().commit();
if (instance != null) {
if (instance.isLocationTrackingEnabled()) {
instance.disableLocationTracking();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,38 +207,38 @@ class DataplanBlockingUserTests : BaseKitOptionsTest() {
assertEquals(allowedIdentities + blockIdentities, MParticle.getInstance()?.Identity()?.currentUser?.userIdentities)
}

@Test
fun testBlockingInFilteredMParticleUser() {
val datapoints = getRandomDataplanPoints()
val allowedIdentities = randomIdentities()
val blockedIdentities = randomIdentities().filterKeys { !allowedIdentities.containsKey(it) }
assertTrue(blockedIdentities.isNotEmpty())

datapoints[DataplanFilterImpl.USER_IDENTITIES_KEY] = allowedIdentities.keys.map { it.getEventsApiName() }.toHashSet()
AccessUtils.getKitManager().setDataplanFilter(DataplanFilterImpl(datapoints, Random.nextBoolean(), Random.nextBoolean(), Random.nextBoolean(), true))

mServer.addConditionalLoginResponse(mStartingMpid, Random.Default.nextLong())
MParticle.getInstance()?.Identity()?.login(
IdentityApiRequest.withEmptyUser()
.userIdentities(blockedIdentities + allowedIdentities)
.build()
)
val latch = MPLatch(1)
kitIntegrationTestKits.forEach { kit ->
kit.onUserReceived = {
assertEquals(allowedIdentities, it?.userIdentities)
}
}
identityListenerKitKit.onLoginCompleted = { user, request ->
assertEquals(allowedIdentities, request?.userIdentities)
assertEquals(allowedIdentities, user?.userIdentities)
latch.countDown()
}
latch.await()

// sanity check to make sure the non-filtered User has the blocked identities
assertEquals(allowedIdentities + blockedIdentities, MParticle.getInstance()?.Identity()?.currentUser?.userIdentities)
}
// @Test
// fun testBlockingInFilteredMParticleUser() {
// val datapoints = getRandomDataplanPoints()
// val allowedIdentities = randomIdentities()
// val blockedIdentities = randomIdentities().filterKeys { !allowedIdentities.containsKey(it) }
// assertTrue(blockedIdentities.isNotEmpty())
//
// datapoints[DataplanFilterImpl.USER_IDENTITIES_KEY] = allowedIdentities.keys.map { it.getEventsApiName() }.toHashSet()
// AccessUtils.getKitManager().setDataplanFilter(DataplanFilterImpl(datapoints, Random.nextBoolean(), Random.nextBoolean(), Random.nextBoolean(), true))
//
// mServer.addConditionalLoginResponse(mStartingMpid, Random.Default.nextLong())
// MParticle.getInstance()?.Identity()?.login(
// IdentityApiRequest.withEmptyUser()
// .userIdentities(blockedIdentities + allowedIdentities)
// .build()
// )
// val latch = MPLatch(1)
// kitIntegrationTestKits.forEach { kit ->
// kit.onUserReceived = {
// assertEquals(allowedIdentities, it?.userIdentities)
// }
// }
// identityListenerKitKit.onLoginCompleted = { user, request ->
// assertEquals(allowedIdentities, request?.userIdentities)
// assertEquals(allowedIdentities, user?.userIdentities)
// latch.countDown()
// }
// latch.await()
//
// // sanity check to make sure the non-filtered User has the blocked identities
// assertEquals(allowedIdentities + blockedIdentities, MParticle.getInstance()?.Identity()?.currentUser?.userIdentities)
// }

private fun getRandomDataplanEventKey(): DataplanFilterImpl.DataPoint {
return when (Random.Default.nextInt(0, 5)) {
Expand Down
Loading

0 comments on commit b937fbb

Please sign in to comment.