Skip to content
Merged
Show file tree
Hide file tree
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: 17 additions & 1 deletion IntegrationTests/Runner/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,24 @@ struct XcodeTestRunner: Sendable {
environment: config.environment,
server: self.backend.baseURL)
print("note: [IntegrationTestRunner]: test \(testBundle)/\(test) finished, status: \(status).")
let requests = self.backend.requests
defer { self.backend.reset() }
try await function(self.backend.requests, status == 0, config)
// Propagate device/OS tags from the inner test process to the outer runner span.
// The runner always executes on macOS; for simulator platforms the inner tests
// carry the real simulator device info that would otherwise be absent.
if let span = requests.allSpans.first(where: { $0.meta[DDOSTags.osPlatform] != nil }),
let osPlatform = span.meta[DDOSTags.osPlatform],
osPlatform != "macOS",
let currentTest = DDTest.current
{
for key in [DDOSTags.osPlatform, DDOSTags.osArchitecture, DDOSTags.osVersion,
DDDeviceTags.deviceName, DDDeviceTags.deviceModel] {
if let value = span.meta[key] {
currentTest.set(tag: key, value: value)
}
}
}
try await function(requests, status == 0, config)
}
activeTests[module] = Task { let _ = await task.result }
try await task.value
Expand Down
34 changes: 17 additions & 17 deletions Tests/TestUtils/MockBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ extension MockBackend {

func extend(metadata: borrowing [String: [String: String]]) -> Self {
switch self {
case .span(let span): return .span(span.extend(metadata: metadata))
case .test(let span): return .test(span.extend(metadata: metadata))
case .span(let span): return .span(span.extend(metadata: metadata, includeTestLevels: false))
case .test(let span): return .test(span.extend(metadata: metadata, includeTestLevels: true))
case .suiteEnd(let event): return .suiteEnd(event.extend(type: CodingKeys.suiteEnd.rawValue,
metadata: metadata))
case .moduleEnd(let event): return .moduleEnd(event.extend(type: CodingKeys.moduleEnd.rawValue,
Expand Down Expand Up @@ -629,14 +629,15 @@ extension MockBackend {
case itrCorrelationId = "itr_correlation_id"
}

func extend(metadata: borrowing [String: [String: String]]) -> Self {
var meta = self.meta
if let typed = metadata[type] {
meta.merge(typed) { a, b in a }
}
if let common = metadata["*"] {
meta.merge(common) { a, b in a }
}
func extend(metadata: borrowing [String: [String: String]], includeTestLevels: Bool) -> Self {
// Priority (highest to lowest): span.meta > metadata[type] > metadata["test_levels"] > metadata["*"]
// "test_levels" only applies to test* spans, not generic "span" events.
// Build from lowest priority up; { a, _ in a } keeps the already-accumulated value.
var meta = [String: String]()
if let common = metadata["*"] { meta.merge(common) { a, _ in a } }
if includeTestLevels, let levels = metadata["test_levels"] { meta.merge(levels) { a, _ in a } }
if let typed = metadata[type] { meta.merge(typed) { a, _ in a } }
meta.merge(self.meta) { a, _ in a }
return .init(traceId: traceId, spanId: spanId, parentId: parentId,
testSessionId: testSessionId, testModuleId: testModuleId,
testSuiteId: testSuiteId, name: name, service: service,
Expand Down Expand Up @@ -666,13 +667,12 @@ extension MockBackend {
}

func extend(type: String, metadata: borrowing [String: [String: String]]) -> Self {
var meta = self.meta
if let typed = metadata[type] {
meta.merge(typed) { a, b in a }
}
if let common = metadata["*"] {
meta.merge(common) { a, b in a }
}
// Priority (highest to lowest): span.meta > metadata[type] > metadata["test_levels"] > metadata["*"]
var meta = [String: String]()
if let common = metadata["*"] { meta.merge(common) { a, _ in a } }
if let levels = metadata["test_levels"] { meta.merge(levels) { a, _ in a } }
if let typed = metadata[type] { meta.merge(typed) { a, _ in a } }
meta.merge(self.meta) { a, _ in a }
return .init(testSessionId: testSessionId, testModuleId: testModuleId,
testSuiteId: testSuiteId, name: name, service: service,
resource: resource, start: start, duration: duration,
Expand Down
Loading