From 85b12d1aecb872d8841f157f7817ae230a163501 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 30 Sep 2025 16:14:17 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Prevent=20unit=20tests=20f?= =?UTF-8?q?rom=20running=20concurrently?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The way the testing classes are built with the singletons currently prevents various test structs from being run at the same time. I've adjusted the tests in the PHP Monitor EAP test configuration so that they are not executed concurrently. This does slow down the test suite but prevents odd crashes from individual tests interfering with other tests. It's not an ideal solution and I would like to address this in the future, but I suspect this will be rather cumbersome. Since the app does not actually suffer from this particular issue, this is something worth investigating later. --- PHP Monitor.xcodeproj/project.pbxproj | 2 - .../xcschemes/PHP Monitor EAP.xcscheme | 8 ++- .../xcschemes/PHP Monitor.xcscheme | 9 +-- .../Integrations/Homebrew/CaskFile.swift | 2 +- tests/PHP Monitor.xctestplan | 67 ------------------- tests/Shared/TestableConfigurations.swift | 15 +++++ .../Parsers/CaskFileParserTest.swift | 5 ++ .../Parsers/PhpConfigurationFileTest.swift | 4 +- .../Parsers/PhpExtensionTest.swift | 5 ++ 9 files changed, 36 insertions(+), 81 deletions(-) delete mode 100644 tests/PHP Monitor.xctestplan diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index c0a8fa8..21c445d 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -1144,7 +1144,6 @@ C46FA98A2822F08F00D78807 /* PhpConfigurationFileTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhpConfigurationFileTest.swift; sourceTree = ""; }; C47015012C46D6910069AAE7 /* NVAlertExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NVAlertExtension.swift; sourceTree = ""; }; C4709CA128524B3400088BB8 /* StatsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsView.swift; sourceTree = ""; }; - C471E79228F9B1D30021E251 /* PHP Monitor.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "PHP Monitor.xctestplan"; sourceTree = ""; }; C471E7AD28F9B4940021E251 /* Feature Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Feature Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; C471E7AF28F9B4940021E251 /* InternalSwitcherTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InternalSwitcherTest.swift; sourceTree = ""; }; C471E7BC28F9B90F0021E251 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1970,7 +1969,6 @@ isa = PBXGroup; children = ( C4E2E86828FC2FF2003B070C /* Shared */, - C471E79228F9B1D30021E251 /* PHP Monitor.xctestplan */, C4F7807A25D7F84B000DBC97 /* unit */, C471E7AE28F9B4940021E251 /* feature */, C471E7BD28F9B90F0021E251 /* ui */, diff --git a/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor EAP.xcscheme b/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor EAP.xcscheme index 4635407..ab0bc59 100644 --- a/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor EAP.xcscheme +++ b/PHP Monitor.xcodeproj/xcshareddata/xcschemes/PHP Monitor EAP.xcscheme @@ -31,7 +31,8 @@ + parallelizable = "NO" + testExecutionOrdering = "random"> + skipped = "NO" + parallelizable = "NO"> - - - - + shouldUseLaunchSchemeArgsEnv = "YES" + shouldAutocreateTestPlan = "YES"> diff --git a/phpmon/Domain/Integrations/Homebrew/CaskFile.swift b/phpmon/Domain/Integrations/Homebrew/CaskFile.swift index b13f567..944bfd9 100644 --- a/phpmon/Domain/Integrations/Homebrew/CaskFile.swift +++ b/phpmon/Domain/Integrations/Homebrew/CaskFile.swift @@ -25,7 +25,7 @@ struct CaskFile { } private static func loadFromApi(_ url: URL) async -> String { - if App.hasLoadedTestableConfiguration { + if App.hasLoadedTestableConfiguration || url.absoluteString.contains("https://raw.githubusercontent.com") { return await Shell.pipe("curl -s --max-time 10 '\(url.absoluteString)'").out } else { return await Shell.pipe(""" diff --git a/tests/PHP Monitor.xctestplan b/tests/PHP Monitor.xctestplan deleted file mode 100644 index cd0bc27..0000000 --- a/tests/PHP Monitor.xctestplan +++ /dev/null @@ -1,67 +0,0 @@ -{ - "configurations" : [ - { - "id" : "98F42C11-E6D2-4AD9-A5CA-40EFE44F384A", - "name" : "Configuration 1", - "options" : { - - } - } - ], - "defaultOptions" : { - "codeCoverage" : false, - "commandLineArgumentEntries" : [ - { - "argument" : "--v", - "enabled" : false - } - ], - "environmentVariableEntries" : [ - { - "enabled" : false, - "key" : "EXTREME_DOCTOR_MODE", - "value" : "" - }, - { - "enabled" : false, - "key" : "SLOW_SHELL_MODE", - "value" : "" - }, - { - "enabled" : false, - "key" : "PAINT_PHPMON_SWIFTUI_VIEWS", - "value" : "" - } - ], - "targetForVariableExpansion" : { - "containerPath" : "container:PHP Monitor.xcodeproj", - "identifier" : "C41C1B3222B0097F00E7CF16", - "name" : "PHP Monitor" - } - }, - "testTargets" : [ - { - "parallelizable" : true, - "target" : { - "containerPath" : "container:PHP Monitor.xcodeproj", - "identifier" : "C4F7807825D7F84B000DBC97", - "name" : "Unit Tests" - } - }, - { - "target" : { - "containerPath" : "container:PHP Monitor.xcodeproj", - "identifier" : "C471E7AC28F9B4940021E251", - "name" : "Feature Tests" - } - }, - { - "target" : { - "containerPath" : "container:PHP Monitor.xcodeproj", - "identifier" : "C471E7BB28F9B90F0021E251", - "name" : "UI Tests" - } - } - ], - "version" : 1 -} diff --git a/tests/Shared/TestableConfigurations.swift b/tests/Shared/TestableConfigurations.swift index 6961704..65f5ed7 100644 --- a/tests/Shared/TestableConfigurations.swift +++ b/tests/Shared/TestableConfigurations.swift @@ -153,6 +153,21 @@ class TestableConfigurations { app 'PHP Monitor DEV.app', target: "PHP Monitor DEV.app" end """), + "curl -s --max-time 10 'https://raw.githubusercontent.com/nicoverbruggen/homebrew-cask/master/Casks/phpmon.rb''" : + .delayed(0.5, """ + cask 'phpmon-dev' do + depends_on formula: 'gnu-sed' + + version '25.08.0_1000' + sha256 '1cb147bd1b1fbd52971d90dff577465b644aee7c878f15ede57f46e8f217067a' + + url 'https://github.com/nicoverbruggen/phpmon/releases/download/v6.0/phpmon-dev.zip' + name 'PHP Monitor DEV' + homepage 'https://phpmon.app' + + app 'PHP Monitor DEV.app', target: "PHP Monitor DEV.app" + end + """), "/opt/homebrew/bin/brew unlink php" : .delayed(0.2, "OK"), "/opt/homebrew/bin/brew unlink php@8.2" diff --git a/tests/unit/SwiftTestMigrated/Parsers/CaskFileParserTest.swift b/tests/unit/SwiftTestMigrated/Parsers/CaskFileParserTest.swift index e24581f..07e1402 100644 --- a/tests/unit/SwiftTestMigrated/Parsers/CaskFileParserTest.swift +++ b/tests/unit/SwiftTestMigrated/Parsers/CaskFileParserTest.swift @@ -9,8 +9,13 @@ import Testing import Foundation +@Suite(.serialized) struct CaskFileParserTest { + init() async throws { + ActiveShell.useSystem() + } + // MARK: - Test Files static var exampleFilePath: URL { TestBundle.url(forResource: "phpmon-dev", withExtension: "rb")! diff --git a/tests/unit/SwiftTestMigrated/Parsers/PhpConfigurationFileTest.swift b/tests/unit/SwiftTestMigrated/Parsers/PhpConfigurationFileTest.swift index 0f0f8b1..e9ea17b 100644 --- a/tests/unit/SwiftTestMigrated/Parsers/PhpConfigurationFileTest.swift +++ b/tests/unit/SwiftTestMigrated/Parsers/PhpConfigurationFileTest.swift @@ -9,13 +9,14 @@ import Testing import Foundation +@Suite(.serialized) class PhpConfigurationFileTest { - static var phpIniFileUrl: URL { return TestBundle.url(forResource: "php", withExtension: "ini")! } @Test func can_load_extension() throws { + ActiveFileSystem.useSystem() let iniFile = PhpConfigurationFile.from(filePath: Self.phpIniFileUrl.path) #expect(iniFile != nil) @@ -23,6 +24,7 @@ class PhpConfigurationFileTest { } @Test func can_check_key_existence() throws { + print(Self.phpIniFileUrl.path) let iniFile = PhpConfigurationFile.from(filePath: Self.phpIniFileUrl.path)! #expect(iniFile.has(key: "error_reporting")) diff --git a/tests/unit/SwiftTestMigrated/Parsers/PhpExtensionTest.swift b/tests/unit/SwiftTestMigrated/Parsers/PhpExtensionTest.swift index fc49bfb..574bea0 100644 --- a/tests/unit/SwiftTestMigrated/Parsers/PhpExtensionTest.swift +++ b/tests/unit/SwiftTestMigrated/Parsers/PhpExtensionTest.swift @@ -9,7 +9,12 @@ import Testing import Foundation +@Suite(.serialized) struct PhpExtensionTest { + init () async throws { + ActiveShell.useSystem() + } + static var phpIniFileUrl: URL { TestBundle.url(forResource: "php", withExtension: "ini")! }