Skip to content

Commit

Permalink
fix: NoopTimer#time(Runnable) should run the Runnable (#4540)
Browse files Browse the repository at this point in the history
  • Loading branch information
joschi authored Oct 21, 2024
1 parent 8641ac5 commit 4f6fc57
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 @@ -432,7 +432,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 @@ -492,4 +493,13 @@ public void registerNullMetric() {
.isThrownBy(() -> registry.register("any_name", null))
.withMessage("metric == null");
}

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

assertThat(called).isTrue();
}
}

0 comments on commit 4f6fc57

Please sign in to comment.