Skip to content
This repository was archived by the owner on Oct 31, 2022. It is now read-only.

Commit 5b953d6

Browse files
authored
Merge pull request #155 from OneSignal/fix/jvm_memory_issue_with_tests
Fix jvm memory issue with tests
2 parents 024e3f1 + 0ada42b commit 5b953d6

File tree

4 files changed

+129
-101
lines changed

4 files changed

+129
-101
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ before_script:
1717
- yes | sdkmanager "platforms;android-27"
1818
- chmod +x gradlew
1919
script:
20-
- ./gradlew build
20+
- ./gradlew test --tests "com.onesignal.androidsdk.MainTest"
21+
- ./gradlew test --tests "com.onesignal.androidsdk.FullBuildTest"
2122
after_failure:
2223
- cat build/reports/lint-results.xml
2324
- cat build/outputs/lint-results-debug.xml
2425
- cd ../..
2526
- pwd
2627
- ls -la $HOME
27-
- ls -la $HOME/android-sdk
28+
- ls -la $HOME/android-sdk
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.onesignal.androidsdk
2+
3+
class AssertHelpers {
4+
static assertResults(results, Closure closure) {
5+
// 1.Ensure one or more results exist
6+
assert results
7+
8+
// 2. Ensure we don't have any failures
9+
results.each {
10+
assert !it.value.contains('FAILED')
11+
}
12+
13+
// 3. Run test specific asserts
14+
results.each {
15+
closure(it)
16+
}
17+
}
18+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.onesignal.androidsdk
2+
3+
import spock.lang.Specification
4+
5+
// These tests are slow (about 20 second each) as they are doing a full build as an end-to-end test
6+
// Note: This test file should be run on it's own due to Gradle 7 + JVM 8 memory issues
7+
class FullBuildTest extends Specification {
8+
static def GRADLE_LATEST_VERSION = GradleTestTemplate.GRADLE_LATEST_VERSION
9+
static def GRADLE_OLDEST_VERSION = GradleTestTemplate.GRADLE_OLDEST_VERSION
10+
11+
// Before each test
12+
def setup() {
13+
GradleTestTemplate.setup()
14+
}
15+
16+
static assertResults(results, Closure closure) {
17+
AssertHelpers.assertResults(results, closure)
18+
}
19+
20+
def runGradleProject(params) {
21+
GradleTestTemplate.runGradleProject(params)
22+
}
23+
24+
// This is needed as we are making sure compile and runtime versions are not being miss aligned
25+
// Asserts just a double check as Gradle or AGP fails to build when this happens
26+
def "Upgrade to compatible OneSignal SDK when targetSdkVersion is 26 with build tasks"() {
27+
GradleTestTemplate.buildArgumentSets = [
28+
'6.7.1': [['build']]
29+
]
30+
GradleTestTemplate.gradleVersions['6.7.1'] = 'com.android.tools.build:gradle:4.1.1'
31+
32+
when:
33+
def results = runGradleProject([
34+
compileSdkVersion: 26,
35+
targetSdkVersion: 26,
36+
compileLines: "compile 'com.onesignal:OneSignal:3.5.+'"
37+
])
38+
39+
then:
40+
assert results // Asserting existence and contains 1+ entries
41+
}
42+
43+
def 'Full build on project with sub project prints no errors'() {
44+
GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['build']]
45+
46+
when:
47+
def results = runGradleProject([
48+
skipGradleVersion: GRADLE_OLDEST_VERSION,
49+
subProjectCompileLines: """\
50+
compile 'com.onesignal:OneSignal:3.6.4'
51+
"""
52+
])
53+
54+
then:
55+
assertResults(results) {
56+
assert !it.value.toLowerCase().contains('failure')
57+
}
58+
}
59+
60+
// This test is designed to fail with new Google releases
61+
// - This is a flag to know we need to make a change in this plugin to resolve version conflicts
62+
// Run manually search for "Warning:".
63+
def 'Find min-support for Firebase and GMS - build'() {
64+
GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['build']]
65+
when:
66+
// Keep as '+' for latest when checking in to this fails when Google changes requirements
67+
def results = runGradleProject([
68+
'android.useAndroidX': true,
69+
compileLines: """
70+
compile 'com.google.android.gms:play-services-ads:+'
71+
compile 'com.google.android.gms:play-services-base:+'
72+
compile 'com.google.android.gms:play-services-location:+'
73+
// compile 'com.onesignal:OneSignal:[3.11.1, 3.99.99]' // TODO: Need to fix, see note below
74+
""",
75+
skipGradleVersion: GRADLE_OLDEST_VERSION
76+
])
77+
// NOTE: There is a mix between AndroidX and the Android Support Library.
78+
// One to this test may cause duplicated or missing classes with either of these
79+
// Might need to follow the AndroidX migration guide to fix and re-add support library
80+
81+
then:
82+
assert results // Assert success
83+
}
84+
85+
// Run manually search for "Warning:".
86+
// If a support library class is listed
87+
// then the support library needs to be updated for the firebase / GMS version
88+
def 'test core and messaging - build'() {
89+
// Other run options that can be manually run to help debug the issue
90+
// GradleTestTemplate.buildArgumentSets[GRADLE_OLDEST_VERSION] = [['checkReleaseDuplicateClasses', '--info']]
91+
// GradleTestTemplate.buildArgumentSets[GRADLE_OLDEST_VERSION] = [['transformClassesAndResourcesWithProguardForDebug', '--info']]
92+
// GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['dependencies', '--configuration', 'debugCompileClasspath', '--info']]
93+
GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['build']] // , '--info']]
94+
when:
95+
def results = runGradleProject([
96+
compileLines: """
97+
implementation 'com.google.android.gms:play-services-base:15.0.1'
98+
implementation 'com.google.android.gms:play-services-basement:17.4.0'
99+
""",
100+
skipGradleVersion: GRADLE_OLDEST_VERSION,
101+
'android.useAndroidX': true,
102+
])
103+
104+
then:
105+
assert results // Assert success
106+
}
107+
}

