Skip to content

Commit

Permalink
tech: Resolve issues supporting Linux with async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
surpher committed May 13, 2024
1 parent cae0832 commit 338457a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 33 deletions.
55 changes: 30 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build

on:
pull_request:
push:
branches:
- 'main'
Expand All @@ -14,6 +15,7 @@ on:
- 'style/**'
- 'test/**'
- 'tech/**'
- 'for-posterity/**'

env:
RUST_TARGET_PATH: pact-reference
Expand All @@ -22,23 +24,23 @@ jobs:
test:
name: Run ${{ matrix.platform }} on ${{ matrix.host }}
runs-on: ${{ matrix.host }}

strategy:
fail-fast: true
matrix:
host: [macos-11, macos-12]
host: [macos-13, macos-14]
platform: [ios, macos]
include:
- platform: ios
scheme: "PactSwift-iOS"
destination: "platform=iOS Simulator,name=iPhone 12 Pro"
destination: "platform=iOS Simulator,name=iPhone 15 Pro"
- platform: macos
scheme: "PactSwift-macOS"
destination: "arch=x86_64"
- host: macos-11
xcode: 13.2.1
- host: macos-12
xcode: 14.0.1
destination: "arch=aarm64"
- host: macos-13
xcode: 14.3.1
- host: macos-14
xcode: 15.4

env:
SCHEME: ${{ matrix.scheme }}
Expand Down Expand Up @@ -104,30 +106,33 @@ jobs:
run: |
Scripts/build_test_linux
test_carthage:
name: "Verify for Carthage"
runs-on: macos-12
# test_carthage:
# name: "Verify for Carthage"
# runs-on: macos-14

strategy:
fail-fast: true
# strategy:
# fail-fast: true

concurrency:
group: test-carthage-${{ github.ref }}
cancel-in-progress: true
# concurrency:
# group: test-carthage-${{ github.ref }}
# cancel-in-progress: true

steps:
- name: Checkout repository
uses: actions/checkout@v2
# steps:
# - name: Checkout repository
# uses: actions/checkout@v2

- name: Use Xcode 13.4.1
run: sudo xcode-select -switch /Applications/Xcode_13.4.1.app
# - name: Use Xcode 13.4.1
# run: sudo xcode-select -switch /Applications/Xcode_13.4.1.app

- name: Carthage build
run: |
carthage build --use-xcframeworks --no-skip-current
# - name: Carthage build
# run: |
# carthage build --use-xcframeworks --no-skip-current

after_success:
needs: [test, test_carthage, test_linux]
needs:
- test
- test_linux
# - test_carthage
name: Build demo projects
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
Expand Down
21 changes: 14 additions & 7 deletions Sources/Extensions/MockServer+Async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@
import Foundation

#if os(Linux)
import PactSwiftMockServerLinux
import PactSwiftMockServerLinux
#elseif compiler(>=5.5)
@_implementationOnly import PactSwiftMockServer
@_implementationOnly import PactSwiftMockServer
#else
import PactSwiftMockServer
import PactSwiftMockServer
#endif

extension MockServer {


// Handling platform specifics
#if os(Linux)
typealias TransferProtocolScheme = PactSwiftMockServerLinux.TransferProtocol
#else
private var TransferProtocolScheme = PactSwiftMockServer.TransferProtocol

Check failure on line 34 in Sources/Extensions/MockServer+Async.swift

View workflow job for this annotation

GitHub Actions / Run ios on macos-14

expected member name or constructor call after type name

Check failure on line 34 in Sources/Extensions/MockServer+Async.swift

View workflow job for this annotation

GitHub Actions / Run ios on macos-14

extensions must not contain stored properties
#endif

/// Spins up a mock server with expected interactions defined in the provided Pact
///
/// - Parameters:
Expand All @@ -35,14 +42,14 @@ extension MockServer {
///
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
@discardableResult
func setup(pact: Data, protocol: PactSwiftMockServer.TransferProtocol = .standard) async throws -> Int {
func setup(pact: Data, protocol: TransferProtocolScheme = .standard) async throws -> Int {

Check failure on line 45 in Sources/Extensions/MockServer+Async.swift

View workflow job for this annotation

GitHub Actions / Run ios on macos-14

cannot find type 'TransferProtocolScheme' in scope
try await withCheckedThrowingContinuation { continuation in
self.setup(pact: pact, protocol: `protocol`) { result in
continuation.resume(with: result)
}
}
}

/// Verifies all interactions passed to mock server
///
/// By default pact files are written to `/tmp/pacts`.
Expand All @@ -56,7 +63,7 @@ extension MockServer {
}
}
}

/// Finalises Pact tests by writing the pact contract file to disk
///
/// - Parameters:
Expand Down
6 changes: 5 additions & 1 deletion Sources/Extensions/Task+Timeout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
extension Task where Failure == Error {

// Start a new Task with a timeout. If the timeout expires before the operation is
// completed then the task is cancelled and an error is thrown.
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
Expand All @@ -28,7 +28,11 @@ extension Task where Failure == Error {
try await withThrowingTaskGroup(of: Success.self) { group -> Success in
group.addTask(operation: operation)
group.addTask {
#if os(Linux)
try await _Concurrency.Task.sleep(nanoseconds: UInt64(timeout * 1_000_000_000))
#else
try await _Concurrency.Task.sleep(nanoseconds: UInt64(timeout * Double(NSEC_PER_SEC)))
#endif
throw TimeoutError(interval: timeout)
}
guard let success = try await group.next() else {
Expand Down

0 comments on commit 338457a

Please sign in to comment.