-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
112 changed files
with
3,927 additions
and
525 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Instrumented tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- '*' | ||
|
||
jobs: | ||
test: | ||
runs-on: macos-12 | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
api-level: [ 29 ] | ||
shard: [ 0, 1, 2, 3 ] | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Gradle cache | ||
uses: gradle/gradle-build-action@v2 | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: 11 | ||
cache: 'gradle' | ||
|
||
- name: AVD cache | ||
uses: actions/cache@v3 | ||
id: avd-cache | ||
with: | ||
path: | | ||
~/.android/avd/* | ||
~/.android/adb* | ||
key: avd-${{ matrix.api-level }} | ||
|
||
- name: create AVD and generate snapshot for caching | ||
if: steps.avd-cache.outputs.cache-hit != 'true' | ||
uses: reactivecircus/[email protected] | ||
with: | ||
api-level: ${{ matrix.api-level }} | ||
force-avd-creation: false | ||
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | ||
disable-animations: true | ||
script: echo "Generated AVD snapshot for caching." | ||
|
||
- name: Assemble debug AndroidTest | ||
run: ./gradlew assembleDebugAndroidTest | ||
|
||
- name: Run tests | ||
uses: reactivecircus/android-emulator-runner@v2 | ||
with: | ||
api-level: ${{ matrix.api-level }} | ||
profile: Galaxy Nexus | ||
script: ./gradlew connectedCheck --continue -Pandroid.testInstrumentationRunnerArguments.numShards=4 -Pandroid.testInstrumentationRunnerArguments.shardIndex=${{ matrix.shard }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package helper | ||
|
||
const val MOCK_DATA_IMPRESSION = """ | ||
{ | ||
"featureName": "onboarding", | ||
"keyName": "9oIdSh7h+ACsSTBhZBMzgRHmljmcuZ6OioFinkdf4EtuElENWIYloE", | ||
"bucketingKey": null, | ||
"treatment": "on", | ||
"label": "default rule", | ||
"time":" 546546546549, | ||
"changeNumber": 546546546549, | ||
"previousTime": 498357419865 | ||
} | ||
""" | ||
|
||
const val MOCK_DATA_EVENT: String = """ | ||
{ | ||
"key": "CD16FqbutYKb5Mgd4TwAcXFOZsKrVm9QJM5LL1lwHoIn4SmOdOMqH", | ||
"eventTypeId": "id33", | ||
"trafficTypeName": "user", | ||
"value": 123.0, | ||
"timestamp": 5465465469, | ||
"properties": ["prop1": 1, "prop2": "dos"], | ||
"sizeInBytes": 0 | ||
} | ||
""" | ||
|
||
const val MOCK_DATA_SPLIT: String = """ | ||
{ | ||
"trafficTypeName":"account", | ||
"name":"FACUNDO_TEST", | ||
"trafficAllocation":59, | ||
"trafficAllocationSeed":-2108186082, | ||
"seed":-1947050785, | ||
"status":"ACTIVE", | ||
"killed":false, | ||
"defaultTreatment":"off", | ||
"changeNumber":1506703262916, | ||
"algo":2, | ||
"conditions":[ | ||
{ | ||
"conditionType":"WHITELIST", | ||
"matcherGroup":{ | ||
"combiner":"AND", | ||
"matchers":[ | ||
{ | ||
"keySelector":null, | ||
"matcherType":"WHITELIST", | ||
"negate":false, | ||
"userDefinedSegmentMatcherData":null, | ||
"whitelistMatcherData":{ | ||
"whitelist":[ | ||
"nico_test", | ||
"othertest" | ||
] | ||
}, | ||
"unaryNumericMatcherData":null, | ||
"betweenMatcherData":null, | ||
"booleanMatcherData":null, | ||
"dependencyMatcherData":null, | ||
"stringMatcherData":null | ||
} | ||
] | ||
}, | ||
"partitions":[ | ||
{ | ||
"treatment":"on", | ||
"size":100 | ||
} | ||
], | ||
"label":"whitelisted" | ||
}, | ||
{ | ||
"conditionType":"WHITELIST", | ||
"matcherGroup":{ | ||
"combiner":"AND", | ||
"matchers":[ | ||
{ | ||
"keySelector":null, | ||
"matcherType":"WHITELIST", | ||
"negate":false, | ||
"userDefinedSegmentMatcherData":null, | ||
"whitelistMatcherData":{ | ||
"whitelist":[ | ||
"bla" | ||
] | ||
}, | ||
"unaryNumericMatcherData":null, | ||
"betweenMatcherData":null, | ||
"booleanMatcherData":null, | ||
"dependencyMatcherData":null, | ||
"stringMatcherData":null | ||
} | ||
] | ||
}, | ||
"partitions":[ | ||
{ | ||
"treatment":"off", | ||
"size":100 | ||
} | ||
], | ||
"label":"whitelisted" | ||
}, | ||
{ | ||
"conditionType":"ROLLOUT", | ||
"matcherGroup":{ | ||
"combiner":"AND", | ||
"matchers":[ | ||
{ | ||
"keySelector":{ | ||
"trafficType":"account", | ||
"attribute":null | ||
}, | ||
"matcherType":"ALL_KEYS", | ||
"negate":false, | ||
"userDefinedSegmentMatcherData":null, | ||
"whitelistMatcherData":null, | ||
"unaryNumericMatcherData":null, | ||
"betweenMatcherData":null, | ||
"booleanMatcherData":null, | ||
"dependencyMatcherData":null, | ||
"stringMatcherData":null | ||
} | ||
] | ||
}, | ||
"partitions":[ | ||
{ | ||
"treatment":"on", | ||
"size":0 | ||
}, | ||
{ | ||
"treatment":"off", | ||
"size":100 | ||
}, | ||
{ | ||
"treatment":"visa", | ||
"size":0 | ||
} | ||
], | ||
"label":"in segment all" | ||
} | ||
] | ||
} | ||
""" | ||
|
||
const val MOCK_DATA_LONG_TEXT = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dolor arcu, ultrices eget diam ut, tincidunt rhoncus felis. Suspendisse vel libero nec risus tincidunt ultricies. Aenean a vulputate nulla, a viverra enim. Phasellus volutpat magna quam, non ultrices lorem facilisis id. Morbi ultrices est augue. Integer interdum nisi at erat molestie auctor. Donec in diam vel sapien tincidunt luctus.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/androidTest/java/tests/database/ExclusiveTransactionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package tests.database | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import io.split.android.client.storage.db.SplitEntity | ||
import io.split.android.client.storage.db.SplitRoomDatabase | ||
import io.split.android.client.storage.db.attributes.AttributesEntity | ||
import org.junit.Before | ||
import org.junit.Test | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
import kotlin.test.fail | ||
|
||
class ExclusiveTransactionTest { | ||
|
||
private lateinit var db: SplitRoomDatabase | ||
|
||
@Before | ||
fun setUp() { | ||
db = SplitRoomDatabase.getDatabase( | ||
InstrumentationRegistry.getInstrumentation().context, | ||
"test_db" | ||
) | ||
} | ||
|
||
@Test | ||
fun transactionPreventsReads() { | ||
val writeFinished = AtomicBoolean(false) | ||
val readFinished = AtomicBoolean(false) | ||
|
||
// Insert multiple values in multiple DAOs inside a transaction | ||
val updateThread = Thread() { | ||
db.runInTransaction { | ||
for (i in 0..400) { | ||
db.splitDao().insert( | ||
SplitEntity().apply { | ||
name = "split${i}" | ||
body = "body${i}" | ||
updatedAt = System.currentTimeMillis() | ||
} | ||
) | ||
|
||
db.attributesDao().update( | ||
AttributesEntity().apply { | ||
userKey = "key${i}" | ||
attributes = "value${i}" | ||
} | ||
) | ||
} | ||
writeFinished.set(true) | ||
} | ||
} | ||
|
||
// Read values from multiple DAOs | ||
val readThread = Thread() { | ||
db.splitDao().all | ||
db.attributesDao().all | ||
readFinished.set(true) | ||
} | ||
|
||
// Monitor the operations | ||
val monitorThread = Thread() { | ||
while (true) { | ||
if (readFinished.get() && !writeFinished.get()) { | ||
fail("Values were read before update was done") | ||
} else if (writeFinished.get() && readFinished.get()) { | ||
break | ||
} | ||
} | ||
} | ||
|
||
monitorThread.start() | ||
readThread.start() | ||
updateThread.start() | ||
|
||
monitorThread.join(2000) | ||
readThread.join(2000) | ||
updateThread.join(2000) | ||
} | ||
} |
Oops, something went wrong.