Skip to content
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

[CIVIS-9813] Fix for test sdk integration #1852

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions DatadogCore/Sources/FeaturesIntegration/CITestIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ internal class CITestIntegration {
let testExecutionId: String
/// Tag that must be added to spans and headers when running inside a CIApp test
let origin = "ciapp-test"
// UUID for test process message channel
private let messageChannelUUID: String?

private init?(processInfo: ProcessInfo = .processInfo) {
guard let testID = processInfo.environment["CI_VISIBILITY_TEST_EXECUTION_ID"] else {
return nil
}
self.testExecutionId = testID
self.messageChannelUUID = processInfo.environment["CI_VISIBILITY_MESSAGE_CHANNEL_UUID"]
}

/// Entry point for running all the tasks needed for CIApp integration
Expand All @@ -38,7 +41,10 @@ internal class CITestIntegration {
/// created in the CIApp framework
private func notifyRUMSession() {
let timeout: CFTimeInterval = 1.0
guard let remotePort = CFMessagePortCreateRemote(nil, "DatadogTestingPort" as CFString) else {

guard let remotePort = CFMessagePortCreateRemote(
nil, messagePortId(name: "DatadogTestingPort")
) else {
return
}
CFMessagePortSendRequest(
Expand All @@ -65,10 +71,18 @@ internal class CITestIntegration {
return nil
}

guard let port = CFMessagePortCreateLocal(nil, "DatadogRUMTestingPort" as CFString, attributeCallback, nil, nil) else {
guard let port = CFMessagePortCreateLocal(
nil, messagePortId(name: "DatadogRUMTestingPort"), attributeCallback, nil, nil
) else {
return
}
let runLoopSource = CFMessagePortCreateRunLoopSource(nil, port, 0)
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, CFRunLoopMode.commonModes)
}

/// Creates a ID for message port. If UUID is provided joins name with UUID.
/// Fallbacks to name if UUID is nil for backward compatibility
private func messagePortId(name: String) -> CFString {
(messageChannelUUID.map { "\(name)-\($0)" } ?? name) as CFString
}
}