-
Notifications
You must be signed in to change notification settings - Fork 33
Fix flaky StreamVideo tests #1118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,9 +38,10 @@ final class VideoProximityPolicy_Tests: XCTestCase, @unchecked Sendable { | |
|
|
||
| subject.didUpdateProximity(.near, on: mockCall) | ||
|
|
||
| await wait(for: 0.25) | ||
| XCTAssertEqual(mockCallController.timesCalled(.changeVideoState), 0) | ||
| XCTAssertEqual(mockCall.state.incomingVideoQualitySettings, .disabled(group: .all)) | ||
| await assertState( | ||
| incomingVideoQualitySettings: .disabled(group: .all), | ||
| timesCalledChangeVideoState: 0 | ||
| ) | ||
| } | ||
|
|
||
| func test_didUpdateProximity_near_videoTrue_incomingVideoQualitySettingsNone_incomingVideoQualitySettingsAndCameraDisabled( | ||
|
|
@@ -50,9 +51,10 @@ final class VideoProximityPolicy_Tests: XCTestCase, @unchecked Sendable { | |
|
|
||
| subject.didUpdateProximity(.near, on: mockCall) | ||
|
|
||
| await wait(for: 0.25) | ||
| XCTAssertEqual(mockCallController.timesCalled(.changeVideoState), 1) | ||
| XCTAssertEqual(mockCall.state.incomingVideoQualitySettings, .disabled(group: .all)) | ||
| await assertState( | ||
| incomingVideoQualitySettings: .disabled(group: .all), | ||
| timesCalledChangeVideoState: 1 | ||
| ) | ||
| } | ||
|
|
||
| func test_didUpdateProximity_near_videoFalse_incomingVideoQualitySettingsOtherThanNone_incomingVideoQualitySettingsAndCameraDisabled( | ||
|
|
@@ -62,9 +64,10 @@ final class VideoProximityPolicy_Tests: XCTestCase, @unchecked Sendable { | |
|
|
||
| subject.didUpdateProximity(.near, on: mockCall) | ||
|
|
||
| await wait(for: 0.25) | ||
| XCTAssertEqual(mockCallController.timesCalled(.changeVideoState), 0) | ||
| XCTAssertEqual(mockCall.state.incomingVideoQualitySettings, .disabled(group: .all)) | ||
| await assertState( | ||
| incomingVideoQualitySettings: .disabled(group: .all), | ||
| timesCalledChangeVideoState: 0 | ||
| ) | ||
| } | ||
|
|
||
| func test_didUpdateProximity_far_noCachedValue_nothingHappens() async { | ||
|
|
@@ -73,36 +76,45 @@ final class VideoProximityPolicy_Tests: XCTestCase, @unchecked Sendable { | |
|
|
||
| subject.didUpdateProximity(.far, on: mockCall) | ||
|
|
||
| await wait(for: 0.25) | ||
| XCTAssertEqual(mockCallController.timesCalled(.changeVideoState), 0) | ||
| XCTAssertEqual(mockCall.state.incomingVideoQualitySettings, .manual(group: .all, targetSize: .quarter)) | ||
| await assertState( | ||
| incomingVideoQualitySettings: .manual(group: .all, targetSize: .quarter), | ||
| timesCalledChangeVideoState: 0 | ||
| ) | ||
| } | ||
|
|
||
| func test_didUpdateProximity_far_cachedValueWithIncomingQualitySettingsAndVideoOff_incomingVideoQualitySettingsUpdated() async { | ||
| mockCall.state.callSettings = .init(videoOn: false) | ||
| mockCall.state.incomingVideoQualitySettings = .manual(group: .all, targetSize: .quarter) | ||
|
|
||
| subject.didUpdateProximity(.near, on: mockCall) | ||
| await wait(for: 0.25) | ||
| await assertState( | ||
| incomingVideoQualitySettings: .disabled(group: .all), | ||
| timesCalledChangeVideoState: 0 | ||
| ) | ||
| subject.didUpdateProximity(.far, on: mockCall) | ||
|
|
||
| await wait(for: 0.25) | ||
| XCTAssertEqual(mockCallController.timesCalled(.changeVideoState), 0) | ||
| XCTAssertEqual(mockCall.state.incomingVideoQualitySettings, .manual(group: .all, targetSize: .quarter)) | ||
| await assertState( | ||
| incomingVideoQualitySettings: .manual(group: .all, targetSize: .quarter), | ||
| timesCalledChangeVideoState: 0 | ||
| ) | ||
| } | ||
|
|
||
| func test_didUpdateProximity_far_cachedValueWithoutIncomingQualitySettingsAndVideoOn_videoWasUpdated() async { | ||
| mockCall.state.callSettings = .init(videoOn: true) | ||
| mockCall.state.incomingVideoQualitySettings = .none | ||
|
|
||
| subject.didUpdateProximity(.near, on: mockCall) | ||
| await wait(for: 0.25) | ||
| await assertState( | ||
| incomingVideoQualitySettings: .disabled(group: .all), | ||
| timesCalledChangeVideoState: 1 | ||
| ) | ||
| subject.didUpdateProximity(.far, on: mockCall) | ||
|
|
||
| await wait(for: 0.25) | ||
| XCTAssertEqual(mockCallController.timesCalled(.changeVideoState), 2) | ||
| XCTAssertEqual(mockCallController.recordedInputPayload(Bool.self, for: .changeVideoState)?.last, true) | ||
| XCTAssertEqual(mockCall.state.incomingVideoQualitySettings, .none) | ||
| await assertState( | ||
| incomingVideoQualitySettings: .none, | ||
| timesCalledChangeVideoState: 2, | ||
| lastChangeVideoStateValue: true | ||
| ) | ||
| } | ||
|
|
||
| func test_didUpdateProximity_far_cachedValueWithIncomingQualitySettingsAndVideoOn_incomingVideoQualitySettingsAndVideoWereUpdated( | ||
|
|
@@ -111,12 +123,53 @@ final class VideoProximityPolicy_Tests: XCTestCase, @unchecked Sendable { | |
| mockCall.state.incomingVideoQualitySettings = .manual(group: .all, targetSize: .quarter) | ||
|
|
||
| subject.didUpdateProximity(.near, on: mockCall) | ||
| await wait(for: 0.25) | ||
| await assertState( | ||
| incomingVideoQualitySettings: .disabled(group: .all), | ||
| timesCalledChangeVideoState: 1 | ||
| ) | ||
| subject.didUpdateProximity(.far, on: mockCall) | ||
|
|
||
| await wait(for: 0.25) | ||
| XCTAssertEqual(mockCallController.timesCalled(.changeVideoState), 2) | ||
| XCTAssertEqual(mockCallController.recordedInputPayload(Bool.self, for: .changeVideoState)?.last, true) | ||
| XCTAssertEqual(mockCall.state.incomingVideoQualitySettings, .manual(group: .all, targetSize: .quarter)) | ||
| await assertState( | ||
| incomingVideoQualitySettings: .manual(group: .all, targetSize: .quarter), | ||
| timesCalledChangeVideoState: 2, | ||
| lastChangeVideoStateValue: true | ||
| ) | ||
| } | ||
|
|
||
| // MARK: - Private helpers | ||
|
|
||
| private func assertState( | ||
| incomingVideoQualitySettings expectedIncomingVideoQualitySettings: IncomingVideoQualitySettings, | ||
| timesCalledChangeVideoState expectedTimesCalledChangeVideoState: Int, | ||
| lastChangeVideoStateValue expectedLastChangeVideoStateValue: Bool? = nil, | ||
| file: StaticString = #filePath, | ||
| line: UInt = #line | ||
| ) async { | ||
| await fulfilmentInMainActor(timeout: 2, filePath: file, line: line) { | ||
| self.mockCall.state.incomingVideoQualitySettings == expectedIncomingVideoQualitySettings | ||
| && self.mockCallController.timesCalled(.changeVideoState) == expectedTimesCalledChangeVideoState | ||
| } | ||
|
Comment on lines
+141
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 148 uses 🤖 Prompt for AI Agents |
||
|
|
||
| XCTAssertEqual( | ||
| mockCallController.timesCalled(.changeVideoState), | ||
| expectedTimesCalledChangeVideoState, | ||
| file: file, | ||
| line: line | ||
| ) | ||
| XCTAssertEqual( | ||
| mockCall.state.incomingVideoQualitySettings, | ||
| expectedIncomingVideoQualitySettings, | ||
| file: file, | ||
| line: line | ||
| ) | ||
|
|
||
| if let expectedLastChangeVideoStateValue { | ||
| XCTAssertEqual( | ||
| mockCallController.recordedInputPayload(Bool.self, for: .changeVideoState)?.last, | ||
| expectedLastChangeVideoStateValue, | ||
| file: file, | ||
| line: line | ||
| ) | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That same behavior is already covered directly in CallState_Tests.swift (line 224), CallState_Tests.swift (line 237), and CallState_Tests.swift (line 278).