Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into armcknight/ref/profil…
Browse files Browse the repository at this point in the history
…er-mocks
  • Loading branch information
armcknight committed Jul 11, 2023
2 parents dea1676 + 596ccc1 commit b9c22e6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3112,6 +3112,7 @@
8454CF8B293EAF9A006AC140 /* SentryMetricProfiler.mm */,
03F84D1127DD414C008FE43F /* SentryProfiler.h */,
03F84D2B27DD4191008FE43F /* SentryProfiler.mm */,
84A888FC28D9B11700C51DFD /* SentryProfiler+Test.h */,
84A888FC28D9B11700C51DFD /* SentryProfiler+Private.h */,
0354A22A2A134D9C003C3A04 /* SentryProfilerState.h */,
84281C642A57D36100EE88F2 /* SentryProfilerState+ObjCpp.h */,
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryProfilerTests/SentryBacktraceTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ - (void)testCollectsMultiThreadBacktrace
break;
}
std::this_thread::sleep_for(
std::chrono::milliseconds(static_cast<long long>(std::pow(2, i + 1)) * 1000));
std::chrono::milliseconds(static_cast<long long>(std::pow(2, i + 1))));
}

XCTAssertEqual(pthread_cancel(thread1), 0);
Expand Down
8 changes: 5 additions & 3 deletions Tests/SentryProfilerTests/SentrySamplingProfilerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ - (void)testProfiling
profiler->startSampling([&start] { start = getAbsoluteTime(); });
XCTAssertTrue(profiler->isSampling());

std::this_thread::sleep_for(std::chrono::seconds(3));
// sleep long enough for 2 samples to be collected
const auto sleep = (uint64_t)(2.0 / samplingRateHz * 1000);
std::this_thread::sleep_for(std::chrono::milliseconds(sleep));

profiler->stopSampling();

XCTAssertFalse(profiler->isSampling());

const auto duration = std::chrono::nanoseconds(getDurationNs(start, getAbsoluteTime()));
XCTAssertGreaterThan(start, static_cast<std::uint64_t>(0));
XCTAssertGreaterThan(std::chrono::duration_cast<std::chrono::seconds>(duration).count(), 0);
XCTAssertGreaterThan(getDurationNs(start, getAbsoluteTime()), 0ULL);
XCTAssertGreaterThan(profiler->numSamples(), static_cast<std::uint64_t>(0));
XCTAssertGreaterThan(numIdleSamples, 0);
}
Expand Down
16 changes: 11 additions & 5 deletions Tests/SentryProfilerTests/SentryThreadMetadataCacheTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ - (void)testRetrievesThreadMetadata
SENTRY_PROF_LOG_ERROR_RETURN(pthread_setschedparam(thread, policy, &param));
}

std::this_thread::sleep_for(std::chrono::seconds(1));
// give the other thread a little time to spawn, otherwise its name comes back as an empty
// string and the isSentryOwnedThreadName check will fail
std::this_thread::sleep_for(std::chrono::milliseconds(10));

const auto cache = std::make_shared<ThreadMetadataCache>();
ThreadHandle handle(pthread_mach_thread_np(thread));
Expand All @@ -72,7 +74,9 @@ - (void)testReturnsCachedThreadMetadata
SENTRY_PROF_LOG_ERROR_RETURN(pthread_setschedparam(thread, policy, &param));
}

std::this_thread::sleep_for(std::chrono::seconds(1));
// give the other thread a little time to spawn, otherwise its metadata doesn't come back as
// expected
std::this_thread::sleep_for(std::chrono::milliseconds(10));

const auto cache = std::make_shared<ThreadMetadataCache>();
ThreadHandle handle(pthread_mach_thread_np(thread));
Expand All @@ -94,11 +98,13 @@ - (void)testIgnoresSentryOwnedThreads
char name[] = "io.sentry.SentryThreadMetadataCacheTests";
XCTAssertEqual(pthread_create(&thread, nullptr, threadSpin, reinterpret_cast<void *>(name)), 0);

std::this_thread::sleep_for(std::chrono::seconds(1));
// give the other thread a little time to spawn, otherwise its name comes back as an empty
// string and the isSentryOwnedThreadName check will fail
std::this_thread::sleep_for(std::chrono::milliseconds(10));

const auto cache = std::make_shared<ThreadMetadataCache>();
ThreadHandle handle(pthread_mach_thread_np(thread));
XCTAssertEqual(cache->metadataForThread(handle).threadID, static_cast<unsigned long long>(0));
XCTAssertEqual(cache->metadataForThread(handle).threadID, 0ULL);

XCTAssertEqual(pthread_cancel(thread), 0);
XCTAssertEqual(pthread_join(thread, nullptr), 0);
Expand All @@ -120,7 +126,7 @@ - (void)testNonexistentQueueAddressReturnsNoMetadata
const auto cache = std::make_shared<ThreadMetadataCache>();
const auto metadata = cache->metadataForQueue(0);

XCTAssertEqual(metadata.address, static_cast<unsigned long long>(0));
XCTAssertEqual(metadata.address, 0ULL);
XCTAssertEqual(metadata.label, nullptr);
}

Expand Down

0 comments on commit b9c22e6

Please sign in to comment.