Skip to content

Commit

Permalink
Do not log once global percentage exceeded 100 percent
Browse files Browse the repository at this point in the history
  • Loading branch information
s1ck committed Sep 26, 2023
1 parent 088a385 commit c4f423b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private synchronized void doLogPercentage(Supplier<String> msgFactory, long prog
String message = msgFactory != NO_MESSAGE ? msgFactory.get() : null;
progressCounter.add(progress);
int nextPercentage = (int) ((progressCounter.sum() / (double) taskVolume) * 100);
if (globalPercentage < nextPercentage) {
if (globalPercentage < nextPercentage && globalPercentage < 100) {
globalPercentage = nextPercentage;
if (message == null || message.isEmpty()) {
logProgress(nextPercentage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ void shouldLog100OnlyOnce() {
.containsExactly("Test 100%");
}

@Test
void shouldNotExceed100Percent() {
TestLog log = Neo4jProxy.testLog();
var testProgressLogger = new BatchingProgressLogger(log, Tasks.leaf("Test"), 1);
testProgressLogger.reset(1);
testProgressLogger.logProgress(1); // reaches 100 %
testProgressLogger.logProgress(1); // exceeds 100 %
assertThat(log.getMessages(TestLog.INFO))
.extracting(Extractors.removingThreadId())
.containsExactly("Test 100%");
}

@Test
void closesThreadLocal() {
var logger = new BatchingProgressLogger(
Expand Down

0 comments on commit c4f423b

Please sign in to comment.