Skip to content

Commit

Permalink
Limit integration tests to 100 runs per Gradle daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith committed Jul 22, 2023
1 parent d315f47 commit 29a279b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ org.gradle.daemon.idletimeout=1800000

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
#
# Chaquopy: the default from the new project wizard is 2048, but we had to increase it
# because of intermittent OutOfMemoryErrors with AGP 8.0.0-rc01. No reports yet of this
# affecting any users, so it's probably just because we're reusing the daemon to build
# many different projects, and exposing a leak somewhere.
org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
Expand Down
27 changes: 24 additions & 3 deletions product/gradle-plugin/src/test/integration/test_gradle_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,15 @@ def test_variant_merge(self):


class RunGradle(object):
# With AGP 8.0 on Windows, the full test run sometimes causes OutOfMemoryErrors.
# Editing gradle.properties to increase -Xmx to 4096m was enough to work around this
# locally, but we still had native crashes in CI towards the end of the run. No
# reports yet of this affecting any users, so it's probably just because we're
# reusing the daemon to build many different projects, and exposing a leak
# somewhere. So set a limit to the number of times we reuse it.
MAX_RUNS_PER_DAEMON = 100
runs_per_daemon = 0

def __init__(self, test, *layers, run=True, **kwargs):
self.test = test
if os.path.exists(test.run_dir):
Expand Down Expand Up @@ -1494,6 +1503,11 @@ def apply_layers(self, *layers):

def rerun(self, *layers, succeed=True, variants=["debug"], env=None, add_path=None,
**kwargs):
if RunGradle.runs_per_daemon >= RunGradle.MAX_RUNS_PER_DAEMON:
run([self.gradlew_path, "--stop"], cwd=self.project_dir, check=True)
RunGradle.runs_per_daemon = 0
RunGradle.runs_per_daemon += 1

self.apply_layers(*layers)

# In Android Studio Bumblebee and later, the new project wizard sets all plugin
Expand Down Expand Up @@ -1575,6 +1589,9 @@ def run_gradle(self, variants, env, java_version):
# daemon (https://github.com/gradle/gradle/issues/12905). On the other
# platforms, this only affects specific variables such as PATH and TZ
# (https://github.com/gradle/gradle/issues/10483).
#
# TODO: avoid this by changing as many tests as possible to use
# gradle.properties instead.
gradlew_flags.append("--no-daemon")

# The following environment variables aren't affected by the above issue, either
Expand All @@ -1586,13 +1603,17 @@ def run_gradle(self, variants, env, java_version):
"JAVA_HOME": product_props[f"chaquopy.java.home.{java_version}"],
}

process = run([join(self.project_dir,
"gradlew.bat" if (os.name == "nt") else "gradlew")] +
gradlew_flags + [task_name("assemble", v) for v in variants],
process = run([self.gradlew_path] + gradlew_flags +
[task_name("assemble", v) for v in variants],
cwd=self.project_dir, # See Windows notes for add_path above.
capture_output=True, text=True, env=merged_env, timeout=600)
return process.returncode, process.stdout, process.stderr

@property
def gradlew_path(self):
return join(self.project_dir,
"gradlew.bat" if (os.name == "nt") else "gradlew")

def check_apk(self, variant, kwargs):
apk_zip, apk_dir = self.get_output("app", variant, "apk")
self.test.pre_check(self, apk_dir, kwargs)
Expand Down

0 comments on commit 29a279b

Please sign in to comment.