From 2b64bd16205bf6858b17cfa89172bf73992308d4 Mon Sep 17 00:00:00 2001 From: Ryan Dowling Date: Sat, 15 Jul 2023 09:40:00 +1000 Subject: [PATCH] fix: ui tests failing constantly --- .editorconfig | 6 ++++ .github/workflows/application.yml | 28 +++++++++---------- .github/workflows/aur-publish.yml | 4 +-- .vscode/settings.json | 5 +++- CHANGELOG.md | 3 +- src/main/java/com/atlauncher/App.java | 12 ++++++++ src/main/java/com/atlauncher/Network.java | 3 +- .../gui/tabs/accounts/AccountsTab.java | 2 -- src/test/java/ui/AbstractUiTest.java | 3 +- src/test/java/ui/BasicLauncherUiTest.java | 5 +--- src/test/java/ui/mocks/MockHelper.java | 9 ++++++ .../mocks/download-nodecdn-net/config.json | 1 + .../download-nodecdn-net/java_runtimes.json | 11 ++++++++ 13 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 src/test/resources/mocks/download-nodecdn-net/java_runtimes.json diff --git a/.editorconfig b/.editorconfig index dd73d98b..b381fcd8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,3 +8,9 @@ indent_style = space indent_size = 4 trim_trailing_whitespace = true max_line_length = 120 + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 diff --git a/.github/workflows/application.yml b/.github/workflows/application.yml index 2c7f0a78..610e0a9e 100644 --- a/.github/workflows/application.yml +++ b/.github/workflows/application.yml @@ -15,9 +15,9 @@ jobs: - name: Set up JDK 1.8 uses: actions/setup-java@v3 with: - distribution: 'temurin' + distribution: "temurin" java-version: 8 - cache: 'gradle' + cache: "gradle" - name: Check license headers run: ./gradlew checkLicenses @@ -27,7 +27,7 @@ jobs: strategy: matrix: java-version: ["8", "11", "17", "19"] # LTS + Latest - os: [ 'ubuntu-latest', 'macos-latest', 'windows-latest' ] + os: ["ubuntu-latest", "macos-latest", "windows-latest"] name: Java ${{ matrix.java-version }} (${{ matrix.os }}) Tests steps: - uses: actions/checkout@v3 @@ -35,15 +35,15 @@ jobs: - name: Set up JDK ${{ matrix.java-version }} uses: actions/setup-java@v3 with: - distribution: 'temurin' + distribution: "temurin" java-version: ${{ matrix.java-version }} - cache: 'gradle' + cache: "gradle" - name: Run Unit Tests run: ./gradlew --no-daemon test --tests com.atlauncher.* - name: Run UI Tests - uses: GabrielBB/xvfb-action@v1 + uses: coactions/setup-xvfb@v1 if: matrix.os != 'macos-latest' # skipped on OSX as not working and no way to test fixes continue-on-error: ${{ matrix.os == 'windows-latest' }} # Windows seems flaky with: @@ -60,9 +60,9 @@ jobs: - name: Set up JDK 1.8 uses: actions/setup-java@v3 with: - distribution: 'temurin' + distribution: "temurin" java-version: 8 - cache: 'gradle' + cache: "gradle" - name: Read version id: version @@ -77,7 +77,7 @@ jobs: with: string: ${{ steps.version.outputs.text }} pattern: '([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\.?\w*' - replace-with: '$1' + replace-with: "$1" - name: Build run: ./gradlew build -x test @@ -111,7 +111,7 @@ jobs: with: string: ${{ steps.changelog.outputs.text }} pattern: '^.*?(### (New Features|Fixes|Misc)\n.*)$' - replace-with: '$1' + replace-with: "$1" flags: gs - name: Clean up the changelog to only have used sections @@ -190,12 +190,12 @@ jobs: - name: Commit new version/CHANGELOG file uses: EndBug/add-and-commit@v7.0.0 with: - add: 'CHANGELOG.md src/main/resources/version' - message: 'chore: bump version' + add: "CHANGELOG.md src/main/resources/version" + message: "chore: bump version" - name: Add comment, remove label and then close issues labeled with 'awaiting-release' uses: ./.github/actions/label-cleanup with: - label: 'awaiting-release' - comment: 'This has been fixed with version ${{ needs.build.outputs.clean-version }}' + label: "awaiting-release" + comment: "This has been fixed with version ${{ needs.build.outputs.clean-version }}" token: ${{ secrets.BOT_GITHUB_TOKEN }} diff --git a/.github/workflows/aur-publish.yml b/.github/workflows/aur-publish.yml index 045c3bdd..0a1b46c6 100644 --- a/.github/workflows/aur-publish.yml +++ b/.github/workflows/aur-publish.yml @@ -35,5 +35,5 @@ jobs: - name: Commit changed files uses: EndBug/add-and-commit@v7.0.0 with: - add: 'packaging/aur/' - message: 'chore: update aur packages' + add: "packaging/aur/" + message: "chore: update aur packages" diff --git a/.vscode/settings.json b/.vscode/settings.json index 1e72b90a..aba91d18 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,6 +9,9 @@ "source.organizeImports": true } }, + "[github-actions-workflow]": { + "editor.tabSize": 2 + }, "editor.formatOnSave": true, "better-comments.tags": [ { @@ -30,4 +33,4 @@ "java.codeGeneration.generateComments": true, "git.inputValidationLength": 100, "java.compile.nullAnalysis.mode": "automatic", -} +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a47f9de..203aaf0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,4 +15,5 @@ This changelog only contains the changes that are unreleased. For changes for in ### Misc - Upgrade to Gradle 8.2 -- Update dependency versions \ No newline at end of file +- Update dependency versions +- Fix ui tests failing constantly \ No newline at end of file diff --git a/src/main/java/com/atlauncher/App.java b/src/main/java/com/atlauncher/App.java index 1d13c721..e85ba965 100644 --- a/src/main/java/com/atlauncher/App.java +++ b/src/main/java/com/atlauncher/App.java @@ -178,6 +178,13 @@ public class App { */ public static Path workingDir = null; + /** + * This will tell the launcher to disable HTTP2 connections. + *

