Skip to content

Commit

Permalink
Use blocking expectation awaiting again
Browse files Browse the repository at this point in the history
  • Loading branch information
ffried committed Oct 1, 2023
1 parent 742b96c commit 448e936
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 50 deletions.
22 changes: 6 additions & 16 deletions Tests/SwiftyHolidaysTests/Gregorian/GregorianCalculatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import XCTest
@testable import SwiftyHolidays

final class GregorianCalculatorTests: XCTestCase {
private actor Promise<Value> {
var value: Value?

func fulfill(with value: Value) {
self.value = value
}
}

private let calculator = GregorianCalculator()

override func setUp() {
Expand Down Expand Up @@ -142,7 +134,7 @@ final class GregorianCalculatorTests: XCTestCase {
XCTAssertEqual(sema.wait(timeout: .now()), .success)
}

func testAwaitingCalculation() async {
func testAwaitingCalculation() {
let sema = DispatchSemaphore(value: 0)
let date = HolidayDate(day: 21, month: 4, year: 2019)
calculator.contextRef.withContext { $0.semaphores[date.year, default: [:]][.easterSunday] = sema }
Expand All @@ -152,17 +144,15 @@ final class GregorianCalculatorTests: XCTestCase {
_ = self.calculator.easterSunday(forYear: date.year)
awaitExpectation.fulfill()
}
await fulfillment(of: [awaitExpectation], timeout: 2)
wait(for: [awaitExpectation], timeout: 2)
calculator.contextRef.withContext { $0.fulfill(.easterSunday, with: date) }
let calcExpectation = expectation(description: "Waiting for the calculator to return the calculated result")
let resultPromise = Promise<HolidayDate>()
Task.detached {
let calculated = self.calculator.easterSunday(forYear: date.year)
await resultPromise.fulfill(with: calculated)
var result: HolidayDate?
DispatchQueue.global().async {
result = self.calculator.easterSunday(forYear: date.year)
calcExpectation.fulfill()
}
await fulfillment(of: [calcExpectation], timeout: 2)
let result = await resultPromise.value
wait(for: [calcExpectation], timeout: 2)
XCTAssertEqual(result, date)
}

Expand Down
34 changes: 0 additions & 34 deletions Tests/SwiftyHolidaysTests/Helpers.swift

This file was deleted.

0 comments on commit 448e936

Please sign in to comment.