Skip to content

Commit

Permalink
Top-level isSimulated accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Mar 10, 2022
1 parent aa948f7 commit 1b6a0a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Sources/Meter/DiagnosticPayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ public class DiagnosticPayload: Codable {

return (try? encoder.encode(self)) ?? Data()
}

public var isSimulated: Bool {
if crashDiagnostics?.allSatisfy({ $0.isSimulated }) == false {
return false
}

if hangDiagnostics?.allSatisfy({ $0.isSimulated }) == false {
return false
}

if cpuExceptionDiagnostics?.allSatisfy({ $0.isSimulated }) == false {
return false
}

if diskWriteExceptionDiagnostics?.allSatisfy({ $0.isSimulated }) == false {
return false
}

return true
}
}

public extension DiagnosticPayload {
Expand Down
9 changes: 9 additions & 0 deletions Tests/MeterTests/DiagnosticTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class DiagnosticTests: XCTestCase {

XCTAssertEqual(payload.timeStampBegin, Date(timeIntervalSince1970: 1602358524))
XCTAssertEqual(payload.timeStampEnd, Date(timeIntervalSince1970: 1602358524))
XCTAssertTrue(payload.isSimulated)

XCTAssertEqual(payload.crashDiagnostics?.count, 1)
let crashDiagnostic = try XCTUnwrap(payload.crashDiagnostics?[0])
Expand Down Expand Up @@ -53,6 +54,8 @@ class DiagnosticTests: XCTestCase {

let payload = try XCTUnwrap(DiagnosticPayload.from(data: data))

XCTAssertTrue(payload.isSimulated)

XCTAssertEqual(payload.crashDiagnostics?.count, 1)

let crashDiagnostic = try XCTUnwrap(payload.crashDiagnostics?[0])
Expand All @@ -74,6 +77,8 @@ class DiagnosticTests: XCTestCase {

let payload = try XCTUnwrap(DiagnosticPayload.from(data: data))

XCTAssertTrue(payload.isSimulated)

XCTAssertEqual(payload.hangDiagnostics?.count, 1)
let diagnostic = try XCTUnwrap(payload.hangDiagnostics?[0])

Expand Down Expand Up @@ -102,6 +107,8 @@ class DiagnosticTests: XCTestCase {

let payload = try XCTUnwrap(DiagnosticPayload.from(data: data))

XCTAssertTrue(payload.isSimulated)

XCTAssertEqual(payload.cpuExceptionDiagnostics?.count, 1)
let diagnostic = try XCTUnwrap(payload.cpuExceptionDiagnostics?[0])

Expand All @@ -124,6 +131,8 @@ class DiagnosticTests: XCTestCase {
let data = try Data(contentsOf: url, options: [])
let payload = try DiagnosticPayload.from(data: data)

XCTAssertFalse(payload.isSimulated)

XCTAssertEqual(payload.crashDiagnostics?.count, 2)

let crashDiagnostic = try XCTUnwrap(payload.crashDiagnostics?[0])
Expand Down

0 comments on commit 1b6a0a5

Please sign in to comment.