Skip to content

Commit

Permalink
Legacy flaky tests fix (#63)
Browse files Browse the repository at this point in the history
* test fixes

* 100-times less dispatched action because it's flaky on CI a fails due to timeout
  • Loading branch information
KazaiMazai authored Sep 2, 2024
1 parent e100594 commit 0af1a91
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ViewWithRootStoreWithAlwaysEqualDeduplicationPropsTests: XCTestCase {
extension ViewWithRootStoreWithAlwaysEqualDeduplicationPropsTests {

func test_WhenManyNonMutatingActionsAndDeduplicationAlwaysEqual_ThenPropsEvaluatedOnce() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -67,7 +67,7 @@ extension ViewWithRootStoreWithAlwaysEqualDeduplicationPropsTests {
}

func test_WhenManyMutatingActionsAndDeduplicationAlwaysEqual_ThenPropsEvaluatedOnce() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ViewWithRootStoreDeduplicationTests: XCTestCase {
extension ViewWithRootStoreDeduplicationTests {

func test_WhenManyNonMutatingActions_ThenPropsEvaluatedOnce() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -90,7 +90,7 @@ extension ViewWithRootStoreDeduplicationTests {
}

func test_WhenManyMutatingActions_ThenPropsEvaluatedForEveryDeduplicatedMutation() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = actionsCount

Expand All @@ -104,7 +104,7 @@ extension ViewWithRootStoreDeduplicationTests {
}

func test_WhenMutatingAndNonMutatingActions_ThenPropsEvaluatedForEveryDeduplicatedMutation() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = actionsCount

Expand All @@ -122,7 +122,7 @@ extension ViewWithRootStoreDeduplicationTests {
}

func test_WhenSpecificSubStateMutatingActions_ThenPropsEvaluatedForEveryDeduplicatedMutation() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = actionsCount

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class ViewEnvRootStoreWithoutDeduplicationPropsTests: ViewWithRootStoreWithoutDe

class ViewWithRootStoreWithoutDeduplicationPropsTests: XCTestCase {
let timeout: TimeInterval = 4

let actionDelay: TimeInterval = 0.1

let state = TestAppState(
subStateWithTitle: SubStateWithTitle(title: ""),
subStateWithIndex: SubStateWithIndex(index: 0)
Expand Down Expand Up @@ -84,21 +85,21 @@ extension ViewWithRootStoreWithoutDeduplicationPropsTests {
}

func test_WhenManyNonMutatingActionsAndDeduplicateNeverEqual_ThenPropsEvaluatedForEveryAction() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = actionsCount

setupWindowForTests(propsEvaluatedExpectation: expectation)

(0..<actionsCount).forEach { _ in
store.dispatch(NonMutatingStateAction())
(0..<actionsCount).forEach { idx in
store.dispatch(NonMutatingStateAction(), after: actionDelay * Double(idx))
}

waitForExpectations(timeout: timeout)
waitForExpectations(timeout: 2 * (actionDelay * Double(actionsCount)))
}

func test_WhenManyMutatingActionsAndDeduplicateNeverEqual_ThenPropsEvaluatedForEveryAction() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = actionsCount

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AlwaysEqualDeduplicationPropsTests: XCTestCase {
extension AlwaysEqualDeduplicationPropsTests {

func test_WhenManyNonMutatingActionsAndDeduplicationAlwaysEqual_ThenPropsEvaluatedOnce() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -74,7 +74,7 @@ extension AlwaysEqualDeduplicationPropsTests {
}

func test_WhenManyMutatingActionsAndDeduplicationAlwaysEqual_ThenPropsEvaluatedOnce() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import UIKit

class NoDeduplicationPropsTests: XCTestCase {
let timeout: TimeInterval = 4

let actionDelay: TimeInterval = 0.2

let state = TestAppState(
subStateWithTitle: SubStateWithTitle(title: ""),
subStateWithIndex: SubStateWithIndex(index: 0)
Expand Down Expand Up @@ -69,21 +70,21 @@ extension NoDeduplicationPropsTests {
}

func test_WhenManyNonMutatingActionsAndDeduplicateNeverEqual_ThenPropsEvaluatedForEveryAction() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = actionsCount

setupWindowForTests(propsEvaluatedExpectation: expectation, rootStore: store)

(0..<actionsCount).forEach { _ in
store.dispatch(NonMutatingStateAction())
(0..<actionsCount).forEach { idx in
store.dispatch(NonMutatingStateAction(), after: actionDelay * Double(idx))
}

waitForExpectations(timeout: timeout)
waitForExpectations(timeout: 2 * (actionDelay * Double(actionsCount)))
}

func test_WhenManyMutatingActionsAndDeduplicateNeverEqual_ThenPropsEvaluatedForEveryAction() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = actionsCount

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DeduplicationPropsTests: XCTestCase {

extension DeduplicationPropsTests {
func test_WhenManyNonMutatingActions_ThenPropsEvaluatedOnce() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -73,7 +73,7 @@ extension DeduplicationPropsTests {
}

func test_WhenManyMutatingActions_ThenPropsEvaluatedForEveryDeduplicatedMutation() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = actionsCount

Expand All @@ -87,7 +87,7 @@ extension DeduplicationPropsTests {
}

func test_WhenMutatingAndNonMutatingActions_ThenPropsEvaluatedForEveryDeduplicatedMutation() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = actionsCount

Expand All @@ -105,7 +105,7 @@ extension DeduplicationPropsTests {
}

func test_WhenSpecificSubStateMutatingActions_ThenPropsEvaluatedForEveryDeduplicatedMutation() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = actionsCount

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import UIKit

class ViewWithStoreRenderTests: XCTestCase {
let timeout: TimeInterval = 4
let actionDelay: TimeInterval = 0.1
let actionDelay: TimeInterval = 0.2

let state = TestAppState(
subStateWithTitle: SubStateWithTitle(title: ""),
Expand Down Expand Up @@ -97,11 +97,9 @@ extension ViewWithStoreRenderTests {

setupWindowForTests(contentRenderedExpectation: contentRendered)

(0..<actionsCount).forEach {
let delay = actionDelay * Double($0)
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
self?.store.dispatch(UpdateTitle(title: "\(delay)"))
}
(0..<actionsCount).forEach { idx in
let delay = actionDelay * Double(idx)
store.dispatch(UpdateTitle(title: "\(delay)"), after: delay)
}

waitForExpectations(timeout: (actionDelay * Double(actionsCount) * 4))
Expand Down
8 changes: 8 additions & 0 deletions Tests/PureduxTests/TestUtils/StoreExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ extension StateStore {
}
}
}

extension PublishingStore {
func dispatch(_ action: Action, after delay: TimeInterval) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
dispatch(action)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ extension PropsEvaluationWithChildStoreTests {
}

func test_WhenManyNonMutatingActionsAndNeverEqual_ThenPropsEvaluationsDebouncedToOne() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -79,7 +79,7 @@ extension PropsEvaluationWithChildStoreTests {
}

func test_WhenManyMutatingActionsAndDeduplicateNeverEqual_ThenPropsEvaluationsDebouncedToOne() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class AlwaysEqualDeduplicationPropsUIKitTests: XCTestCase {

extension AlwaysEqualDeduplicationPropsUIKitTests {
func test_WhenManyNonMutatingActionsAndNotSubscribedAndDeduplicationAlwaysEqual_ThenPropsNotEvaluated() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.isInverted = true

Expand All @@ -61,7 +61,7 @@ extension AlwaysEqualDeduplicationPropsUIKitTests {
}

func test_WhenManyNonMutatingActionsDeduplicationAlwaysEqual_ThenPropsEvaluatedOnce() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -76,7 +76,7 @@ extension AlwaysEqualDeduplicationPropsUIKitTests {
}

func test_WhenManyMutatingActionsAndDeduplicationAlwaysEqual_ThenPropsEvaluatedOnce() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class DeduplicationPropsUIKitTests: XCTestCase {

extension DeduplicationPropsUIKitTests {
func test_WhenManyNonMutatingActionsAndNotSubscribed_ThenPropsNotEvaluated() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.isInverted = true

Expand All @@ -62,7 +62,7 @@ extension DeduplicationPropsUIKitTests {
}

func test_WhenManyNonMutatingActions_ThenPropsEvaluatedOnce() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -77,7 +77,7 @@ extension DeduplicationPropsUIKitTests {
}

func test_WhenManyMutatingActions_ThenPropsEvaluationsDebouncedToOne() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -92,7 +92,7 @@ extension DeduplicationPropsUIKitTests {
}

func test_WhenMutatingAndNonMutatingActions_ThenPropsEvaluationsDebouncedToOne() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -111,7 +111,7 @@ extension DeduplicationPropsUIKitTests {
}

func test_WhenSpecificSubStateMutatingActions_ThenPropsEvaluationsDebouncedToOne() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extension NoDeduplicationPropsUIKitTests {
}

func test_WhenManyNonMutatingActionsAndDeduplicateNeverEqual_ThenPropsEvaluationDebouncedToOne() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -77,7 +77,7 @@ extension NoDeduplicationPropsUIKitTests {
}

func test_WhenManyMutatingActionsAndDeduplicateNeverEqual_ThenPropsEvaluationDebouncedToOne() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class AlwaysEqualDeduplicationVCTests: XCTestCase {

extension AlwaysEqualDeduplicationVCTests {
func test_WhenManyNonMutatingActionsAndNotSubscribedAndDeduplicationAlwaysEqual_ThenVCNotUpdated() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.isInverted = true

Expand All @@ -63,7 +63,7 @@ extension AlwaysEqualDeduplicationVCTests {
}

func test_WhenManyNonMutatingActionsDeduplicationAlwaysEqual_ThenVCUpdatedOnce() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -78,7 +78,7 @@ extension AlwaysEqualDeduplicationVCTests {
}

func test_WhenManyMutatingActionsAndDeduplicationAlwaysEqual_ThenVCUpdatedOnce() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class DeduplicationVCTests: XCTestCase {

extension DeduplicationVCTests {
func test_WhenManyNonMutatingActionsAndNotSubscribed_ThenVCNotUpdated() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.isInverted = true

Expand All @@ -64,7 +64,7 @@ extension DeduplicationVCTests {
}

func test_WhenManyNonMutatingActions_ThenVCUpdatedOnce() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -79,7 +79,7 @@ extension DeduplicationVCTests {
}

func test_WhenManyMutatingActions_ThenVCUpdatesAreDebouncedToOne() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -94,7 +94,7 @@ extension DeduplicationVCTests {
}

func test_WhenMutatingAndNonMutatingActions_ThenVCUpdatesAreDebouncedToOne() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand All @@ -113,7 +113,7 @@ extension DeduplicationVCTests {
}

func test_WhenSpecificSubStateMutatingActions_ThenVCUpdatesAreDebouncedToOne() {
let actionsCount = 1000
let actionsCount = 10
let expectation = expectation(description: "propsEvaluated")
expectation.expectedFulfillmentCount = 1

Expand Down
Loading

0 comments on commit 0af1a91

Please sign in to comment.