Skip to content

Commit

Permalink
Fixed subsequent failures when a page fails quickly before the next c…
Browse files Browse the repository at this point in the history
…ommand begins
  • Loading branch information
jferris committed May 5, 2011
1 parent cc74875 commit 728feee
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
8 changes: 6 additions & 2 deletions spec/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@
before(:all) do
@app = lambda do |env|
if env['PATH_INFO'] == "/error"
body = "error"
[404, {}, []]
else
body = <<-HTML
Expand All @@ -568,10 +567,15 @@
it "raises a webkit error for the requested url" do
expect {
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})
end

def wait_for_error_to_complete
sleep(0.5)
end
end

context "slow error app" do
Expand Down
40 changes: 23 additions & 17 deletions src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ Connection::Connection(QTcpSocket *socket, WebPage *page, QObject *parent) :
m_page = page;
m_command = NULL;
m_expectingDataSize = -1;
m_pageSuccess = true;
m_commandWaiting = false;
connect(m_socket, SIGNAL(readyRead()), this, SLOT(checkNext()));
connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
}

void Connection::checkNext() {
Expand Down Expand Up @@ -75,25 +78,32 @@ void Connection::processArgument(const char *data) {

if (m_arguments.length() == m_argumentsExpected) {
if (m_page->isLoading())
connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
m_commandWaiting = true;
else
startCommand();
}
}

void Connection::startCommand() {
m_command = createCommand(m_commandName.toAscii().constData());
if (m_command) {
connect(m_command,
SIGNAL(finished(Response *)),
this,
SLOT(finishCommand(Response *)));
m_command->start(m_arguments);
m_commandWaiting = false;
if (m_pageSuccess) {
m_command = createCommand(m_commandName.toAscii().constData());
if (m_command) {
connect(m_command,
SIGNAL(finished(Response *)),
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 {
QString failure = QString("Unknown command: ") + m_commandName + "\n";
writeResponse(new Response(false, failure));
m_pageSuccess = true;
QString message = m_page->failureString();
writeResponse(new Response(false, message));
}
m_commandName = QString();
}

Command *Connection::createCommand(const char *name) {
Expand All @@ -102,13 +112,9 @@ Command *Connection::createCommand(const char *name) {
}

void Connection::pendingLoadFinished(bool success) {
m_page->disconnect(this, SLOT(pendingLoadFinished(bool)));
if (success) {
m_pageSuccess = success;
if (m_commandWaiting)
startCommand();
} else {
QString message = m_page->failureString();
writeResponse(new Response(false, message));
}
}

void Connection::finishCommand(Response *response) {
Expand Down
2 changes: 2 additions & 0 deletions src/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ class Connection : public QObject {
int m_argumentsExpected;
WebPage *m_page;
int m_expectingDataSize;
bool m_pageSuccess;
bool m_commandWaiting;
};

0 comments on commit 728feee

Please sign in to comment.