SeleniumHQ/selenium — pull request #130 by nataliakoval (2013-10-30 14:23:10+00:00)
Title: Fixed incorrect behavior DefaultToFIFOPriorityTest (Issue 6504)

DefaultToFIFOPriorityTest fills the queue with MAX requests at loop:

for (MockedRequestHandler h : requests) {
final MockedRequestHandler req = h;
new Thread(new Runnable() { // Thread safety reviewed
public void run() {
req.process();
}
}).start();
}

and expects that the order in the queue (NewSessionRequestQueue newSessionQueue in Registry class) will match to order of the list (List requests). But this isn't always true, because the order running threads is not defined.

The test expects that first element in the queue will be same that in the list:
while (cpt < 8) {
try {
requests.get(0).getSession();
break;
} catch (Throwable e) {
// ignore.
}
Thread.sleep(250);
}

if this not true, we get an infinite loop.

I propose to switch next request when previous already added to queue.