Skip to content

Commit

Permalink
SPT-1998 fix tests and code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mrandrewsmith committed Apr 10, 2024
1 parent b0e483f commit 729253a
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 132 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
## Build generated
build/
DerivedData/
CoverageReports/
Docs/swift_output/
CoverageReports/
Package.resolved

## Various settings
*.pbxuser
Expand Down
Empty file removed NodeKit.framework.coverage.txt
Empty file.

This file was deleted.

Empty file removed NodeKitTests.xctest.coverage.txt
Empty file.
5 changes: 3 additions & 2 deletions NodeKitTests/UnitTests/LoadIndicatableNodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ final class LoadIndicatableNodeTests: XCTestCase {
XCTAssertEqual(error, .firstError)
}

@MainActor
func testAsyncProcess_thenIndicatorIncremented() async {
// given

var count = 0
let expectation = expectation(description: "result")
let expectation = expectation(description: #function)
nextNodeMock.stubbedAsyncProccessResult = .success(1)
nextNodeMock.stubbedAsyncProcessRunFunction = {
count += 1
Expand All @@ -113,7 +114,7 @@ final class LoadIndicatableNodeTests: XCTestCase {
_ = await sut.process(1, logContext: logContextMock)
}

await fulfillment(of: [expectation], timeout: 0.2)
await fulfillment(of: [expectation], timeout: 3)

// then

Expand Down
4 changes: 2 additions & 2 deletions NodeKitTests/UnitTests/Node/AsyncNodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final class AsyncNodeTests: XCTestCase {
// given

let sut = AsyncNodeMock<Int, Int>()
let expectation = expectation(description: "result")
let expectation = expectation(description: #function)
let expectedInput = 15
let expectedResult = 21
let logContext = LoggingContextMock()
Expand All @@ -103,7 +103,7 @@ final class AsyncNodeTests: XCTestCase {
})
.store(in: &cancellable)

await fulfillment(of: [expectation], timeout: 0.1)
await fulfillment(of: [expectation], timeout: 3)

// then

Expand Down
4 changes: 2 additions & 2 deletions NodeKitTests/UnitTests/Node/AsyncStreamNodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ final class AsyncStreamNodeTests: XCTestCase {
// given

let sut = AsyncStreamNodeMock<Int, Int>()
let expectation = expectation(description: "result")
let expectation = expectation(description: #function)
let expectedInput = 43

let expectedResults: [Result<Int, Error>] = [
Expand Down Expand Up @@ -154,7 +154,7 @@ final class AsyncStreamNodeTests: XCTestCase {

node.process(expectedInput, logContext: logContextMock)

await fulfillment(of: [expectation], timeout: 0.1)
await fulfillment(of: [expectation], timeout: 3)

// then

Expand Down
31 changes: 18 additions & 13 deletions NodeKitTests/UnitTests/Node/Combine/AsyncCombineNodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ final class AsyncCombineNodeTests: XCTestCase {

// MARK: - Tests

@MainActor
func testnodeResultPublisher_withPublisherOnMainQueue_thenResultsReceivedOnMainQueue() async {
let expectation = expectation(description: "result")
let expectation = expectation(description: #function)

var isMainThread = false

Expand All @@ -58,7 +59,7 @@ final class AsyncCombineNodeTests: XCTestCase {
})
.store(in: &cancellable)

await fulfillment(of: [expectation], timeout: 0.1)
await fulfillment(of: [expectation], timeout: 3)

// then

Expand All @@ -68,7 +69,7 @@ final class AsyncCombineNodeTests: XCTestCase {
func testNodeResultPublisher_onCustomQueue_thenDataReceivedOnCustomQueue() async {
// given

let expectation = expectation(description: "result")
let expectation = expectation(description: #function)
let expectedQueueName = "Test Process Queue"
let queue = DispatchQueue(label: expectedQueueName)

Expand All @@ -85,17 +86,18 @@ final class AsyncCombineNodeTests: XCTestCase {
})
.store(in: &cancellable)

await fulfillment(of: [expectation], timeout: 0.1)
await fulfillment(of: [expectation], timeout: 3)

// then

XCTAssertEqual(queueName, expectedQueueName)
}

@MainActor
func testNodeResultPublisher_thenNextNodeCalled() async throws {
// given

let expectation = expectation(description: "result")
let expectation = expectation(description: #function)
let expectedInput = 7
let expectedResult: NodeResult<Int> = .success(8)

Expand All @@ -109,7 +111,7 @@ final class AsyncCombineNodeTests: XCTestCase {
})
.store(in: &cancellable)

await fulfillment(of: [expectation], timeout: 0.1)
await fulfillment(of: [expectation], timeout: 3)

// then

Expand All @@ -119,10 +121,11 @@ final class AsyncCombineNodeTests: XCTestCase {
XCTAssertEqual(input.data, expectedInput)
}

@MainActor
func testNodeResultPublisher_whenResultIsSuccess_thenSuccessResultReceived() async throws {
// given

let expectation = expectation(description: "result")
let expectation = expectation(description: #function)
let expectedResult = 8

var result: NodeResult<Int>?
Expand All @@ -138,7 +141,7 @@ final class AsyncCombineNodeTests: XCTestCase {
})
.store(in: &cancellable)

await fulfillment(of: [expectation], timeout: 0.1)
await fulfillment(of: [expectation], timeout: 3)

// then

Expand All @@ -147,11 +150,12 @@ final class AsyncCombineNodeTests: XCTestCase {
XCTAssertEqual(value, expectedResult)
}

@MainActor
func testNodeResultPublisher_whithMultipleSubscriptions_thenResultsReceived() async throws {
// given

let expectation1 = expectation(description: "result1")
let expectation2 = expectation(description: "result2")
let expectation1 = expectation(description: #function + "1")
let expectation2 = expectation(description: #function + "2")
let expectedResult = 8

var result1: NodeResult<Int>?
Expand All @@ -177,7 +181,7 @@ final class AsyncCombineNodeTests: XCTestCase {
})
.store(in: &cancellable)

await fulfillment(of: [expectation1, expectation2], timeout: 0.1)
await fulfillment(of: [expectation1, expectation2], timeout: 3)

// then

Expand All @@ -188,10 +192,11 @@ final class AsyncCombineNodeTests: XCTestCase {
XCTAssertEqual(value2, expectedResult)
}

@MainActor
func testNodeResultPublisher_whenResultIsFailure_thenFailureResultReceived() async throws {
// given

let expectation = expectation(description: "result")
let expectation = expectation(description: #function)

var result: NodeResult<Int>?

Expand All @@ -206,7 +211,7 @@ final class AsyncCombineNodeTests: XCTestCase {
})
.store(in: &cancellable)

await fulfillment(of: [expectation], timeout: 0.1)
await fulfillment(of: [expectation], timeout: 3)

// then

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ final class AsyncStreamCombineNodeTests: XCTestCase {

// MARK: - Tests

@MainActor
func testProcess_withPublisherOnMainQueue_thenResultsReceivedOnMainQueue() async {
// given

let expectation = expectation(description: "result")
let expectation = expectation(description: #function)

var isMainThread = false

Expand All @@ -67,7 +68,7 @@ final class AsyncStreamCombineNodeTests: XCTestCase {

sut.process(12, logContext: logContextMock)

await fulfillment(of: [expectation], timeout: 0.1)
await fulfillment(of: [expectation], timeout: 3)

// then

Expand All @@ -77,7 +78,7 @@ final class AsyncStreamCombineNodeTests: XCTestCase {
func testProcess_withPublisherOnCustomQueue_thenResultsReceivedOnCustomQueue() async {
// given

let expectation = expectation(description: "result")
let expectation = expectation(description: #function)
let expectedLabel = "Test Process Queue"
let queue = DispatchQueue(label: expectedLabel)

Expand All @@ -103,18 +104,19 @@ final class AsyncStreamCombineNodeTests: XCTestCase {

sut.process(12, logContext: logContextMock)

await fulfillment(of: [expectation], timeout: 0.1)
await fulfillment(of: [expectation], timeout: 3)

// then

XCTAssertFalse(isMainThread)
XCTAssertEqual(queueLabel, expectedLabel)
}

@MainActor
func testProcess_thenResultsReceived() async throws {
// given

let expectation = expectation(description: "result")
let expectation = expectation(description: #function)
let expectedInput = 43

let expectedResults: [Result<Int, Error>] = [
Expand Down Expand Up @@ -147,7 +149,7 @@ final class AsyncStreamCombineNodeTests: XCTestCase {

sut.process(expectedInput, logContext: logContextMock)

await fulfillment(of: [expectation], timeout: 0.1)
await fulfillment(of: [expectation], timeout: 3)

// then

Expand All @@ -162,11 +164,12 @@ final class AsyncStreamCombineNodeTests: XCTestCase {
)
}

@MainActor
func testProcess_withMultipleSubsciptions_thenResultsReceived() async {
// given

let expectation1 = expectation(description: "result1")
let expectation2 = expectation(description: "result2")
let expectation1 = expectation(description: #function + "1")
let expectation2 = expectation(description: #function + "2")

let expectedResults: [Result<Int, MockError>] = [
.success(500),
Expand Down Expand Up @@ -216,7 +219,7 @@ final class AsyncStreamCombineNodeTests: XCTestCase {

sut.process(1, logContext: logContextMock)

await fulfillment(of: [expectation1, expectation2], timeout: 1)
await fulfillment(of: [expectation1, expectation2], timeout: 3)

// then

Expand Down
3 changes: 3 additions & 0 deletions NodeKitTests/UnitTests/Node/Combine/CombineNodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class CombineNodeTests: XCTestCase {

// MARK: - Tests

@MainActor
func testNodeResultPublisher_withVoid_thenMainMethodCalled() throws {
// given

Expand All @@ -33,6 +34,7 @@ final class CombineNodeTests: XCTestCase {
XCTAssertEqual(scheduler, .main)
}

@MainActor
func testNodeResultPublisher_withData_thenMainMethodCalled() throws {
// given

Expand Down Expand Up @@ -80,6 +82,7 @@ final class CombineNodeTests: XCTestCase {
XCTAssertEqual(scheduler, queue)
}

@MainActor
func testNodeResultPublisher_withData_andLogContext_thenMainMethodCalled() throws {
// given

Expand Down
Loading

0 comments on commit 729253a

Please sign in to comment.