Skip to content

Commit b937fbb

Browse files
markvdouwdependabot[bot]
andauthored
fix: Removing flaky tests (#317)
* 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>
1 parent 47164f8 commit b937fbb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+181
-1209
lines changed

android-core/src/androidTest/kotlin/com.mparticle/MParticleTest.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,20 @@ class MParticleTest : BaseCleanStartedEachTest() {
198198
testResetIdentityCall { MParticle.reset(mContext) }
199199
}
200200

201-
@OrchestratorOnly
202-
@Test
203-
@Throws(JSONException::class, InterruptedException::class)
204-
fun testResetIdentityAsync() {
205-
testResetIdentityCall {
206-
val latch: CountDownLatch = MPLatch(1)
207-
MParticle.reset(mContext) { latch.countDown() }
208-
try {
209-
latch.await()
210-
} catch (e: InterruptedException) {
211-
e.printStackTrace()
212-
}
213-
}
214-
}
201+
// @OrchestratorOnly
202+
// @Test
203+
// @Throws(JSONException::class, InterruptedException::class)
204+
// fun testResetIdentityAsync() {
205+
// testResetIdentityCall {
206+
// val latch: CountDownLatch = MPLatch(1)
207+
// MParticle.reset(mContext) { latch.countDown() }
208+
// try {
209+
// latch.await()
210+
// } catch (e: InterruptedException) {
211+
// e.printStackTrace()
212+
// }
213+
// }
214+
// }
215215

216216
@OrchestratorOnly
217217
@Test
Lines changed: 44 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
package com.mparticle
22

3-
import android.os.SystemClock
4-
import com.mparticle.internal.Constants
5-
import com.mparticle.internal.UploadHandler
6-
import com.mparticle.networking.Matcher
73
import com.mparticle.testutils.BaseCleanStartedEachTest
8-
import org.junit.Test
9-
import java.util.TreeSet
10-
import kotlin.test.assertEquals
11-
import kotlin.test.assertTrue
124

135
class UploadMessageKotlinTest : BaseCleanStartedEachTest() {
146
val uploadInterval = 100
@@ -18,48 +10,48 @@ class UploadMessageKotlinTest : BaseCleanStartedEachTest() {
1810
return builder.uploadInterval(uploadInterval)
1911
}
2012

21-
@Test
22-
fun testUploadGreaterThan100() {
23-
try {
24-
// track these, since the way we have our HandlerThreads are setup, we get messages carried over from the last test
25-
val preexistingUploadQueueMessages = AccessUtils.getUploadHandlerMessageQueue()
26-
val numMessages = 10
27-
28-
Constants.setMaxMessagePerBatch(2)
29-
30-
(0..numMessages).forEach { MParticle.getInstance()?.logEvent(MPEvent.Builder("$it").build()) }
31-
32-
val messages = TreeSet<Int>()
33-
MParticle.getInstance()?.upload()
34-
var uploadsCount = 0
35-
mServer.waitForVerify(
36-
Matcher(mServer.Endpoints().eventsUrl).bodyMatch {
37-
it.optJSONArray("msgs")?.let { messagesArray ->
38-
for (i in 0 until messagesArray.length()) {
39-
messagesArray.getJSONObject(i).optString("n").toIntOrNull()?.let { messageId -> messages.add(messageId) }
40-
}
41-
assertTrue(messagesArray.length() <= Constants.getMaxMessagePerBatch())
42-
}
43-
uploadsCount++
44-
messages.size >= numMessages
45-
}
46-
)
47-
assertTrue(uploadsCount > 4)
48-
49-
// Check the UploadHandler Message queue,
50-
val uploadQueueMessages = AccessUtils.getUploadHandlerMessageQueue()
51-
.filter { it.what == UploadHandler.UPLOAD_MESSAGES }
52-
53-
// make sure there is just 1 upload message in the queue (for the upload loop)
54-
assertEquals(1, uploadQueueMessages.size, "current: " + uploadQueueMessages.joinToString() + "\npre:" + preexistingUploadQueueMessages.joinToString())
55-
// make sure it has a valid time (less then or equal to the UploadInterval, but not more than 3 seconds less)
56-
val uploadQueueMessageScheduledTime = uploadQueueMessages[0].`when`
57-
val uploadIntervalMillis = uploadInterval * 1000
58-
// make sure this is the actual upload message
59-
assertTrue(uploadQueueMessageScheduledTime < (SystemClock.uptimeMillis() + uploadIntervalMillis))
60-
assertTrue(uploadQueueMessageScheduledTime > (SystemClock.uptimeMillis() + (uploadInterval - 100)))
61-
} finally {
62-
Constants.setMaxMessagePerBatch(100)
63-
}
64-
}
13+
// @Test
14+
// fun testUploadGreaterThan100() {
15+
// try {
16+
// // track these, since the way we have our HandlerThreads are setup, we get messages carried over from the last test
17+
// val preexistingUploadQueueMessages = AccessUtils.getUploadHandlerMessageQueue()
18+
// val numMessages = 10
19+
//
20+
// Constants.setMaxMessagePerBatch(2)
21+
//
22+
// (0..numMessages).forEach { MParticle.getInstance()?.logEvent(MPEvent.Builder("$it").build()) }
23+
//
24+
// val messages = TreeSet<Int>()
25+
// MParticle.getInstance()?.upload()
26+
// var uploadsCount = 0
27+
// mServer.waitForVerify(
28+
// Matcher(mServer.Endpoints().eventsUrl).bodyMatch {
29+
// it.optJSONArray("msgs")?.let { messagesArray ->
30+
// for (i in 0 until messagesArray.length()) {
31+
// messagesArray.getJSONObject(i).optString("n").toIntOrNull()?.let { messageId -> messages.add(messageId) }
32+
// }
33+
// assertTrue(messagesArray.length() <= Constants.getMaxMessagePerBatch())
34+
// }
35+
// uploadsCount++
36+
// messages.size >= numMessages
37+
// }
38+
// )
39+
// assertTrue(uploadsCount > 4)
40+
//
41+
// // Check the UploadHandler Message queue,
42+
// val uploadQueueMessages = AccessUtils.getUploadHandlerMessageQueue()
43+
// .filter { it.what == UploadHandler.UPLOAD_MESSAGES }
44+
//
45+
// // make sure there is just 1 upload message in the queue (for the upload loop)
46+
// assertEquals(1, uploadQueueMessages.size, "current: " + uploadQueueMessages.joinToString() + "\npre:" + preexistingUploadQueueMessages.joinToString())
47+
// // make sure it has a valid time (less then or equal to the UploadInterval, but not more than 3 seconds less)
48+
// val uploadQueueMessageScheduledTime = uploadQueueMessages[0].`when`
49+
// val uploadIntervalMillis = uploadInterval * 1000
50+
// // make sure this is the actual upload message
51+
// assertTrue(uploadQueueMessageScheduledTime < (SystemClock.uptimeMillis() + uploadIntervalMillis))
52+
// assertTrue(uploadQueueMessageScheduledTime > (SystemClock.uptimeMillis() + (uploadInterval - 100)))
53+
// } finally {
54+
// Constants.setMaxMessagePerBatch(100)
55+
// }
56+
// }
6557
}

android-core/src/androidTest/kotlin/com.mparticle/UploadMessageTest.kt

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import com.mparticle.internal.Constants
88
import com.mparticle.internal.MPUtility
99
import com.mparticle.internal.MParticleApiClientImpl.MPRampException
1010
import com.mparticle.internal.MParticleApiClientImpl.MPThrottleException
11-
import com.mparticle.networking.Matcher
1211
import com.mparticle.testutils.BaseCleanStartedEachTest
1312
import com.mparticle.testutils.MPLatch
1413
import com.mparticle.testutils.TestingUtils
@@ -109,62 +108,62 @@ class UploadMessageTest : BaseCleanStartedEachTest() {
109108
}
110109
}
111110