src/test/groovy/com/onesignal/androidsdk/MainTest.groovy

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,7 @@ class MainTest extends Specification {
1919
}
2020

2121
static assertResults(results, Closure closure) {
22-
// 1.Ensure one or more results exist
23-
assert results
24-
25-
// 2. Ensure we don't have any failures
26-
results.each {
27-
assert !it.value.contains('FAILED')
28-
}
29-
30-
// 3. Run test specific asserts
31-
results.each {
32-
closure(it)
33-
}
22+
AssertHelpers.assertResults(results, closure)
3423
}
3524

3625
// This version range is in the OneSignal instructions
@@ -1177,44 +1166,6 @@ class MainTest extends Specification {
11771166
}
11781167
}
11791168

1180-
// Note: Slow 20 second test, this is doing a full build
1181-
// This is needed as we are making sure compile and runtime versions are not being miss aligned
1182-
// Asserts just a double check as Gradle or AGP fails to build when this happens
1183-
def "Upgrade to compatible OneSignal SDK when targetSdkVersion is 26 with build tasks"() {
1184-
GradleTestTemplate.buildArgumentSets = [
1185-
'6.7.1': [['build']]
1186-
]
1187-
GradleTestTemplate.gradleVersions['6.7.1'] = 'com.android.tools.build:gradle:4.1.1'
1188-
1189-
when:
1190-
def results = runGradleProject([
1191-
compileSdkVersion: 26,
1192-
targetSdkVersion: 26,
1193-
compileLines: "compile 'com.onesignal:OneSignal:3.5.+'"
1194-
])
1195-
1196-
then:
1197-
assert results // Asserting existence and contains 1+ entries
1198-
}
1199-
1200-
1201-
// Note: Slow 20 second test, this is doing a full build
1202-
def 'Full build on project with sub project prints no errors'() {
1203-
GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['build']]
1204-
1205-
when:
1206-
def results = runGradleProject([
1207-
skipGradleVersion: GRADLE_OLDEST_VERSION,
1208-
subProjectCompileLines: """\
1209-
compile 'com.onesignal:OneSignal:3.6.4'
1210-
"""
1211-
])
1212-
1213-
then:
1214-
assertResults(results) {
1215-
assert !it.value.toLowerCase().contains('failure')
1216-
}
1217-
}
12181169
def 'upgrade support library to 25 when gms is 11.2.0'() {
12191170
def compileLines = """\
12201171
compile 'com.google.android.gms:play-services-base:11.2.0'
@@ -1306,7 +1257,6 @@ class MainTest extends Specification {
13061257
}
13071258
}
13081259

1309-
13101260
// Note: Run manually to find the min compileSdkVersion for each support version
13111261
def 'Find min-support version for compileSdkVersion'() {
13121262
GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['compileDebugSources']]
@@ -1324,52 +1274,4 @@ class MainTest extends Specification {
13241274
then:
13251275
assert results // Asserting existence and contains 1+ entries
13261276
}
1327-
1328-
// This test is designed to fail with new Google releases
1329-
// - This is a flag to know we need to make a change in this plugin to resolve version conflicts
1330-
// Run manually search for "Warning:".
1331-
def 'Find min-support for Firebase and GMS - build'() {
1332-
GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['build']]
1333-
when:
1334-
// Keep as '+' for latest when checking in to this fails when Google changes requirements
1335-
def results = runGradleProject([
1336-
'android.useAndroidX': true,
1337-
compileLines: """
1338-
compile 'com.google.android.gms:play-services-ads:+'
1339-
compile 'com.google.android.gms:play-services-base:+'
1340-
compile 'com.google.android.gms:play-services-location:+'
1341-
// compile 'com.onesignal:OneSignal:[3.11.1, 3.99.99]' // TODO: Need to fix, see note below
1342-
""",
1343-
skipGradleVersion: GRADLE_OLDEST_VERSION
1344-
])
1345-
// NOTE: There is a mix between AndroidX and the Android Support Library.
1346-
// One to this test may cause duplicated or missing classes with either of these
1347-
// Might need to follow the AndroidX migration guide to fix and re-add support library
1348-
1349-
then:
1350-
assert results // Assert success
1351-
}
1352-
1353-
// Run manually search for "Warning:".
1354-
// If a support library class is listed
1355-
// then the support library needs to be updated for the firebase / GMS version
1356-
def 'test core and messaging - build'() {
1357-
// Other run options that can be manually run to help debug the issue
1358-
// GradleTestTemplate.buildArgumentSets[GRADLE_OLDEST_VERSION] = [['checkReleaseDuplicateClasses', '--info']]
1359-
// GradleTestTemplate.buildArgumentSets[GRADLE_OLDEST_VERSION] = [['transformClassesAndResourcesWithProguardForDebug', '--info']]
1360-
// GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['dependencies', '--configuration', 'debugCompileClasspath', '--info']]
1361-
GradleTestTemplate.buildArgumentSets[GRADLE_LATEST_VERSION] = [['build']] // , '--info']]
1362-
when:
1363-
def results = runGradleProject([
1364-
compileLines: """
1365-
implementation 'com.google.android.gms:play-services-base:15.0.1'
1366-
implementation 'com.google.android.gms:play-services-basement:17.4.0'
1367-
""",
1368-
skipGradleVersion: GRADLE_OLDEST_VERSION,
1369-
'android.useAndroidX': true,
1370-
])
1371-
1372-
then:
1373-
assert results // Assert success
1374-
}
13751277
}

0 commit comments

Comments
 (0)