-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RUM-3284 Provide process info background tasks for extensions
- Loading branch information
1 parent
690fc23
commit 218344a
Showing
6 changed files
with
96 additions
and
16 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
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
66 changes: 66 additions & 0 deletions
66
DatadogCore/Tests/Datadog/Core/Upload/ExtensionBackgroundTaskCoordinatorTests.swift
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,66 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-Present Datadog, Inc. | ||
*/ | ||
|
||
import XCTest | ||
import DatadogInternal | ||
@testable import DatadogCore | ||
|
||
class ExtensionBackgroundTaskCoordinatorTests: XCTestCase { | ||
var processInfoSpy: ProcessInfoSpy! // swiftlint:disable:this implicitly_unwrapped_optional | ||
var coordinator: ExtensionBackgroundTaskCoordinator! // swiftlint:disable:this implicitly_unwrapped_optional | ||
|
||
override func setUp() { | ||
super.setUp() | ||
processInfoSpy = ProcessInfoSpy() | ||
coordinator = ExtensionBackgroundTaskCoordinator( | ||
processInfo: processInfoSpy | ||
) | ||
} | ||
|
||
func testBeginBackgroundTask() { | ||
coordinator?.beginBackgroundTask() | ||
|
||
XCTAssertEqual(processInfoSpy?.beginBackgroundTaskCalled, true) | ||
XCTAssertEqual(processInfoSpy?.endBackgroundTaskCalled, false) | ||
} | ||
|
||
func testEndBackgroundTask() throws { | ||
coordinator?.beginBackgroundTask() | ||
coordinator?.endBackgroundTask() | ||
|
||
XCTAssertEqual(processInfoSpy?.beginBackgroundTaskCalled, true) | ||
XCTAssertEqual(processInfoSpy?.endBackgroundTaskCalled, true) | ||
} | ||
|
||
func testEndBackgroundTaskNotCalledWhenNotBegan() throws { | ||
coordinator?.endBackgroundTask() | ||
|
||
XCTAssertEqual(processInfoSpy?.beginBackgroundTaskCalled, false) | ||
XCTAssertEqual(processInfoSpy?.endBackgroundTaskCalled, false) | ||
} | ||
|
||
func testBeginEndsPreviousTask() throws { | ||
coordinator?.beginBackgroundTask() | ||
coordinator?.beginBackgroundTask() | ||
|
||
XCTAssertEqual(processInfoSpy?.beginBackgroundTaskCalled, true) | ||
XCTAssertEqual(processInfoSpy?.endBackgroundTaskCalled, true) | ||
} | ||
} | ||
|
||
class ProcessInfoSpy: ProcessInfoActivityCoordinator { | ||
var beginBackgroundTaskCalled = false | ||
var endBackgroundTaskCalled = false | ||
|
||
func beginActivity(options: ProcessInfo.ActivityOptions, reason: String) -> any NSObjectProtocol { | ||
beginBackgroundTaskCalled = true | ||
return NSObject() | ||
} | ||
|
||
func endActivity(_ activity: any NSObjectProtocol) { | ||
endBackgroundTaskCalled = true | ||
} | ||
} |