Fix for testPreTrusted gradle test failing on CI #3479
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR attempts to fix gradle test suite that is randomly failing just on CI. The root cause is that obviously I've written the test wrong ;) the original idea was to test what will happen if:
Since I didn't want to bring all the NbModuleSuite machinery, the test just moved the original project, created a copy == new
FileObject
and opened the project again. New FileObject means new Project.But some Gradle caches rely on
j.io.File
, not FileObjects, so at this point theprj2
was a new instance, but itsGradleFiles
key into the cache was the same as theprj
key...... so the project info was found in the cache loaded, and was returned. And the test was failing because sometimes the timestamps of the copied files were different from the timestamps of the in-memory loaded cache data, if CI was lucky to execute the two project loads in different seconds. Then the cache failed, and legacy project loader did not execute the script because it should not do so implicitly on open, but only when (somehow) asked to load the real contents - that is intended and is being tested in Gradle core testsuite.
So I split the test into two cases:
I need to flush the project info cache from the test, and potentially delete the cache data for project
During the debugging, I've noticed that access to the disk cache was not synchronized and while that did not cause the test failures, it could cause weird things in production (as the hashtable may become corrupted).
I've also encountered a deadlock caused by
toString()
was trying to synchronize on the project's instance. If the project object was just being formatted by a LogHandler, and some other thread was trying to use Logger insynchronized
section using that same project instance, the two threads would block each other.Then there was a nasty typo that caused the
CompletableFuture
NOT to complete on success - and therefore Source Groups [were not refreshed[(https://github.com/apache/netbeans/blob/master/java/gradle.java/src/org/netbeans/modules/gradle/java/classpath/ClassPathProviderImpl.java#L159) after project load. This typo was not even noticed by tests ! So I added checks forjava2
directory that should appear after full load inClassPath.SOURCE
.I left some logging tweaks in the test class: it enables FINER logging for the test that was randomly failing, so if this PR does not fix the problem, CI logs will hopefully contain some hints to analyse. I'll remove the setLevel later after the fix proves OK.