Skip to content

Commit

Permalink
added qsync integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
LeFrosch committed Dec 2, 2024
1 parent c0bf80c commit cab06ca
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clwb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ clwb_integration_test(
srcs = ["tests/integrationtests/com/google/idea/blaze/clwb/ExternalIncludesTest.java"],
)

clwb_integration_test(
name = "query_sync_integration_test",
project = "simple",
srcs = ["tests/integrationtests/com/google/idea/blaze/clwb/QuerySyncTest.java"],
)

test_suite(
name = "integration_tests",
tests = [
Expand Down
3 changes: 3 additions & 0 deletions clwb/test_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def clwb_integration_test(name, project, srcs, deps = []):
"-Dcom.google.testing.junit.runner.shouldInstallTestSecurityManager=false",
# fixes preferences not writable on mac
"-Djava.util.prefs.PreferencesFactory=com.google.idea.blaze.clwb.base.InMemoryPreferencesFactory",
# define the path to the query sync aspects
"-Dblaze.idea.build_dependencies.bzl.file=aspect/build_dependencies.bzl",
"-Dblaze.idea.build_dependencies_deps.bzl.file=aspect/build_dependencies_deps.bzl",
],
deps = deps + [
":clwb_lib",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.google.idea.blaze.clwb;

import static com.google.common.truth.Truth.assertThat;
import static com.google.idea.blaze.clwb.base.Assertions.assertContainsHeader;

import com.google.idea.blaze.clwb.base.BazelVersionRule;
import com.google.idea.blaze.clwb.base.ClwbIntegrationTestCase;
import com.google.idea.blaze.clwb.base.OSRule;
import com.intellij.util.system.OS;
import java.util.concurrent.ExecutionException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class QuerySyncTest extends ClwbIntegrationTestCase {

// currently query sync only works on linux, TODO: fix mac and windows
@Rule
public final OSRule osRule = new OSRule(OS.Linux);

// query sync requires bazel 6+
@Rule
public final BazelVersionRule bazelRule = new BazelVersionRule(6, 0);

@Test
public void testClwb() throws Exception {
final var success = runQuerySync();
assertThat(success).isTrue();

checkAnalysis();
checkCompiler();
}

private void checkAnalysis() throws ExecutionException {
final var success = enableAnalysisFor(findProjectFile("main/hello-world.cc"));
assertThat(success).isTrue();
}

private void checkCompiler() {
final var compilerSettings = findFileCompilerSettings("main/hello-world.cc");

// TODO: query sync selects the wrong compiler
// if (SystemInfo.isMac) {
// assertThat(compilerSettings.getCompilerKind()).isEqualTo(ClangCompilerKind.INSTANCE);
// } else if (SystemInfo.isLinux) {
// assertThat(compilerSettings.getCompilerKind()).isEqualTo(GCCCompilerKind.INSTANCE);
// } else if (SystemInfo.isWindows) {
// assertThat(compilerSettings.getCompilerKind()).isEqualTo(MSVCCompilerKind.INSTANCE);
// }

assertContainsHeader("iostream", compilerSettings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import static com.google.common.truth.Truth.assertThat;

import com.google.idea.blaze.base.async.process.ExternalTask;
import com.google.idea.blaze.base.logging.utils.querysync.QuerySyncActionStatsScope;
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
import com.google.idea.blaze.base.project.AutoImportProjectOpenProcessor;
import com.google.idea.blaze.base.project.ExtendableBazelProjectCreator;
import com.google.idea.blaze.base.projectview.ProjectView;
import com.google.idea.blaze.base.projectview.ProjectViewSet;
import com.google.idea.blaze.base.projectview.section.sections.TextBlock;
import com.google.idea.blaze.base.projectview.section.sections.TextBlockSection;
import com.google.idea.blaze.base.qsync.QuerySyncManager;
import com.google.idea.blaze.base.qsync.QuerySyncManager.TaskOrigin;
import com.google.idea.blaze.base.scope.BlazeContext;
import com.google.idea.blaze.base.settings.BlazeUserSettings;
import com.google.idea.blaze.base.settings.BuildSystemName;
Expand Down Expand Up @@ -248,6 +251,47 @@ protected BlazeSyncParams.Builder defaultSyncParams() {
.setAddProjectViewTargets(true);
}

protected boolean runQuerySync() {
final var future = QuerySyncManager.getInstance(myProject).onStartup(QuerySyncActionStatsScope.create(getClass(), null));

while (!future.isDone()) {
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue();
}

try {
return future.get();
} catch (ExecutionException e) {
fail("query sync failed " + e.getMessage());
} catch (InterruptedException e) {
fail("query sync was interrupted");
}

return false;
}

protected boolean enableAnalysisFor(VirtualFile file) throws ExecutionException {
final var manager = QuerySyncManager.getInstance(myProject);
final var targets = manager.getTargetsToBuild(file).targets();

final var future = manager.enableAnalysis(
targets,
QuerySyncActionStatsScope.createForFile(getClass(), null, file),
TaskOrigin.USER_ACTION
);

while (!future.isDone()) {
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue();
}

try {
return future.get();
} catch (InterruptedException e) {
fail("enable analysis was interrupted");
}

return false;
}

protected VirtualFile findProjectFile(String relativePath) {
final var file = myProjectRoot.findFileByRelativePath(relativePath);
assertThat(file).isNotNull();
Expand Down

0 comments on commit cab06ca

Please sign in to comment.