Skip to content

Commit 44ec89c

Browse files
CopilotvharsekoCopilot
authored
fix: correct inverted park condition in PooledTaskExecutorTest.LongTask (#971)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com> Co-authored-by: Valery Kharseko <vharseko@3a-systems.ru> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent aae2895 commit 44ec89c

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

openam-core/src/test/java/org/forgerock/openam/sm/datalayer/impl/PooledTaskExecutorTest.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
1414
* Copyright 2015-2016 ForgeRock AS.
15-
* Portions copyright 2025 3A Systems LLC.
15+
* Portions copyright 2023-2026 3A Systems LLC.
1616
*/
1717

1818
package org.forgerock.openam.sm.datalayer.impl;
@@ -22,10 +22,9 @@
2222
import static org.mockito.Mockito.*;
2323

2424
import java.text.MessageFormat;
25+
import java.util.concurrent.CountDownLatch;
2526
import java.util.concurrent.Semaphore;
2627
import java.util.concurrent.TimeUnit;
27-
import java.util.concurrent.atomic.AtomicBoolean;
28-
import java.util.concurrent.locks.LockSupport;
2928

3029
import jakarta.inject.Provider;
3130

@@ -148,18 +147,18 @@ public void run() {
148147

149148
private static class LongTask implements Task {
150149

151-
private AtomicBoolean locked = new AtomicBoolean(false);
152-
private Thread executingThread;
150+
private final CountDownLatch latch = new CountDownLatch(1);
153151

154152
@Override
155153
public void execute(TokenStorageAdapter adapter) throws DataLayerException {
156-
this.executingThread = Thread.currentThread();
157154
debug("Locking");
158-
locked.set(true);
159-
while (!locked.compareAndSet(false, true)) {
160-
debug("Task still locked - parking thread");
161-
LockSupport.park(this);
162-
debug("Thread unparked");
155+
try {
156+
if (!latch.await(30, TimeUnit.SECONDS)) {
157+
fail("LongTask was not unblocked within 30 seconds; test is likely hung.");
158+
}
159+
} catch (InterruptedException e) {
160+
Thread.currentThread().interrupt();
161+
throw new DataLayerException("Task was interrupted while waiting on latch", e);
163162
}
164163
debug("Thread unlocked - continuing");
165164
}
@@ -169,10 +168,7 @@ public void processError(DataLayerException error) {}
169168

170169
public void unblock() {
171170
debug("Setting task unlocked");
172-
locked.set(false);
173-
debug("Unparking thread {0}", executingThread);
174-
LockSupport.unpark(executingThread);
175-
debug("Unparked thread {0}", executingThread);
171+
latch.countDown();
176172
}
177173

178174
}

0 commit comments

Comments
 (0)