mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Improve ASTCacheTest timing
This commit is contained in:
parent
5638a8eeb6
commit
97b59aed2e
1 changed files with 36 additions and 25 deletions
|
@ -35,6 +35,8 @@ import org.eclipse.core.runtime.Path;
|
||||||
* Tests for the {@link ASTCache}.
|
* Tests for the {@link ASTCache}.
|
||||||
*/
|
*/
|
||||||
public class ASTCacheTests extends BaseTestCase {
|
public class ASTCacheTests extends BaseTestCase {
|
||||||
|
private final static boolean DEBUG= false;
|
||||||
|
|
||||||
private static int fgReconcilerCount;
|
private static int fgReconcilerCount;
|
||||||
|
|
||||||
public class MockReconciler extends Thread {
|
public class MockReconciler extends Thread {
|
||||||
|
@ -54,14 +56,18 @@ public class ASTCacheTests extends BaseTestCase {
|
||||||
try {
|
try {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
fCache.aboutToBeReconciled(fTU);
|
fCache.aboutToBeReconciled(fTU);
|
||||||
|
if (DEBUG) System.out.println("about ot reconcile "+fTU.getElementName());
|
||||||
fAST= null;
|
fAST= null;
|
||||||
notify();
|
notify();
|
||||||
}
|
}
|
||||||
Thread.sleep(100);
|
Thread.sleep(50);
|
||||||
|
IASTTranslationUnit ast= fCache.createAST(fTU, fIndex, null);
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
fAST= fCache.createAST(fTU, fIndex, null);
|
fAST= ast;
|
||||||
|
if (DEBUG) System.out.println("reconciled "+fTU.getElementName());
|
||||||
fCache.reconciled(fAST, fTU);
|
fCache.reconciled(fAST, fTU);
|
||||||
}
|
}
|
||||||
|
Thread.sleep(50);
|
||||||
} catch (InterruptedException exc) {
|
} catch (InterruptedException exc) {
|
||||||
fStopped= true;
|
fStopped= true;
|
||||||
break;
|
break;
|
||||||
|
@ -211,36 +217,32 @@ public class ASTCacheTests extends BaseTestCase {
|
||||||
Thread.sleep(50);
|
Thread.sleep(50);
|
||||||
reconciler2.start();
|
reconciler2.start();
|
||||||
try {
|
try {
|
||||||
int cacheHits= 0;
|
|
||||||
int iterations= 0;
|
int iterations= 0;
|
||||||
while (cacheHits < 4 && iterations < 10) {
|
while (iterations < 10) {
|
||||||
++iterations;
|
++iterations;
|
||||||
|
if (DEBUG) System.out.println("iteration="+iterations);
|
||||||
IASTTranslationUnit ast;
|
IASTTranslationUnit ast;
|
||||||
cache.setActiveElement(fTU1);
|
cache.setActiveElement(fTU1);
|
||||||
Thread.sleep(100);
|
Thread.sleep(50);
|
||||||
ast= cache.getAST(fTU1, fIndex, false, null);
|
ast = waitForAST(cache, fTU1);
|
||||||
if (ast != null) {
|
assertNotNull(ast);
|
||||||
assertSame(ast, reconciler1.fAST);
|
assertEquals("void foo1() {}", ast.getDeclarations()[0].getRawSignature());
|
||||||
++cacheHits;
|
|
||||||
} else {
|
ast = waitForAST(cache, fTU2);
|
||||||
ast= cache.getAST(fTU1, fIndex, true, null);
|
assertNotNull(ast);
|
||||||
assertNotNull(ast);
|
assertEquals("void foo2() {}", ast.getDeclarations()[0].getRawSignature());
|
||||||
assertEquals("void foo1() {}", ast.getDeclarations()[0].getRawSignature());
|
|
||||||
}
|
|
||||||
|
|
||||||
// change active element
|
// change active element
|
||||||
cache.setActiveElement(fTU2);
|
cache.setActiveElement(fTU2);
|
||||||
Thread.sleep(100);
|
Thread.sleep(50);
|
||||||
ast= cache.getAST(fTU1, fIndex, false, null);
|
ast = waitForAST(cache, fTU2);
|
||||||
if (ast != null) {
|
assertNotNull(ast);
|
||||||
assertSame(ast, reconciler2.fAST);
|
assertEquals("void foo2() {}", ast.getDeclarations()[0].getRawSignature());
|
||||||
++cacheHits;
|
|
||||||
} else {
|
ast = waitForAST(cache, fTU1);
|
||||||
ast= cache.getAST(fTU2, fIndex, true, null);
|
assertNotNull(ast);
|
||||||
assertNotNull(ast);
|
assertEquals("void foo1() {}", ast.getDeclarations()[0].getRawSignature());
|
||||||
assertEquals("void foo2() {}", ast.getDeclarations()[0].getRawSignature());
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
reconciler1.fStopped= true;
|
reconciler1.fStopped= true;
|
||||||
reconciler1.join(1000);
|
reconciler1.join(1000);
|
||||||
|
@ -249,4 +251,13 @@ public class ASTCacheTests extends BaseTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IASTTranslationUnit waitForAST(ASTCache cache, ITranslationUnit tUnit) {
|
||||||
|
if (DEBUG) System.out.println("waiting for "+tUnit.getElementName());
|
||||||
|
long start= System.currentTimeMillis();
|
||||||
|
IASTTranslationUnit ast;
|
||||||
|
ast= cache.getAST(tUnit, fIndex, true, null);
|
||||||
|
if (DEBUG) System.out.println("wait time= " + (System.currentTimeMillis() - start));
|
||||||
|
return ast;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue