Fix reset crash when replies are destroyed

We attempted to track in-progress replies and abort them in 1.5.1.
However, sometimes these replies are destroyed unexpectedly, so
attempting to abort them raises errors.

This commit tracks when replies are destroyed and removes them from the
queue of in-progress replies.
This commit is contained in:
Joe Ferris 2015-06-05 13:29:26 -04:00
parent 179ca5b6da
commit 79088c2282
4 changed files with 65 additions and 4 deletions

View File

@ -7,8 +7,12 @@ require 'base64'
describe Capybara::Webkit::Driver do
include AppRunner
def visit(url, driver=self.driver)
driver.visit("#{AppRunner.app_host}#{url}")
def visit(path, driver=self.driver)
driver.visit(url(path))
end
def url(path)
"#{AppRunner.app_host}#{path}"
end
context "iframe app" do
@ -3041,6 +3045,53 @@ CACHE MANIFEST
end
end
context "with unfinished responses" do
it_behaves_like "output writer" do
let(:driver) do
count = 0
driver_for_app browser do
get "/" do
count += 1
<<-HTML
<html>
<body>
<script type="text/javascript">
setTimeout(function () {
xhr = new XMLHttpRequest();
xhr.open('GET', '/async?#{count}', true);
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.send();
}, 50);
</script>
</body>
</html>
HTML
end
get "/async" do
sleep 2
""
end
end
end
it "aborts unfinished responses" do
driver.enable_logging
visit "/"
sleep 0.5
visit "/"
sleep 0.5
driver.reset!
stderr.should abort_request_to("/async?2")
stderr.should_not abort_request_to("/async?1")
end
def abort_request_to(path)
include(%{Aborting request to "#{url(path)}"})
end
end
end
def driver_url(driver, path)
URI.parse(driver.current_url).merge(path).to_s
end

View File

@ -25,10 +25,10 @@ module AppRunner
AppRunner.app = app
end
def driver_for_app(&body)
def driver_for_app(*driver_args, &body)
app = Class.new(ExampleApp, &body)
run_application app
build_driver
build_driver(*driver_args)
end
def driver_for_html(html, *driver_args)

View File

@ -89,6 +89,11 @@ void WebPageManager::requestCreated(QByteArray &url, QNetworkReply *reply) {
else {
m_pendingReplies.append(reply);
connect(reply, SIGNAL(finished()), SLOT(handleReplyFinished()));
connect(
reply,
SIGNAL(destroyed(QObject *)),
SLOT(replyDestroyed(QObject *))
);
}
}
@ -104,6 +109,10 @@ void WebPageManager::replyFinished(QNetworkReply *reply) {
m_pendingReplies.removeAll(reply);
}
void WebPageManager::replyDestroyed(QObject *reply) {
m_pendingReplies.removeAll((QNetworkReply *) reply);
}
void WebPageManager::setPageStatus(bool success) {
logger() << "Page finished with" << success;
m_started.remove(qobject_cast<WebPage *>(sender()));

View File

@ -48,6 +48,7 @@ class WebPageManager : public QObject {
void setPageStatus(bool);
void requestCreated(QByteArray &url, QNetworkReply *reply);
void handleReplyFinished();
void replyDestroyed(QObject *);
signals:
void pageFinished(bool);