Skip to content

Commit

Permalink
Fix call graph test regression now that population is async
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Aug 30, 2023
1 parent c83c10e commit d52dc59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ private void setActive(boolean active) {
}
}

/**
* @return Observable boolean tracking the state of the call-graph's parsing of the current workspace.
*/
@Nonnull
public ObservableBoolean isReady() {
return isReady;
}

/**
* @param classInfo
* Class to wrap.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package software.coley.recaf.services.callgraph;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import software.coley.observables.ObservableBoolean;
import software.coley.recaf.info.JvmClassInfo;
import software.coley.recaf.path.ClassPathNode;
import software.coley.recaf.test.TestClassUtils;
Expand All @@ -9,6 +11,7 @@
import software.coley.recaf.workspace.model.Workspace;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -17,6 +20,7 @@
*/
class CallGraphTest {
@Test
@Timeout(10)
void testCalleeCallerRelation() throws IOException {
Workspace workspace = TestClassUtils.fromBundle(TestClassUtils.fromClasses(
StringConsumer.class,
Expand All @@ -31,6 +35,15 @@ void testCalleeCallerRelation() throws IOException {
JvmClassInfo functionClass = pathFunc.getValue().asJvmClass();

CallGraph graph = new CallGraph(new CallGraphConfig(), workspace);

// Need to wait until async population of graph contents is done.
ObservableBoolean ready = graph.isReady();
assertDoesNotThrow(() ->{
while (!ready.getValue()) {
Thread.sleep(100);
}
});

ClassMethodsContainer containerMain = graph.getClassMethodsContainer(mainClass);
ClassMethodsContainer containerFunction = graph.getClassMethodsContainer(functionClass);

Expand Down

0 comments on commit d52dc59

Please sign in to comment.