Skip to content

Commit

Permalink
fix: NoopTimer#time(Runnable) should run the Runnable (#4541)
Browse files Browse the repository at this point in the history
  • Loading branch information
joschi authored Oct 21, 2024
1 parent 8442c24 commit 0e29c4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public <T> T timeSupplier(Supplier<T> event) {
*/
@Override
public void time(Runnable event) {
// NOP
event.run();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
Expand Down Expand Up @@ -494,4 +495,13 @@ void registerNullMetric() {
.isThrownBy(() -> registry.register(MetricName.build("any_name"), null))
.withMessage("metric == null");
}

@Test
void timesRunnableInstances() {
Timer timer = registry.timer("thing");
final AtomicBoolean called = new AtomicBoolean();
timer.time(() -> called.set(true));

assertThat(called).isTrue();
}
}

0 comments on commit 0e29c4e

Please sign in to comment.