Skip to content

Commit db78740

Browse files
committed
instrument: fix flakyness in thread-safety tests
Signed-off-by: inge4pres <[email protected]>
1 parent 08f2966 commit db78740

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/api/metrics/instrument.zig

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,11 @@ fn testCounterAddingOne(counter: *Counter(u64)) !void {
744744

745745
fn testCounterCollect(counter: *Counter(u64)) !void {
746746
// FIXME flaky test can result in failure, so we added a sleep but we should find a more robust solution.
747-
while (!counter.lock.tryLock()) {
748-
std.time.sleep(44);
747+
for (0..1000) |_| {
748+
counter.lock.lock();
749+
counter.lock.unlock();
750+
std.time.sleep(25);
749751
}
750-
counter.lock.unlock();
751752

752753
const fetched = try counter.measurementsData(std.testing.allocator);
753754
defer {
@@ -789,10 +790,11 @@ fn testHistogramRecordOne(histogram: *Histogram(u64)) !void {
789790

790791
fn testHistogramCollect(histogram: *Histogram(u64)) !void {
791792
// FIXME flaky test can result in failure, so we added a sleep but we should find a more robust solution.
792-
while (!histogram.lock.tryLock()) {
793-
std.time.sleep(44);
793+
for (0..1000) |_| {
794+
histogram.lock.lock();
795+
histogram.lock.unlock();
796+
std.time.sleep(25);
794797
}
795-
histogram.lock.unlock();
796798

797799
const fetched = try histogram.measurementsData(std.testing.allocator);
798800
defer {

0 commit comments

Comments
 (0)