Use ConcurrentLinkedDeque for EventHandler

ArrayList::add is not thread safe. I ran into cases where async tests
using utests would fail even when all of the individual tests passed.
This was because multiple threads called back into the handle method of
the handler instance variable, which just delegated to eventList::add.
When this happened, one of the events would get added to the list as a
null reference, which would manifest as an NPE upstream on the master
process. After this change, my tests stopped failing.
This commit is contained in:
Ethan Atkins 2018-03-20 18:06:03 -07:00
parent 8eb2d7389d
commit 9b24e9f9eb
1 changed files with 2 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import java.net.Socket;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.*;
@ -294,7 +295,7 @@ final public class ForkMain {
Task[] nestedTasks;
final TaskDef taskDef = task.taskDef();
try {
final List<ForkEvent> eventList = new ArrayList<ForkEvent>();
final Collection<ForkEvent> eventList = new ConcurrentLinkedDeque<ForkEvent>();
final EventHandler handler = new EventHandler() { public void handle(final Event e){ eventList.add(new ForkEvent(e)); } };
logDebug(os, " Running " + taskDef);
nestedTasks = task.execute(handler, loggers);