-
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #708 from khlopko/issue-693
#693: DataPublisher created from async function should start lazily
- Loading branch information
Showing
3 changed files
with
53 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// DataPublisherTests.swift | ||
// | ||
|
||
import XCTest | ||
import Combine | ||
@testable import Nuke | ||
|
||
internal final class DataPublisherTests: XCTestCase { | ||
|
||
private var cancellable: (any Nuke.Cancellable)? | ||
|
||
func testInitNotStartsExecutionRightAway() { | ||
let operation = MockOperation() | ||
let publisher = DataPublisher(id: UUID().uuidString, { await operation.execute() }) | ||
|
||
XCTAssertEqual(0, operation.executeCalls) | ||
|
||
let expOp = expectation(description: "Waits for MockOperation to complete execution") | ||
cancellable = publisher.sink { completion in expOp.fulfill() } receiveValue: { _ in } | ||
waitForExpectations(timeout: 0.1) | ||
|
||
XCTAssertEqual(1, operation.executeCalls) | ||
} | ||
|
||
private final class MockOperation: @unchecked Sendable { | ||
|
||
private(set) var executeCalls = 0 | ||
|
||
func execute() async -> Data { | ||
executeCalls += 1 | ||
await Task.yield() | ||
return Data() | ||
} | ||
|
||
} | ||
|
||
} |