mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpilib] Throw early when EventLoop is modified while running (#6115)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user