diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f06a896..56de011 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,6 +39,17 @@ jobs: java-version: '17' cache: maven + # Maven Central drops connections at times: the dependencies and plugins of the build are downloaded first + # and again after a failure, not when the tests ran already + - name: Download the dependencies and plugins + shell: bash + run: | + for attempt in 1 2 3; do + ./mvnw -B -ntp dependency:go-offline dependency:unpack@unpack-javafx && exit 0 + sleep 30 + done + exit 1 + # The databases start while SqlJam is compiled - name: Build and test against the main databases (UI tests run headless) run: | @@ -75,6 +86,17 @@ jobs: java-version: '17' cache: maven + # Maven Central drops connections at times: the dependencies and plugins of the build are downloaded first + # and again after a failure, not when the tests ran already + - name: Download the dependencies and plugins + shell: bash + run: | + for attempt in 1 2 3; do + ./mvnw -B -ntp dependency:go-offline dependency:unpack@unpack-javafx && exit 0 + sleep 30 + done + exit 1 + - name: Build and test (UI tests run headless) shell: bash run: ./mvnw -B -ntp verify -Dit.env=ci -Djacoco.haltOnFailure=false @@ -122,7 +144,7 @@ jobs: run: | $wix = Join-Path $env:RUNNER_TEMP "wix" Invoke-WebRequest -Uri "https://github.com/wixtoolset/wix3/releases/download/wix3141rtm/wix314-binaries.zip" ` - -OutFile "$wix.zip" + -OutFile "$wix.zip" -MaximumRetryCount 5 -RetryIntervalSec 15 Expand-Archive -Path "$wix.zip" -DestinationPath $wix $wix | Out-File -FilePath $env:GITHUB_PATH -Append -Encoding utf8 diff --git a/src/main/java/com/github/sqljam/face/view/SqlCompletion.java b/src/main/java/com/github/sqljam/face/view/SqlCompletion.java index 00db8d0..d1b9252 100644 --- a/src/main/java/com/github/sqljam/face/view/SqlCompletion.java +++ b/src/main/java/com/github/sqljam/face/view/SqlCompletion.java @@ -219,7 +219,11 @@ private void showMenu(Context context, List names) { if (caret.isPresent()) { menu.show(area, caret.get().getMinX(), caret.get().getMaxY()); } else { + // No place on the screen while the editor is not shown, e.g. its tab is closed meanwhile Bounds bounds = area.localToScreen(area.getBoundsInLocal()); + if (bounds == null) { + return; + } menu.show(area, bounds.getMinX(), bounds.getMinY()); } // The first suggestion is chosen by Enter diff --git a/src/test/java/com/github/sqljam/face/view/SqlCompletionTest.java b/src/test/java/com/github/sqljam/face/view/SqlCompletionTest.java index edcd89e..f07978a 100644 --- a/src/test/java/com/github/sqljam/face/view/SqlCompletionTest.java +++ b/src/test/java/com/github/sqljam/face/view/SqlCompletionTest.java @@ -16,6 +16,7 @@ package com.github.sqljam.face.view; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -136,4 +137,30 @@ public List columns(String table) { }); assertEquals("SELECT", FxTestSupport.call(editor::getText)); } + + /** + * An editor which is not shown, e.g. its tab is closed while the names are read, opens no menu + */ + @Test + void showsNothingForEditorNotShown() { + AtomicInteger tableReads = new AtomicInteger(); + SqlEditor hidden = FxTestSupport.call(SqlEditor::new); + SqlCompletion completion = FxTestSupport.call(() -> SqlCompletion.attach(hidden, new SqlCompletion.Source() { + @Override + public List tables() { + tableReads.incrementAndGet(); + return List.of("orders"); + } + + @Override + public List columns(String table) { + return List.of(); + } + })); + FxTestSupport.run(completion::show); + FxTestSupport.waitUntil(() -> tableReads.get() == 1); + // After the names are handed to the FX thread + org.testfx.util.WaitForAsyncUtils.waitForFxEvents(); + assertFalse(FxTestSupport.call(completion.getMenu()::isShowing)); + } } diff --git a/src/test/java/com/github/sqljam/face/view/SqlTabTest.java b/src/test/java/com/github/sqljam/face/view/SqlTabTest.java index 48e0a4e..e9a7d54 100644 --- a/src/test/java/com/github/sqljam/face/view/SqlTabTest.java +++ b/src/test/java/com/github/sqljam/face/view/SqlTabTest.java @@ -351,6 +351,9 @@ void switchesBeforeFirstStatement() throws Exception { @Test void completesTablesAndColumns() { open(schemaNode()); + // The editor is in the window after the tab pane lays out its new tab, slow machines take a while + FxTestSupport.waitUntil(() -> FxTestSupport.call(() -> tab.getEditor().getCodeArea().localToScreen(0, 0) + != null)); type("SELECT * FROM T_O", 17); FxTestSupport.run(() -> tab.getEditor().getCodeArea().requestFocus()); FxTestSupport.run(() -> javafx.event.Event.fireEvent(tab.getEditor().getCodeArea(), new javafx.scene.input