-
Notifications
You must be signed in to change notification settings - Fork 874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix php tag fold test (attempt 2) #6665
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thank you for your work!
Document doc = source.getDocument(false); | ||
Document doc = source.getDocument(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@junichi11 would be good to observe this to check if it causes any performance issues.
It could be worth checking how often source.getDocument(false)
would be null here during regular project development. If its very often the case, we could try to solve this differently (e.g bullet point 1 of the PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbien
Or, change to true
only when we test?
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/csl/FoldingScanner.java b/php/php.editor/src/org/netbeans/modules/php/editor/csl/FoldingScanner.java
index fb565eb64a..730455feb3 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/csl/FoldingScanner.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/csl/FoldingScanner.java
@@ -141,6 +141,7 @@ public final class FoldingScanner {
private static final String LAST_CORRECT_FOLDING_PROPERTY = "LAST_CORRECT_FOLDING_PROPERY"; //NOI18N
private static final boolean FOLD_PHPTAG = !Boolean.getBoolean("nb.php.editor.doNotFoldPhptag"); // NOI18N NETBEANS-5480
+ static volatile boolean IS_UNIT_TEST = false;
public static FoldingScanner create() {
return new FoldingScanner();
@@ -179,7 +180,8 @@ public final class FoldingScanner {
program.accept(new FoldingVisitor(folds));
Source source = phpParseResult.getSnapshot().getSource();
assert source != null : "source was null";
- Document doc = source.getDocument(true);
+ // avoid getting `null` in unit testing
+ Document doc = source.getDocument(IS_UNIT_TEST);
if (FOLD_PHPTAG) {
processPHPTags(folds, doc);
}
diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/FoldingTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/FoldingTest.java
index 083d201589..b7ad8a515c 100644
--- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/FoldingTest.java
+++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/FoldingTest.java
@@ -30,6 +30,12 @@ public class FoldingTest extends PHPTestBase {
super(testName);
}
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ FoldingScanner.IS_UNIT_TEST = true;
+ }
+
public void testFoldingMethod() throws Exception {
checkFolds("testfiles/parser/foldingMethod.php");
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes but making the program aware of the test is always a bit ugly. The program should, if possible, never know that it is tested so that the results are the same as in real world. This is also a valid option but I would try to use it only if we really have to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Perhaps, someone would report performance issues if there are them :) Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but something weird is happening here, we might have to revert this:
both micronaut and LSP jobs are failing after this merge and I can't get them green again. I can reproduce it locally, if i set back to false, MicronautGradleArtifactsImplTest
is green, true makes it red...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, there is something else going on, I try to debug it here: mbien#1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this has likely nothing to do with this PR or any recent PRs, both micronaut and LSP tests which fail use gradle which is suspicious, the runner images, jdk version, everything remained unchanged since the last successful build on master)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Thanks!
thanks for review - merging for now to check if it helps. |
The race condition strikes back!
This particular php tests requires too many restarts, I can't stabilize master at all atm:
netbeans/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/FoldingTest.java
Line 88 in 0c8313e
So I took another look at #5658, and I believe all I did back then was to change the timing without fixing the underlying issue. My mistake was to think that
getSource().getDocument(true)
would hold the document internally for the nextgetDocument(false)
call - but this is not the case. So all the last "fix" did was to read a document and forget about it again, the timing however helped the tests to pass.This is also annoying to debug since this usually works when the debugger is attached.
So I think there are two obvious ways how to fix this:
Source.getDocument(true)
for subsequentSource.getDocument(false)
calls, and eager load the document in the test like attempted in 5658Source.getDocument(true)
inFoldingScanner
(might potentially have an performance impact)PR implements currently the second option