Skip to content

Commit

Permalink
[FLINK-37159][runtime] Fix the test timeout by yielding Modifier thread
Browse files Browse the repository at this point in the history
  • Loading branch information
showuon committed Jan 18, 2025
1 parent 8134e33 commit 6249c0a
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

/** Validate memory release under concurrent modification exceptions. */
class MemoryManagerConcurrentModReleaseTest {
private static long testTimeoutMs = 5000;

@Test
void testConcurrentModificationOnce() throws MemoryAllocationException {
Expand Down Expand Up @@ -61,7 +62,7 @@ void testConcurrentModificationWhileReleasing() throws Exception {
memMan.allocatePages(this, segs, numSegments);

// start a thread that performs concurrent modifications
Modifier mod = new Modifier(segs);
Modifier mod = new Modifier(segs, System.currentTimeMillis());
Thread modRunner = new Thread(mod);
modRunner.start();

Expand All @@ -80,11 +81,14 @@ void testConcurrentModificationWhileReleasing() throws Exception {
private static class Modifier implements Runnable {

private final ArrayList<MemorySegment> toModify;
private final long startTimeMs;

private volatile boolean running = true;
private volatile boolean timeout = false;

private Modifier(ArrayList<MemorySegment> toModify) {
private Modifier(ArrayList<MemorySegment> toModify, long startTimeMs) {
this.toModify = toModify;
this.startTimeMs = startTimeMs;
}

public void cancel() {
Expand All @@ -97,7 +101,13 @@ public void run() {
try {
MemorySegment seg = toModify.remove(0);
toModify.add(seg);
} catch (IndexOutOfBoundsException e) {
// if the test running time reaches TEST_TIMEOUT_MS, we should lower the
// priority of the Modifier thread to let segment release completes sooner.
if (timeout || System.currentTimeMillis() - startTimeMs > testTimeoutMs) {
timeout = true;
Thread.sleep(1);
}
} catch (IndexOutOfBoundsException | InterruptedException e) {
// may happen, just retry
}
}
Expand Down

0 comments on commit 6249c0a

Please sign in to comment.