Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Nimble/DSL+Wait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class NMBWait: NSObject {
}
}
}
}.timeout(timeout, forcefullyAbortTimeout: leeway).wait(
}.timeout(timeout, forcefullyAbortTimeout: leeway, isContinuous: false).wait(
"waitUntil(...)",
sourceLocation: SourceLocation(fileID: fileID, filePath: file, line: line, column: column)
)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Nimble/Polling+AsyncAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ internal actor Poller<T> {
fnName: fnName) {
if self.updateMatcherResult(result: try await matcherRunner())
.toBoolean(expectation: style) {
if matchStyle.isContinous {
if matchStyle.isContinuous {
return .incomplete
}
return .finished(true)
} else {
if matchStyle.isContinous {
if matchStyle.isContinuous {
return .finished(false)
} else {
return .incomplete
Expand Down
9 changes: 5 additions & 4 deletions Sources/Nimble/Polling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public struct PollingDefaults: @unchecked Sendable {
internal enum AsyncMatchStyle {
case eventually, never, always

var isContinous: Bool {
var isContinuous: Bool {
switch self {
case .eventually:
return false
Expand All @@ -96,15 +96,16 @@ internal func poll<T>(
pollInterval: poll,
timeoutInterval: timeout,
sourceLocation: actualExpression.location,
fnName: fnName) {
fnName: fnName,
isContinuous: matchStyle.isContinuous) {
lastMatcherResult = try matcher.satisfies(uncachedExpression)
if lastMatcherResult!.toBoolean(expectation: style) {
if matchStyle.isContinous {
if matchStyle.isContinuous {
return .incomplete
}
return .finished(true)
} else {
if matchStyle.isContinous {
if matchStyle.isContinuous {
return .finished(false)
} else {
return .incomplete
Expand Down
7 changes: 4 additions & 3 deletions Sources/Nimble/Utils/PollAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ internal class AwaitPromiseBuilder<T> {
self.trigger = trigger
}

func timeout(_ timeoutInterval: NimbleTimeInterval, forcefullyAbortTimeout: NimbleTimeInterval) -> Self {
func timeout(_ timeoutInterval: NimbleTimeInterval, forcefullyAbortTimeout: NimbleTimeInterval, isContinuous: Bool) -> Self {
/// = Discussion =
///
/// There's a lot of technical decisions here that is useful to elaborate on. This is
Expand Down Expand Up @@ -234,7 +234,7 @@ internal class AwaitPromiseBuilder<T> {
let didNotTimeOut = timedOutSem.wait(timeout: now) != .success
let timeoutWasNotTriggered = semTimedOutOrBlocked.wait(timeout: .now()) == .success
if didNotTimeOut && timeoutWasNotTriggered {
if self.promise.resolveResult(.blockedRunLoop) {
if self.promise.resolveResult(isContinuous ? .timedOut : .blockedRunLoop) {
#if canImport(CoreFoundation)
CFRunLoopStop(CFRunLoopGetMain())
#else
Expand Down Expand Up @@ -402,6 +402,7 @@ internal func pollBlock(
timeoutInterval: NimbleTimeInterval,
sourceLocation: SourceLocation,
fnName: String = #function,
isContinuous: Bool,
expression: @escaping () throws -> PollStatus) -> PollResult<Bool> {
let awaiter = NimbleEnvironment.activeInstance.awaiter
let result = awaiter.poll(pollInterval) { () throws -> Bool? in
Expand All @@ -410,7 +411,7 @@ internal func pollBlock(
}
return nil
}
.timeout(timeoutInterval, forcefullyAbortTimeout: timeoutInterval.divided)
.timeout(timeoutInterval, forcefullyAbortTimeout: timeoutInterval.divided, isContinuous: isContinuous)
.wait(fnName, sourceLocation: sourceLocation)

return result
Expand Down
27 changes: 27 additions & 0 deletions Tests/NimbleTests/PollingTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,33 @@
}
}
}

Check warning on line 142 in Tests/NimbleTests/PollingTest.swift

View workflow job for this annotation

GitHub Actions / lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
func testToEventuallyDetectsStalledMainThreadActivity() {
func spinAndReturnTrue() -> Bool {
Thread.sleep(forTimeInterval: 0.5)
return true
}
let msg = "expected to eventually be true, got <true> (timed out, but main run loop was unresponsive)."
failsWithErrorMessage(msg) {
expect(spinAndReturnTrue()).toEventually(beTrue())
}
}

Check warning on line 153 in Tests/NimbleTests/PollingTest.swift

View workflow job for this annotation

GitHub Actions / lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
func testToNeverDoesNotFailStalledMainThreadActivity() {
func spinAndReturnTrue() -> Bool {
Thread.sleep(forTimeInterval: 0.5)
return true
}
expect(spinAndReturnTrue()).toNever(beFalse())
}

Check warning on line 161 in Tests/NimbleTests/PollingTest.swift

View workflow job for this annotation

GitHub Actions / lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
func testToAlwaysDetectsStalledMainThreadActivity() {
func spinAndReturnTrue() -> Bool {
Thread.sleep(forTimeInterval: 0.5)
return true
}
expect(spinAndReturnTrue()).toAlways(beTrue())
}

func testCombiningAsyncWaitUntilAndToEventuallyIsNotAllowed() {
// Currently we are unable to catch Objective-C exceptions when built by the Swift Package Manager
Expand Down
Loading