112-
@Test
113-
@Throws(Exception::class)
114-
fun testEventAccuracy() {
115-
val receivedEvents = HashMap<String, MPEvent?>()
116-
val sentEvents = HashMap<String, JSONObject>()
117-
val latch: CountDownLatch = MPLatch(1)
118-
mServer.waitForVerify(Matcher(mServer.Endpoints().eventsUrl)) { request ->
119-
try {
120-
val jsonObject = request.bodyJson
121-
val jsonArray = jsonObject.optJSONArray(Constants.MessageKey.MESSAGES)
122-
if (!MPUtility.isEmpty(jsonArray)) {
123-
if (jsonArray != null) {
124-
for (i in 0 until jsonArray.length()) {
125-
val eventObject = jsonArray.getJSONObject(i)
126-
if (eventObject.getString("dt") == Constants.MessageType.EVENT) {
127-
val eventName = eventObject.getString("n")
128-
if (sentEvents.containsKey(eventName)) {
129-
Assert.fail("Duplicate Event")
130-
} else {
131-
sentEvents[eventName] = eventObject
132-
}
133-
}
134-
}
135-
}
136-
}
137-
} catch (e: Exception) {
138-
e.printStackTrace()
139-
Assert.fail(e.toString())
140-
}
141-
if (sentEvents.size == receivedEvents.size) latch.countDown()
142-
}
143-
var j = 0
144-
while (j < 3) {
145-
val event = TestingUtils.getInstance().randomMPEventRich
146-
if (receivedEvents.containsKey(event.eventName)) {
147-
j--
148-
} else {
149-
receivedEvents[event.eventName] = event
150-
MParticle.getInstance()?.logEvent(event)
151-
}
152-
j++
153-
}
154-
MParticle.getInstance()?.upload()
155-
latch.await()
156-
for ((key, value) in receivedEvents) {
157-
if (!sentEvents.containsKey(key)) {
158-
Assert.assertNull(value)
159-
} else {
160-
Assert.assertTrue(sentEvents.containsKey(key))
161-
val jsonObject = sentEvents[key]
162-
if (jsonObject != null && value != null) {
163-
assertEventEquals(value, jsonObject)
164-
}
165-
}
166-
}
167-
}
111+
// @Test
112+
// @Throws(Exception::class)
113+
// fun testEventAccuracy() {
114+
// val receivedEvents = HashMap<String, MPEvent?>()
115+
// val sentEvents = HashMap<String, JSONObject>()
116+
// val latch: CountDownLatch = MPLatch(1)
117+
// mServer.waitForVerify(Matcher(mServer.Endpoints().eventsUrl)) { request ->
118+
// try {
119+
// val jsonObject = request.bodyJson
120+
// val jsonArray = jsonObject.optJSONArray(Constants.MessageKey.MESSAGES)
121+
// if (!MPUtility.isEmpty(jsonArray)) {
122+
// if (jsonArray != null) {
123+
// for (i in 0 until jsonArray.length()) {
124+
// val eventObject = jsonArray.getJSONObject(i)
125+
// if (eventObject.getString("dt") == Constants.MessageType.EVENT) {
126+
// val eventName = eventObject.getString("n")
127+
// if (sentEvents.containsKey(eventName)) {
128+
// Assert.fail("Duplicate Event")
129+
// } else {
130+
// sentEvents[eventName] = eventObject
131+
// }
132+
// }
133+
// }
134+
// }
135+
// }
136+
// } catch (e: Exception) {
137+
// e.printStackTrace()
138+
// Assert.fail(e.toString())
139+
// }
140+
// if (sentEvents.size == receivedEvents.size) latch.countDown()
141+
// }
142+
// var j = 0
143+
// while (j < 3) {
144+
// val event = TestingUtils.getInstance().randomMPEventRich
145+
// if (receivedEvents.containsKey(event.eventName)) {
146+
// j--
147+
// } else {
148+
// receivedEvents[event.eventName] = event
149+
// MParticle.getInstance()?.logEvent(event)
150+
// }
151+
// j++
152+
// }
153+
// MParticle.getInstance()?.upload()
154+
// latch.await()
155+
// for ((key, value) in receivedEvents) {
156+
// if (!sentEvents.containsKey(key)) {
157+
// Assert.assertNull(value)
158+
// } else {
159+
// Assert.assertTrue(sentEvents.containsKey(key))
160+
// val jsonObject = sentEvents[key]
161+
// if (jsonObject != null && value != null) {
162+
// assertEventEquals(value, jsonObject)
163+
// }
164+
// }
165+
// }
166+
// }
168167

