Fixed subsequent failures when a page fails quickly before the next command begins

This commit is contained in:
Joe Ferris 2011-05-05 18:27:04 -04:00
parent cc74875e4b
commit 728feeeff7
3 changed files with 31 additions and 19 deletions

View File

@ -550,7 +550,6 @@ describe Capybara::Driver::Webkit do
before(:all) do before(:all) do
@app = lambda do |env| @app = lambda do |env|
if env['PATH_INFO'] == "/error" if env['PATH_INFO'] == "/error"
body = "error"
[404, {}, []] [404, {}, []]
else else
body = <<-HTML body = <<-HTML
@ -568,10 +567,15 @@ describe Capybara::Driver::Webkit do
it "raises a webkit error for the requested url" do it "raises a webkit error for the requested url" do
expect { expect {
subject.find("//input").first.click subject.find("//input").first.click
subject.find("//p") wait_for_error_to_complete
subject.find("//body")
}. }.
to raise_error(Capybara::Driver::Webkit::WebkitError, %r{/error}) to raise_error(Capybara::Driver::Webkit::WebkitError, %r{/error})
end end
def wait_for_error_to_complete
sleep(0.5)
end
end end
context "slow error app" do context "slow error app" do

View File

@ -20,7 +20,10 @@ Connection::Connection(QTcpSocket *socket, WebPage *page, QObject *parent) :
m_page = page; m_page = page;
m_command = NULL; m_command = NULL;
m_expectingDataSize = -1; m_expectingDataSize = -1;
m_pageSuccess = true;
m_commandWaiting = false;
connect(m_socket, SIGNAL(readyRead()), this, SLOT(checkNext())); connect(m_socket, SIGNAL(readyRead()), this, SLOT(checkNext()));
connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
} }
void Connection::checkNext() { void Connection::checkNext() {
@ -75,25 +78,32 @@ void Connection::processArgument(const char *data) {
if (m_arguments.length() == m_argumentsExpected) { if (m_arguments.length() == m_argumentsExpected) {
if (m_page->isLoading()) if (m_page->isLoading())
connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(pendingLoadFinished(bool))); m_commandWaiting = true;
else else
startCommand(); startCommand();
} }
} }
void Connection::startCommand() { void Connection::startCommand() {
m_command = createCommand(m_commandName.toAscii().constData()); m_commandWaiting = false;
if (m_command) { if (m_pageSuccess) {
connect(m_command, m_command = createCommand(m_commandName.toAscii().constData());
SIGNAL(finished(Response *)), if (m_command) {
this, connect(m_command,
SLOT(finishCommand(Response *))); SIGNAL(finished(Response *)),
m_command->start(m_arguments); this,
SLOT(finishCommand(Response *)));
m_command->start(m_arguments);
} else {
QString failure = QString("Unknown command: ") + m_commandName + "\n";
writeResponse(new Response(false, failure));
}
m_commandName = QString();
} else { } else {
QString failure = QString("Unknown command: ") + m_commandName + "\n"; m_pageSuccess = true;
writeResponse(new Response(false, failure)); QString message = m_page->failureString();
writeResponse(new Response(false, message));
} }
m_commandName = QString();
} }
Command *Connection::createCommand(const char *name) { Command *Connection::createCommand(const char *name) {
@ -102,13 +112,9 @@ Command *Connection::createCommand(const char *name) {
} }
void Connection::pendingLoadFinished(bool success) { void Connection::pendingLoadFinished(bool success) {
m_page->disconnect(this, SLOT(pendingLoadFinished(bool))); m_pageSuccess = success;
if (success) { if (m_commandWaiting)
startCommand(); startCommand();
} else {
QString message = m_page->failureString();
writeResponse(new Response(false, message));
}
} }
void Connection::finishCommand(Response *response) { void Connection::finishCommand(Response *response) {

View File

@ -33,5 +33,7 @@ class Connection : public QObject {
int m_argumentsExpected; int m_argumentsExpected;
WebPage *m_page; WebPage *m_page;
int m_expectingDataSize; int m_expectingDataSize;
bool m_pageSuccess;
bool m_commandWaiting;
}; };