From 00d7b66454dd1cca12014f2f76b1277dfb6c3149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Papp=20=28TWiStErRob=29?= Date: Wed, 10 Aug 2022 13:11:35 +0100 Subject: [PATCH] Rewire HtmlReportTaskTest --- .../quality/tasks/HtmlReportTaskTest.kt | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/quality/src/test/kotlin/net/twisterrob/gradle/quality/tasks/HtmlReportTaskTest.kt b/quality/src/test/kotlin/net/twisterrob/gradle/quality/tasks/HtmlReportTaskTest.kt index 13a826ad2..ff0df87e0 100644 --- a/quality/src/test/kotlin/net/twisterrob/gradle/quality/tasks/HtmlReportTaskTest.kt +++ b/quality/src/test/kotlin/net/twisterrob/gradle/quality/tasks/HtmlReportTaskTest.kt @@ -281,13 +281,16 @@ class HtmlReportTaskTest : BaseIntgTest() { @Test fun `task is capable of handling huge number of violations`() { gradle.basedOn("android-root_app") gradle.basedOn("lint-UnusedResources") + val count = 3000 @Language("gradle") val script = """ + dumpMemory("starting build") apply plugin: 'org.gradle.reporting-base' - File xml = project.file("build/report.xml") - tasks.register('htmlReport', ${HtmlReportTask::class.java.name}) { - inputs.file(xml) + File xml = project.file("build/reports/lint-results-debug.xml") + def generate = tasks.register('generateBigReport') { + outputs.file(xml) doFirst { + dumpMemory("starting generation") xml.text = '' xml.withWriterAppend { writer -> // Note: I tried to estimate the number of violations to create by measuring free memory: @@ -295,7 +298,7 @@ class HtmlReportTaskTest : BaseIntgTest() { // After many tries and empirical measurements, it was still flaky on each execution on GitHub. // Since then I bumped Xmx from 128 to 256 and the count from 1500 to 3000. // This should be stable and catch any regressions, if the processing goes non-linear. - 3000.times { + $count.times { writer.write( '') + dumpMemory("finished generation") } } - - android.lintOptions { - //noinspection GroovyAssignabilityCheck - check = ['UnusedResources'] - xmlOutput = xml + tasks.register('htmlReport', ${HtmlReportTask::class.java.name}) { + dependsOn(generate) + doFirst { dumpMemory("starting report") } + doLast { dumpMemory("finished report") } + } + afterEvaluate { dumpMemory("executing build") } + + static void dumpMemory(String message) { + def rt = Runtime.getRuntime() + 3.times { rt.gc() } + println(message + ": free=" + rt.freeMemory() + " max=" + rt.maxMemory() + " total=" + rt.totalMemory()) } """.trimIndent() gradle.propertiesFile @@ -321,11 +331,13 @@ class HtmlReportTaskTest : BaseIntgTest() { val result = assertTimeoutPreemptively(ofMinutes(2), ThrowingSupplier { gradle.runBuild { - run(script, "lint", "htmlReport") + run(script, "generateBigReport", "htmlReport") } }) assertEquals(TaskOutcome.SUCCESS, result.task(":htmlReport")!!.outcome) + val violationsReport = gradle.violationsReport("html").readText() + assertEquals(count, """