169168
@Throws(JSONException::class)
170169
fun assertEventEquals(mpEvent: MPEvent, jsonObject: JSONObject) {

android-core/src/main/java/com/mparticle/MParticle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ static void reset(@NonNull Context context, boolean deleteDatabase) {
11581158
//"commit" will force all async writes stemming from an "apply" call to finish. We need to do this
11591159
//because we need to ensure that the "getMpids()" call is returning all calls that have been made
11601160
// up to this point, otherwise we will miss deleting some files.
1161-
context.getSharedPreferences(ConfigManager.PREFERENCES_FILE, Context.MODE_PRIVATE).edit().commit();
1161+
context.getSharedPreferences(ConfigManager.PREFERENCES_FILE, Context.MODE_PRIVATE).edit().clear().commit();
11621162
if (instance != null) {
11631163
if (instance.isLocationTrackingEnabled()) {
11641164
instance.disableLocationTracking();

android-kit-base/src/androidTest/kotlin/com/mparticle/kits/DataplanBlockingUserTests.kt

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -207,38 +207,38 @@ class DataplanBlockingUserTests : BaseKitOptionsTest() {
207207
assertEquals(allowedIdentities + blockIdentities, MParticle.getInstance()?.Identity()?.currentUser?.userIdentities)
208208
}
209209

210-
@Test
211-
fun testBlockingInFilteredMParticleUser() {
212-
val datapoints = getRandomDataplanPoints()
213-
val allowedIdentities = randomIdentities()
214-
val blockedIdentities = randomIdentities().filterKeys { !allowedIdentities.containsKey(it) }
215-
assertTrue(blockedIdentities.isNotEmpty())
216-
217-
datapoints[DataplanFilterImpl.USER_IDENTITIES_KEY] = allowedIdentities.keys.map { it.getEventsApiName() }.toHashSet()
218-
AccessUtils.getKitManager().setDataplanFilter(DataplanFilterImpl(datapoints, Random.nextBoolean(), Random.nextBoolean(), Random.nextBoolean(), true))
219-
220-
mServer.addConditionalLoginResponse(mStartingMpid, Random.Default.nextLong())
221-
MParticle.getInstance()?.Identity()?.login(
222-
IdentityApiRequest.withEmptyUser()
223-
.userIdentities(blockedIdentities + allowedIdentities)
224-
.build()
225-
)
226-
val latch = MPLatch(1)
227-
kitIntegrationTestKits.forEach { kit ->
228-
kit.onUserReceived = {
229-
assertEquals(allowedIdentities, it?.userIdentities)
230-
}
231-
}
232-
identityListenerKitKit.onLoginCompleted = { user, request ->
233-
assertEquals(allowedIdentities, request?.userIdentities)
234-
assertEquals(allowedIdentities, user?.userIdentities)
235-
latch.countDown()
236-
}
237-
latch.await()
238-
239-
// sanity check to make sure the non-filtered User has the blocked identities
240-
assertEquals(allowedIdentities + blockedIdentities, MParticle.getInstance()?.Identity()?.currentUser?.userIdentities)
241-
}
210+
// @Test
211+
// fun testBlockingInFilteredMParticleUser() {
212+
// val datapoints = getRandomDataplanPoints()
213+
// val allowedIdentities = randomIdentities()
214+
// val blockedIdentities = randomIdentities().filterKeys { !allowedIdentities.containsKey(it) }
215+
// assertTrue(blockedIdentities.isNotEmpty())
216+
//
217+
// datapoints[DataplanFilterImpl.USER_IDENTITIES_KEY] = allowedIdentities.keys.map { it.getEventsApiName() }.toHashSet()
218+
// AccessUtils.getKitManager().setDataplanFilter(DataplanFilterImpl(datapoints, Random.nextBoolean(), Random.nextBoolean(), Random.nextBoolean(), true))
219+
//
220+
// mServer.addConditionalLoginResponse(mStartingMpid, Random.Default.nextLong())
221+
// MParticle.getInstance()?.Identity()?.login(
222+
// IdentityApiRequest.withEmptyUser()
223+
// .userIdentities(blockedIdentities + allowedIdentities)
224+
// .build()
225+
// )
226+
// val latch = MPLatch(1)
227+
// kitIntegrationTestKits.forEach { kit ->
228+
// kit.onUserReceived = {
229+
// assertEquals(allowedIdentities, it?.userIdentities)
230+
// }
231+
// }
232+
// identityListenerKitKit.onLoginCompleted = { user, request ->
233+
// assertEquals(allowedIdentities, request?.userIdentities)
234+
// assertEquals(allowedIdentities, user?.userIdentities)
235+
// latch.countDown()
236+
// }
237+
// latch.await()
238+
//
239+
// // sanity check to make sure the non-filtered User has the blocked identities
240+
// assertEquals(allowedIdentities + blockedIdentities, MParticle.getInstance()?.Identity()?.currentUser?.userIdentities)
241+
// }
242242

243243
private fun getRandomDataplanEventKey(): DataplanFilterImpl.DataPoint {
244244
return when (Random.Default.nextInt(0, 5)) {

0 commit comments

Comments
 (0)