[wpilib] Throw early when EventLoop is modified while running (#6115)

This commit is contained in:
Thad House
2023-12-31 22:45:10 -08:00
committed by GitHub
parent c16946c0ec
commit f9aabc5ab2
5 changed files with 91 additions and 1 deletions

View File

@@ -5,7 +5,9 @@
package edu.wpi.first.wpilibj.event;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.ConcurrentModificationException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
@@ -58,4 +60,33 @@ class EventLoopTest {
// shouldn't change
assertEquals(1, counter.get());
}
@Test
void testConcurrentModification() {
var loop = new EventLoop();
loop.bind(
() -> {
assertThrows(
ConcurrentModificationException.class,
() -> {
loop.bind(() -> {});
});
});
loop.poll();
loop.clear();
loop.bind(
() -> {
assertThrows(
ConcurrentModificationException.class,
() -> {
loop.clear();
});
});
loop.poll();
}
}