Skip to content

Commit

Permalink
Increment functional test wait time to increase stability on CI (#13)
Browse files Browse the repository at this point in the history
* Increment functional test wait time to increase stability on CI

* increase wait time to 2 seconds

* Add upload coverage as a separate task in CI and upload all coverage files together for faster build time

* fix ci step

* Update coverage folder path

* try to upload multiple coverage files together

* Revert ci changes

* Update wait logic for functional tests

* Added errorResponse test

* bump up test wait time

* Added more unit tests

* Increase wait timeout for functional tests

* Update time for failing test case

* update wait logic for tests
  • Loading branch information
addb authored Mar 9, 2023
1 parent 04618f2 commit 2aab69b
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,4 @@ jobs:
command: |
if [ "${CIRCLE_BRANCH}" == "main" ]; then
make build-app
fi
fi
18 changes: 15 additions & 3 deletions AEPEdgeMedia.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
2EB164F3289AF59C00089C83 /* MediaEventGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EB164F2289AF59C00089C83 /* MediaEventGenerator.swift */; };
2EB164F5289AF63900089C83 /* MockExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EB164F4289AF63900089C83 /* MockExtension.swift */; };
2EB164F7289AF6B900089C83 /* TestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EB164F6289AF6B900089C83 /* TestHelpers.swift */; };
2EC3C49329B98C6900B4308B /* MediaTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EC3C49229B98C6900B4308B /* MediaTests.swift */; };
2EC3C49529B98CFF00B4308B /* TestableExtensionRuntime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EC3C49429B98CFF00B4308B /* TestableExtensionRuntime.swift */; };
2EC3C49729B98D2800B4308B /* MockDataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EC3C49629B98D2800B4308B /* MockDataStore.swift */; };
2EC6027028EB589600C07D5A /* MediaXDMEventHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EC6026F28EB589600C07D5A /* MediaXDMEventHelperTests.swift */; };
2EC6027228EB797B00C07D5A /* AssertUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EC6027128EB797B00C07D5A /* AssertUtils.swift */; };
2ED7125728ADA958006A83D0 /* MediaRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ED7125428ADA958006A83D0 /* MediaRule.swift */; };
Expand Down Expand Up @@ -247,6 +250,9 @@
2EB164F2289AF59C00089C83 /* MediaEventGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediaEventGenerator.swift; sourceTree = "<group>"; };
2EB164F4289AF63900089C83 /* MockExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockExtension.swift; sourceTree = "<group>"; };
2EB164F6289AF6B900089C83 /* TestHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestHelpers.swift; sourceTree = "<group>"; };
2EC3C49229B98C6900B4308B /* MediaTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaTests.swift; sourceTree = "<group>"; };
2EC3C49429B98CFF00B4308B /* TestableExtensionRuntime.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestableExtensionRuntime.swift; sourceTree = "<group>"; };
2EC3C49629B98D2800B4308B /* MockDataStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockDataStore.swift; sourceTree = "<group>"; };
2EC6026F28EB589600C07D5A /* MediaXDMEventHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaXDMEventHelperTests.swift; sourceTree = "<group>"; };
2EC6027128EB797B00C07D5A /* AssertUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssertUtils.swift; sourceTree = "<group>"; };
2ED7125428ADA958006A83D0 /* MediaRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediaRule.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -375,6 +381,8 @@
2E4D752E2979E59F00396819 /* Utils */ = {
isa = PBXGroup;
children = (
2EC3C49629B98D2800B4308B /* MockDataStore.swift */,
2EC3C49429B98CFF00B4308B /* TestableExtensionRuntime.swift */,
2EC6027128EB797B00C07D5A /* AssertUtils.swift */,
2E4D8172293954F6005A4543 /* FakeMediaEventProcessor.swift */,
2E37D38928D4185B00B782F8 /* MediaSessionSpy.swift */,
Expand Down Expand Up @@ -507,6 +515,7 @@
2ED7125E28ADC424006A83D0 /* MediaRuleEngineTests.swift */,
2E459865290B7144003111EE /* MediaRealTimeSessionTests.swift */,
2ED7126628ADDF5B006A83D0 /* MediaStateTests.swift */,
2EC3C49229B98C6900B4308B /* MediaTests.swift */,
2E459863290A2EEC003111EE /* MediaXDMEventTests.swift */,
2E3BF82F28D961440043DD00 /* MediaXDMEventGeneratorTests.swift */,
2EC6026F28EB589600C07D5A /* MediaXDMEventHelperTests.swift */,
Expand Down Expand Up @@ -933,7 +942,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if [[ -z ${ADB_SKIP_LINT} || ${ADB_SKIP_LINT} -ne \"YES\" ]]; then\n if which \"${PODS_ROOT}/SwiftLint/swiftlint\" >/dev/null; then\n ./Pods/SwiftLint/swiftlint lint --config Tests/TestHelpers/.swiftlint.yml --lenient Tests/IntegrationTests Tests/TestHelpers\n else\n echo \"warning: SwiftLint is not installed, please run the pod install command from the project root directory.\"\n fi\nelse\n echo \"Skipping linting build phase as ADB_SKIP_LINT flag is YES.\"\nfi\n";
shellScript = "if [[ -z ${ADB_SKIP_LINT} || ${ADB_SKIP_LINT} -ne \"YES\" ]]; then\n if which \"${PODS_ROOT}/SwiftLint/swiftlint\" >/dev/null; then\n ./Pods/SwiftLint/swiftlint lint --config Tests/.swiftlint.yml --lenient Tests/IntegrationTests Tests/TestHelpers\n else\n echo \"warning: SwiftLint is not installed, please run the pod install command from the project root directory.\"\n fi\nelse\n echo \"Skipping linting build phase as ADB_SKIP_LINT flag is YES.\"\nfi\n";
};
2E0A1C39299703CB0099C134 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -950,7 +959,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if [[ -z ${ADB_SKIP_LINT} || ${ADB_SKIP_LINT} -ne \"YES\" ]]; then\n if which \"${PODS_ROOT}/SwiftLint/swiftlint\" >/dev/null; then\n ./Pods/SwiftLint/swiftlint lint --config Tests/TestHelpers/.swiftlint.yml --lenient Tests/FunctionalTests Tests/TestHelpers\n else\n echo \"warning: SwiftLint is not installed, please run the pod install command from the project root directory.\"\n fi\nelse\n echo \"Skipping linting build phase as ADB_SKIP_LINT flag is YES.\"\nfi\n";
shellScript = "if [[ -z ${ADB_SKIP_LINT} || ${ADB_SKIP_LINT} -ne \"YES\" ]]; then\n if which \"${PODS_ROOT}/SwiftLint/swiftlint\" >/dev/null; then\n ./Pods/SwiftLint/swiftlint lint --config Tests/.swiftlint.yml --lenient Tests/FunctionalTests Tests/TestHelpers\n else\n echo \"warning: SwiftLint is not installed, please run the pod install command from the project root directory.\"\n fi\nelse\n echo \"Skipping linting build phase as ADB_SKIP_LINT flag is YES.\"\nfi\n";
};
2E0A1C3A299703D00099C134 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -967,7 +976,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if [[ -z ${ADB_SKIP_LINT} || ${ADB_SKIP_LINT} -ne \"YES\" ]]; then\n if which \"${PODS_ROOT}/SwiftLint/swiftlint\" >/dev/null; then\n ./Pods/SwiftLint/swiftlint lint --config Tests/TestHelpers/.swiftlint.yml --lenient Tests/UnitTests Tests/TestHelpers\n else\n echo \"warning: SwiftLint is not installed, please run the pod install command from the project root directory.\"\n fi\nelse\n echo \"Skipping linting build phase as ADB_SKIP_LINT flag is YES.\"\nfi\n";
shellScript = "if [[ -z ${ADB_SKIP_LINT} || ${ADB_SKIP_LINT} -ne \"YES\" ]]; then\n if which \"${PODS_ROOT}/SwiftLint/swiftlint\" >/dev/null; then\n ./Pods/SwiftLint/swiftlint lint --config Tests/.swiftlint.yml --lenient Tests/UnitTests Tests/TestHelpers\n else\n echo \"warning: SwiftLint is not installed, please run the pod install command from the project root directory.\"\n fi\nelse\n echo \"Skipping linting build phase as ADB_SKIP_LINT flag is YES.\"\nfi\n";
};
3E694DE201739FFC9E121BF0 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -1261,6 +1270,7 @@
buildActionMask = 2147483647;
files = (
2E4D8173293954F6005A4543 /* FakeMediaEventProcessor.swift in Sources */,
2EC3C49529B98CFF00B4308B /* TestableExtensionRuntime.swift in Sources */,
2EA7BC2928C04796001A7C2A /* XDMChapterDetailsTests.swift in Sources */,
2E459866290B7144003111EE /* MediaRealTimeSessionTests.swift in Sources */,
2E37D38828D416C100B782F8 /* MediaEventProcessorTests.swift in Sources */,
Expand All @@ -1276,6 +1286,7 @@
2E3BF83028D961440043DD00 /* MediaXDMEventGeneratorTests.swift in Sources */,
2EC6027228EB797B00C07D5A /* AssertUtils.swift in Sources */,
2EA7BC2328C02F79001A7C2A /* TestUtils.swift in Sources */,
2EC3C49329B98C6900B4308B /* MediaTests.swift in Sources */,
2EDFBCF62899E06300D22B25 /* MediaPublicTrackerTests.swift in Sources */,
2ED7126928ADDFC0006A83D0 /* TestConstants.swift in Sources */,
2EC6027028EB589600C07D5A /* MediaXDMEventHelperTests.swift in Sources */,
Expand All @@ -1289,6 +1300,7 @@
2EA7BC2528C035FF001A7C2A /* XDMAdvertisingPodDetailsTests.swift in Sources */,
2E37D38B28D4186000B782F8 /* MediaSessionSpy.swift in Sources */,
2E459868290B8585003111EE /* XDMDataHelper.swift in Sources */,
2EC3C49729B98D2800B4308B /* MockDataStore.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
5 changes: 4 additions & 1 deletion Tests/TestHelpers/.swiftlint.yml → Tests/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ file_length:
warning: 1200
error: 1500
ignore_comment_only_lines: true
identifier_name:
identifier_name:
max_length:
warning: 50
error: 60
allowed_symbols: "_"
excluded:
- id
Expand Down
9 changes: 7 additions & 2 deletions Tests/FunctionalTests/Scenarios/BaseScenarioTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BaseScenarioTest: XCTestCase {
var dispatchedEvents: [Event] = []
var mediaState: MediaState!

static let DEFAULT_WAIT_TIMEOUT = TimeInterval(0.5)
static let DEFAULT_WAIT_TIMEOUT = TimeInterval(1)

func getMediaSessions() -> [String: MediaSession] {
return mediaEventProcessorSpy.mediaSessions
Expand All @@ -32,6 +32,7 @@ class BaseScenarioTest: XCTestCase {
}

func setup() {
self.dispatchedEvents = []
self.mediaEventProcessorSpy = MediaEventProcessorSpy(dispatcher: fakeDispatcher(_:))
self.mediaState = MediaState()
createTracker()
Expand Down Expand Up @@ -83,6 +84,10 @@ class BaseScenarioTest: XCTestCase {
}

func wait(_ interval: TimeInterval = DEFAULT_WAIT_TIMEOUT) {
Thread.sleep(forTimeInterval: interval)
let expectation = XCTestExpectation()
DispatchQueue.global().asyncAfter(deadline: DispatchTime.now() + interval - 0.1) {
expectation.fulfill()
}
wait(for: [expectation], timeout: interval)
}
}
2 changes: 1 addition & 1 deletion Tests/FunctionalTests/Scenarios/SpecialAdPlayback.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class SpecialAdPlayback: BaseScenarioTest {

// test
mediaTracker.trackSessionStart(info: mediaInfoWithDefaultPreroll.toMap(), metadata: mediaMetadata)
wait()
wait(4)

// mock sessionIDUpdate
mediaEventProcessorSpy.mockBackendSessionId(sessionId: curSessionId, sessionStartEvent: dispatchedEvents[0], fakeBackendId: backendSessionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class EdgeMediaIntegrationTests: FunctionalTestBase {
let testBackendSessionId = "99cf4e3e7145d8e2b8f4f1e9e1a08cd52518a74091c0b0c611ca97b259e03a4d"
let successResponseBody = "\u{0000}{\"handle\":[{\"payload\":[{\"sessionId\":\"99cf4e3e7145d8e2b8f4f1e9e1a08cd52518a74091c0b0c611ca97b259e03a4d\"}],\"type\":\"media-analytics:new-session\",\"eventIndex\":0}]}"

let errorResponseBody = "{\"errors\" : [{\"type\" : \"https://ns.adobe.com/aep/errors/va-edge-0404-404\", \"status\" : 404,\"title\" : \"Not Found\", \"detail\" : \"The requested resource could not be found but may be available again in the future.\",\"report\" : {\"details\" : \"Error processing request. If the session is longer than 24h, please start a new one. Returning Not Found\"}}]}"

public class override func setUp() {
super.setUp()
FunctionalTestBase.debugEnabled = true
Expand Down Expand Up @@ -97,6 +99,31 @@ class EdgeMediaIntegrationTests: FunctionalTestBase {
assertXDMData(networkRequest: networkRequests[3], eventType: "sessionComplete", backendSessionId: testBackendSessionId, playhead: 7)
}

func testSessionStartErrorResponse_shouldNotSendAnyOtherNetworkRequests() {
// setup
let responseConnection: HttpConnection = HttpConnection(data: errorResponseBody.data(using: .utf8),
response: HTTPURLResponse(url: URL(string: sessionStartEdgeEndpoint)!,
statusCode: 200,
httpVersion: nil,
headerFields: nil),
error: nil)
setNetworkResponseFor(url: sessionStartEdgeEndpoint, httpMethod: .post, responseHttpConnection: responseConnection)

// test
let tracker = Media.createTracker()
tracker.trackSessionStart(info: mediaInfo, metadata: metadata)
tracker.trackPlay()
tracker.updateCurrentPlayhead(time: 7)
tracker.trackPause()
tracker.trackComplete()

// verify
let networkRequests = getAllNetworkRequests()
XCTAssertEqual(1, networkRequests.count)

assertXDMData(networkRequest: networkRequests[0], eventType: "sessionStart", info: mediaInfo, metadata: metadata, configuration: configuration)
}

func testPlayback_withPrerollAdBreak() {
// setup
let responseConnection: HttpConnection = HttpConnection(data: successResponseBody.data(using: .utf8),
Expand Down
88 changes: 88 additions & 0 deletions Tests/UnitTests/MediaTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Copyright 2023 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

@testable import AEPCore
@testable import AEPEdgeMedia
import AEPServices
import XCTest

class MediaTests: XCTestCase {
var media: Media!
var mockRuntime: TestableExtensionRuntime!
var fakeMediaProcessor: FakeMediaEventProcessor!

override func setUp() {
ServiceProvider.shared.namedKeyValueService = MockDataStore()
mockRuntime = TestableExtensionRuntime()
media = Media(runtime: mockRuntime)
media.onRegistered()

fakeMediaProcessor = FakeMediaEventProcessor()
media.mediaEventProcessor = fakeMediaProcessor
}

func testExtensionVersion() {
XCTAssertEqual(MediaConstants.EXTENSION_VERSION, Media.extensionVersion)
}

func testReadyForEvent() {
let event = Event(name: "test-event", type: "test-type", source: "test-source", data: nil)
XCTAssertTrue(media.readyForEvent(event))
}

func testHandleEdgeErrorResponse_WithoutRequestEventId_doesNotNotifyMediaEventProcessor() {
let event = Event(name: "test-event", type: "test-type", source: "test-source", data: ["key": "value"])
media.handleEdgeErrorResponse(event)
XCTAssertFalse(fakeMediaProcessor.notifyErrorResponseCalled)
}

func testHandleEdgeErrorResponse_WithNilEventData_doesNotNotifyMediaEventProcessor() {
let event = Event(name: "test-event", type: "test-type", source: "test-String", data: nil)
media.handleEdgeErrorResponse(event)
XCTAssertFalse(fakeMediaProcessor.notifyErrorResponseCalled)
}

func testHandleEdgeErrorResponse_WithRequestEventId_notifiesMediaEventProcessor() {
let event = Event(name: "test-event", type: "test-type", source: "test-String", data: [MediaConstants.Edge.EventData.REQUEST_EVENT_ID: "testRequestId", MediaConstants.Edge.ErrorKeys.STATUS: Int64(400), MediaConstants.Edge.ErrorKeys.TYPE: "https://ns.adobe.com/aep/errors/va-edge-0400-400"])
media.handleEdgeErrorResponse(event)
XCTAssertTrue(fakeMediaProcessor.notifyErrorResponseCalled)
XCTAssertEqual(3, fakeMediaProcessor.notifyErrorResponseCalledWithData.count)
XCTAssertEqual("testRequestId", fakeMediaProcessor.notifyErrorResponseCalledWithRequestEventId)
XCTAssertEqual(400, fakeMediaProcessor.notifyErrorResponseCalledWithData[MediaConstants.Edge.ErrorKeys.STATUS] as? Int64 ?? 0)
XCTAssertEqual("https://ns.adobe.com/aep/errors/va-edge-0400-400", fakeMediaProcessor.notifyErrorResponseCalledWithData[MediaConstants.Edge.ErrorKeys.TYPE] as? String ?? "")
}

func testHandleMediaEdgeSessionDetails_WithoutRequestEventId_doesNotNotifyMediaEventProcessor() {
let event = Event(name: "test-event", type: "test-type", source: "test-source", data: ["key": "value"])
media.handleMediaEdgeSessionDetails(event)
XCTAssertFalse(fakeMediaProcessor.notifyBackendSessionIdCalled)
}

func testHandleMediaEdgeSessionDetails_WithNilEventData_doesNotNotifyMediaEventProcessor() {
let event = Event(name: "test-event", type: "test-type", source: "test-String", data: nil)
media.handleMediaEdgeSessionDetails(event)
XCTAssertFalse(fakeMediaProcessor.notifyBackendSessionIdCalled)
}

func testHandleMediaEdgeSessionDetails_WithRequestEventId_notifiesMediaEventProcessor() {
let payload: [[String: Any?]] = [[MediaConstants.Edge.EventData.SESSION_ID: "testBackendSessionId"]]
let data: [String: Any] = [MediaConstants.Edge.EventData.REQUEST_EVENT_ID: "testRequestId",
MediaConstants.Edge.EventData.PAYLOAD: payload]

let event = Event(name: "test-event", type: "test-type", source: "test-String", data: data)
media.handleMediaEdgeSessionDetails(event)
XCTAssertTrue(fakeMediaProcessor.notifyBackendSessionIdCalled)
XCTAssertEqual("testRequestId", fakeMediaProcessor.notifyBackendSessionIdCalledWithRequestEventId)
XCTAssertEqual("testBackendSessionId", fakeMediaProcessor.notifyBackendSessionIdCalledWithBackendSessionId)

}
}
Loading

0 comments on commit 2aab69b

Please sign in to comment.