public function testErrorOnFree()
{
$expr = $this->getMock('\\Repo2\\QueryBuilder\\ExpressionInterface');
// the first query will be successful
$firstQuery = $this->getMock('\\Repo2\\QueryReactor\\Query');
$firstQuery->expects($this->at(0))->method('getExpression')->will($this->returnValue($expr));
$firstQuery->expects($this->at(1))->method('resolve');
$firstQuery->expects($this->never())->method('reject');
// the waiting query will be rejected
$waitingQuery = $this->getMock('\\Repo2\\QueryReactor\\Query');
$waitingQuery->expects($this->at(0))->method('getExpression')->will($this->returnValue($expr));
$waitingQuery->expects($this->never())->method('resolve');
$waitingQuery->expects($this->at(1))->method('reject');
// something link
$link = new \stdClass();
$controller = $this->getMock('\\Repo2\\QueryReactor\\Controller');
$controller->expects($this->at(0))->method('getLink')->will($this->returnValue($link));
$controller->expects($this->at(1))->method('getQuery')->will($this->returnValue($waitingQuery));
$result = $this->getMock('\\Repo2\\QueryReactor\\Result');
$driver = $this->getMock('\\Repo2\\QueryReactor\\Driver');
$driver->expects($this->exactly(2))->method('query')->will($this->onConsecutiveCalls(null, $this->throwException(new \Exception())));
$driver->expects($this->once())->method('poll')->will($this->returnValue([[$link], []]));
// [read, error]
$driver->expects($this->once())->method('read')->will($this->returnValue($result));
$reactor = new Reactor($driver, $controller);
$reactor->execQuery($firstQuery)->await();
}