Skip to content

Conversation

dfed
Copy link
Owner

@dfed dfed commented May 24, 2025

The move to Swift Testing in #156 introduced some nondeterminism due to our use of a single static pointer FileFinder. Swift Testing runs multiple tests in parallel, and multiple tests were smashing the FileFinder pointer.

This PR does two things:

  1. Uses TaskLocal to ensure that each test uses the desired FileFinder.
  2. Enables all Swift Test suites to run in parallel.

Best reviewed with whitespace changes ignored.

@dfed dfed self-assigned this May 24, 2025
@dfed dfed force-pushed the dfed--test-reliability branch from 6601292 to 6a4a093 Compare May 24, 2025 19:49
@@ -24,8 +24,7 @@ import Testing

@testable import SafeDITool

@Suite(.serialized)
final class SafeDIToolCodeGenerationErrorTests {
struct SafeDIToolCodeGenerationErrorTests: ~Copyable {
Copy link
Owner Author

@dfed dfed May 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ~Copyable conformance is required for deinit to work on a struct

@@ -40,8 +39,8 @@ final class SafeDIToolCodeGenerationErrorTests {

// MARK: Error Tests

@MainActor @Test
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allows the test to run in parallel

@MainActor @Test
func run_onCodeWithPropertyWithUnknownFulfilledType_throwsError() async {
@Test
mutating func run_onCodeWithPropertyWithUnknownFulfilledType_throwsError() async {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we pass in a modifiable filesToDelete: &filesToDelete in each executeSafeDIToolTest call, we need the test method to be mutating.

Comment on lines -1818 to +1815
func test_include_throwsErrorWhenNoSwiftSourcesFilePathAndNoInclude() async {
@Test
func include_throwsErrorWhenNoSwiftSourcesFilePathAndNoInclude() async {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eek. Missed converting this test in #156. Found a couple like this.

@dfed dfed force-pushed the dfed--test-reliability branch from 3ee0892 to 4906dde Compare May 24, 2025 20:06
Copy link

codecov bot commented May 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.91%. Comparing base (9e524a0) to head (594f1b4).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #159      +/-   ##
==========================================
+ Coverage   99.88%   99.91%   +0.02%     
==========================================
  Files          32       32              
  Lines        3483     3482       -1     
==========================================
  Hits         3479     3479              
+ Misses          4        3       -1     
Files with missing lines Coverage Δ
Sources/SafeDITool/SafeDITool.swift 99.61% <100.00%> (+0.38%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dfed dfed marked this pull request as ready for review May 24, 2025 21:11

linux:
name: Build and Test on Linux
runs-on: ubuntu-latest
container: swift:6.0
container: swift:6.1
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swift Testing on Swift 6 doesn't like using ~Copyable structs in tests

@@ -178,7 +178,7 @@ jobs:
lint-swift:
name: Lint Swift
runs-on: ubuntu-latest
container: swift:6.0
container: swift:6.1
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a functional change, but doesn't seem harmful

@@ -1,4 +1,4 @@
// swift-tools-version: 6.0
// swift-tools-version: 6.1
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

development in this lib should be in Swift 6.1. We just need to support building in Swift 6.

@@ -86,7 +86,7 @@ To install the SafeDI framework into an Xcode project with Swift Package Manager

#### CocoaPods

To add the SafeDI framework as a dependency to a package utilizing [CocoaPods](http://cocoapods.org), add the following to your `Podfile`:
To add the SafeDI framework as a dependency to a package utilizing [CocoaPods](https://blog.cocoapods.org/CocoaPods-Specs-Repo), add the following to your `Podfile`:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cocoapods.org was down at the time of writing, causing a CI failure. So I've moved to linking to the blog post showing that CocoaPods is going away, which seems like a reasonable alternative.

@dfed dfed force-pushed the dfed--test-reliability branch from 80cca69 to 594f1b4 Compare May 24, 2025 22:11
@dfed dfed merged commit 70f3417 into main May 24, 2025
19 checks passed
@dfed dfed deleted the dfed--test-reliability branch May 24, 2025 22:36
@dfed dfed restored the dfed--test-reliability branch May 24, 2025 22:37
@dfed dfed deleted the dfed--test-reliability branch May 24, 2025 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant