Closed lukas-mercari closed 1 month ago
Thanks to the output from this PR, I discovered a bug that our integration tests had not covered. Therefore, I added tests and reverted the removal of test task inputs. https://github.com/takahirom/roborazzi/pull/364
We might be able to modify the input dir for either recording or for comparing and verifying.
@takahirom Nice, thanks for adding the test and reverting the change! Indeed, after looking at it again it seems that making the cache work isn't going to be as simple as we had hoped.
The other problem that I ran into (why I started to make changes) was that even with the caching enabled we relied on copying files from the intermediate dir to the output dir. In my local runs, isTestSkipped
was not always detected correctly, so sometimes the output dir ended up being empty. (Maybe due to the configuration cache?)
We might need to add additional logs for further investigation.
Yes, I added some locally and it seemed that TestTaskSkipEventsServiceProvider.expectingTestNames
wasn't initialised properly. (So, the skipped test run never gets added to skippedTestTaskMap
.)
Thanks. I'm thinking of removing TestTaskSkipEventsServiceProvider and isTestSkipped. Consistency is more important, and I don't think the copy operation is that heavy of a task. What do you think about this?
// if (isTestSkipped) {
// If the test is skipped, we need to use cached files
val startCopy = System.currentTimeMillis()
intermediateDir.get().asFile.mkdirs()
intermediateDir.get().asFile.copyRecursively(
target = outputDir.get().asFile,
overwrite = true
)
finalizeTestTask.infoln("Roborazzi: finalizeTestRoborazziTask Copy files from ${intermediateDir.get()} to ${outputDir.get()} end ${System.currentTimeMillis() - startCopy}ms")
// }
I'll make a PR to check integration tests
@takahirom Sorry for the late reply. I found some time to do a bit more research today.
build/outputs/roborazzi
not being restored from cacheSince #364 I got the following error instead:
* What went wrong:
A problem was found with the configuration of task ':sample-android:testDebugUnitTest' (type 'AndroidUnitTest').
- Type 'com.android.build.gradle.tasks.factory.AndroidUnitTest' property '$1' specifies directory '/Users/lukas/Dev/test/roborazzi/sample-android/build/outputs/roborazzi' which doesn't exist.
Reason: An input file was expected to be present but it doesn't exist.
Possible solutions:
1. Make sure the directory exists before the task is called.
2. Make sure that the task which produces the directory is declared as an input.
For more information, please refer to https://docs.gradle.org/8.4/userguide/validation_problems.html#input_file_does_not_exist in the Gradle documentation.
It's a bit hard to reproduce, since I believe the configuration cache needs to kick in, but the steps are roughly:
// Make a change to the tests in `sample-android`.
./gradlew :sample-android:recordRoborazziDebug --build-cache
rm -rf ./sample-android/build
./gradlew :sample-android:recordRoborazziDebug --build-cache
rm -rf ./sample-android/build
./gradlew :sample-android:recordRoborazziDebug --build-cache
I think the error is essentially what is described in this issue: https://github.com/gradle/gradle/issues/2016 I made a fix like this, and this brought back the problem with restoring the output directory instead. (Edit: It doesn't seem to be working well in all cases though -- see #374.) Finally #366 fixes that issue.
It seems that we cannot read isRecordRun
in configureEach
:
> Could not create task ':sample-android:testDebugUnitTest'.
> Cannot query the value of this property because it has no value available`.
We could read test.systemProperties["roborazzi.test.record"]
directly, but in that case the caching behaviour would only change when the user runs testDebugUnitTest
directly (and not using recordRoborazziDebug
).
I'm a bit out of ideas on how to approach this -- this seems to be a general limitation in the interaction between gradle and how our tasks are set up. (E.g. paparazzi seems to have the problem reversed since they don't declare the output dir as an input.)
Thank you as always for your work and release 1.16.0! When there were no changes affecting screenshot tests, it reduced the CI/CD build time of the VRT task to about 30% of what it used to be. 👏
I noticed one problem when I was checking with a local cache. This can be reproduced using the following commands:
It seems that there is some flakiness when restoring screenshots from the intermediate to the output dir. This was added in #128 (but it's not immediate clear to me why it was needed).