-
Notifications
You must be signed in to change notification settings - Fork 133
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
RUM-3284 Extension background upload #1803
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d7fe1da
RUM-3284 Add background activity when run from extension
maciejburda 13ec282
RUM-3284 Provide process info background tasks for extensions
maciejburda 23bc3df
RUM-3284 Update CHANGELOG
maciejburda 08ff6dd
Update DatadogCore/Sources/Core/Storage/Directories.swift
maciejburda 1c2c466
RUM-3284 Fix after rebase
maciejburda a14f506
RUM-3284 Clean up after rebase
maciejburda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
question/ Because
beginBackgroundTask()
is called right before the SDK starts uploading data, how does it correspond to the explanation of0xdead10cc
?Apple suggestion is to wrap "file write" operations with
.beginActivity()
and.endActivity()
. What we seem to do instead is wrapping data uploads. Considering that upload starts after the file was read and it has nothing to do with file writes (which are decoupled SDK routine), I'm not seeing clearly how this solves the0xdead10cc
problem.Shouldn't we instead use
.beginActivity()
and.endActivity()
when writing to files, instead of when performing data upload 🤔💭?