+ * --disable-http2 + */ + public static boolean disableHttp2 = false; + /** * This will tell the launcher to allow all SSL certs regardless of validity. * This is insecure and only intended for development purposes. @@ -877,6 +884,9 @@ public class App { parser.accepts("base-cdn-domain", "The base CDN domain.").withRequiredArg().ofType(String.class); parser.accepts("base-cdn-path", "The path on the CDN used for downloading files.").withRequiredArg() .ofType(String.class); + parser.accepts("disable-http2", + "This will tell the launcher to disable HTTP2 connections.") + .withOptionalArg().ofType(Boolean.class); parser.accepts("allow-all-ssl-certs", "This will tell the launcher to allow all SSL certs regardless of validity. This is insecure and only intended for development purposes.") .withOptionalArg().ofType(Boolean.class); @@ -978,6 +988,8 @@ public class App { LogManager.warn("Base cdn path set to " + baseCdnPath); } + disableHttp2 = options.has("disable-http2"); + allowAllSslCerts = options.has("allow-all-ssl-certs"); if (allowAllSslCerts) { LogManager.warn("Allowing all ssl certs. This is insecure and should only be used for development."); diff --git a/src/main/java/com/atlauncher/Network.java b/src/main/java/com/atlauncher/Network.java index 18a5691d..914065ae 100644 --- a/src/main/java/com/atlauncher/Network.java +++ b/src/main/java/com/atlauncher/Network.java @@ -52,7 +52,8 @@ import okhttp3.tls.HandshakeCertificates; public final class Network { public static Cache CACHE = new Cache(FileSystem.CACHE.toFile(), 100 * 1024 * 1024); // 100MB cache - private static List protocols = App.settings.dontUseHttp2 ? Arrays.asList(Protocol.HTTP_1_1) + private static List protocols = (App.disableHttp2 || App.settings.dontUseHttp2) + ? Arrays.asList(Protocol.HTTP_1_1) : Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1); public static OkHttpClient CLIENT = new OkHttpClient.Builder().protocols(protocols) diff --git a/src/main/java/com/atlauncher/gui/tabs/accounts/AccountsTab.java b/src/main/java/com/atlauncher/gui/tabs/accounts/AccountsTab.java index 1f8b9f3c..51d5ed7d 100644 --- a/src/main/java/com/atlauncher/gui/tabs/accounts/AccountsTab.java +++ b/src/main/java/com/atlauncher/gui/tabs/accounts/AccountsTab.java @@ -119,7 +119,6 @@ public class AccountsTab extends JPanel implements Tab, RelocalizationListener { JPanel rightPanel = new JPanel(); rightPanel.setLayout(new BorderLayout()); - JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); @@ -478,7 +477,6 @@ public class AccountsTab extends JPanel implements Tab, RelocalizationListener { 0, GetText.tr("Logging Into Minecraft"), "Aborting login for " + viewModel.getLoginUsername()); - dialog.setName("loginDialog"); dialog.addThread(new Thread(() -> { viewModel.login(); dialog.close(); diff --git a/src/test/java/ui/AbstractUiTest.java b/src/test/java/ui/AbstractUiTest.java index 8988dd04..3b24e1bc 100644 --- a/src/test/java/ui/AbstractUiTest.java +++ b/src/test/java/ui/AbstractUiTest.java @@ -81,7 +81,7 @@ public class AbstractUiTest extends AssertJSwingTestCaseTemplate { // start the application ApplicationLauncher.application(App.class) .withArgs("--skip-setup-dialog", "--disable-analytics", "--disable-error-reporting", - "--skip-tray-integration", "--no-launcher-update", "--proxy-type=SOCKS", + "--skip-tray-integration", "--no-launcher-update", "--disable-http2", "--proxy-type=SOCKS", "--proxy-host=127.0.0.1", "--proxy-port=" + mockServer.getPort(), "--working-dir=" + workingDir.toString()) .start(); @@ -115,6 +115,7 @@ public class AbstractUiTest extends AssertJSwingTestCaseTemplate { MockHelper.mockFileResponse(mockServer, "version.json"); MockHelper.mockFileResponse(mockServer, "config.json"); MockHelper.mockFileResponse(mockServer, "minecraft_versions.json"); + MockHelper.mockFileResponse(mockServer, "java_runtimes.json"); MockHelper.mockFileResponse(mockServer, "lwjgl.json"); // files from Minecraft servers diff --git a/src/test/java/ui/BasicLauncherUiTest.java b/src/test/java/ui/BasicLauncherUiTest.java index 18a3be34..6d4874ce 100644 --- a/src/test/java/ui/BasicLauncherUiTest.java +++ b/src/test/java/ui/BasicLauncherUiTest.java @@ -84,9 +84,6 @@ public class BasicLauncherUiTest extends AbstractUiTest { // login loginButton.click(); - DialogFixture loginDialog = WindowFinder.findDialog("loginDialog").using(robot()); - loginDialog.requireVisible(); - // give it 5 seconds Pause.pause(5, TimeUnit.SECONDS); @@ -129,7 +126,7 @@ public class BasicLauncherUiTest extends AbstractUiTest { public boolean test() { return Files.exists(workingDir.resolve("instances/Minecraft1164/instance.json")); } - }, Timeout.timeout(5, TimeUnit.MINUTES)); + }, Timeout.timeout(30, TimeUnit.SECONDS)); DialogFixture installSuccessDialog = WindowFinder.findDialog(new GenericTypeMatcher

(Dialog.class) { @Override diff --git a/src/test/java/ui/mocks/MockHelper.java b/src/test/java/ui/mocks/MockHelper.java index 6256ccf6..089871d7 100644 --- a/src/test/java/ui/mocks/MockHelper.java +++ b/src/test/java/ui/mocks/MockHelper.java @@ -46,6 +46,8 @@ public class MockHelper { static { mockedFilePaths.put("newnews.json", Paths.get("src/test/resources/mocks/download-nodecdn-net/newnews.json")); mockedFilePaths.put("runtimes.json", Paths.get("src/test/resources/mocks/download-nodecdn-net/runtimes.json")); + mockedFilePaths.put("java_runtimes.json", + Paths.get("src/test/resources/mocks/download-nodecdn-net/java_runtimes.json")); mockedFilePaths.put("users.json", Paths.get("src/test/resources/mocks/download-nodecdn-net/users.json")); mockedFilePaths.put("packsnew.json", Paths.get("src/test/resources/mocks/download-nodecdn-net/packsnew.json")); mockedFilePaths.put("version.json", Paths.get("src/test/resources/mocks/download-nodecdn-net/version.json")); @@ -121,6 +123,13 @@ public class MockHelper { minecraftVersions.size = (int) Files.size(mockedFilePaths.get("minecraft_versions.json")); minecraftVersions.sha1 = Hashing.sha1(mockedFilePaths.get("minecraft_versions.json")).toString(); downloadableFiles.add(minecraftVersions); + + DownloadableFile javaRuntimes = new DownloadableFile(); + javaRuntimes.name = "java_runtimes.json"; + javaRuntimes.folder = "json"; + javaRuntimes.size = (int) Files.size(mockedFilePaths.get("java_runtimes.json")); + javaRuntimes.sha1 = Hashing.sha1(mockedFilePaths.get("java_runtimes.json")).toString(); + downloadableFiles.add(javaRuntimes); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/test/resources/mocks/download-nodecdn-net/config.json b/src/test/resources/mocks/download-nodecdn-net/config.json index d192ff39..54eb64ef 100644 --- a/src/test/resources/mocks/download-nodecdn-net/config.json +++ b/src/test/resources/mocks/download-nodecdn-net/config.json @@ -2,6 +2,7 @@ "useLwjglReplacement": false, "analytics": { "enabled": false, + "enabledVersion": "0.0.0.0", "percentage": 0, "autoSendInSeconds": 300 }, diff --git a/src/test/resources/mocks/download-nodecdn-net/java_runtimes.json b/src/test/resources/mocks/download-nodecdn-net/java_runtimes.json new file mode 100644 index 00000000..2f2ddff7 --- /dev/null +++ b/src/test/resources/mocks/download-nodecdn-net/java_runtimes.json @@ -0,0 +1,11 @@ +{ + "linux": {}, + "linux-i386": {}, + "mac-os": {}, + "mac-os-arm64": {}, + "windows-arm64": {}, + "windows-x64": {}, + "windows-x86": {}, + "linux-arm": {}, + "linux-arm64": {} +} \ No newline at end of file