Skip to content

Commit e3b502f

Browse files
[GTK] Some unit tests fail when using the network process
https://bugs.webkit.org/show_bug.cgi?id=151490 Reviewed by Martin Robinson. Run the soup server in a separate thread in TestResources test to avoid deadlocks. This fixes /webkit2/WebKitWebView/sync-request-on-max-conns and /webkit2/WebKitWebResource/get-data when using the network process. * TestWebKitAPI/Tests/WebKit2Gtk/TestResources.cpp: (beforeAll): Create the WebKitTestServer with ServerRunInThread flag. * TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.cpp: (WebKitTestServer::WebKitTestServer): When ServerRunInThread is present, create a WorkQueue to run the server. (WebKitTestServer::run): Run the server in the work queue if it has been created. * TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.h: Convert server type into server options as flags. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@192729 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent afe094d commit e3b502f

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

Tools/ChangeLog

+23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
2015-11-22 Carlos Garcia Campos <[email protected]>
2+
3+
[GTK] Some unit tests fail when using the network process
4+
https://bugs.webkit.org/show_bug.cgi?id=151490
5+
6+
Reviewed by Martin Robinson.
7+
8+
Run the soup server in a separate thread in TestResources test to
9+
avoid deadlocks.
10+
11+
This fixes /webkit2/WebKitWebView/sync-request-on-max-conns and
12+
/webkit2/WebKitWebResource/get-data when using the network process.
13+
14+
* TestWebKitAPI/Tests/WebKit2Gtk/TestResources.cpp:
15+
(beforeAll): Create the WebKitTestServer with ServerRunInThread flag.
16+
* TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.cpp:
17+
(WebKitTestServer::WebKitTestServer): When ServerRunInThread is
18+
present, create a WorkQueue to run the server.
19+
(WebKitTestServer::run): Run the server in the work queue if it
20+
has been created.
21+
* TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.h: Convert server
22+
type into server options as flags.
23+
124
2015-11-22 Carlos Garcia Campos <[email protected]>
225

326
[GTK] ImageDiff should normalize the diff image

Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestResources.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
835835

836836
void beforeAll()
837837
{
838-
kServer = new WebKitTestServer();
838+
kServer = new WebKitTestServer(WebKitTestServer::ServerOptions::ServerRunInThread);
839839
kServer->run(serverCallback);
840840

841841
ResourcesTest::add("WebKitWebView", "resources", testWebViewResources);

Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.cpp

+19-5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@
2121
#include "WebKitTestServer.h"
2222

2323
#include "TestMain.h"
24+
#include <wtf/Threading.h>
2425
#include <wtf/glib/GUniquePtr.h>
2526

26-
WebKitTestServer::WebKitTestServer(ServerType type)
27+
WebKitTestServer::WebKitTestServer(ServerOptions options)
2728
{
29+
if (options & ServerRunInThread) {
30+
WTF::initializeThreading();
31+
m_queue = WorkQueue::create("WebKitTestServer");
32+
}
33+
2834
GUniquePtr<char> sslCertificateFile;
2935
GUniquePtr<char> sslKeyFile;
30-
if (type == ServerHTTPS) {
36+
if (options & ServerHTTPS) {
3137
CString resourcesDir = Test::getResourcesDir();
3238
sslCertificateFile.reset(g_build_filename(resourcesDir.data(), "test-cert.pem", NULL));
3339
sslKeyFile.reset(g_build_filename(resourcesDir.data(), "test-key.pem", NULL));
@@ -37,9 +43,10 @@ WebKitTestServer::WebKitTestServer(ServerType type)
3743
soup_address_resolve_sync(address.get(), 0);
3844

3945
m_soupServer = adoptGRef(soup_server_new(SOUP_SERVER_INTERFACE, address.get(),
46+
SOUP_SERVER_ASYNC_CONTEXT, m_queue ? m_queue->runLoop().mainContext() : nullptr,
4047
SOUP_SERVER_SSL_CERT_FILE, sslCertificateFile.get(),
4148
SOUP_SERVER_SSL_KEY_FILE, sslKeyFile.get(), nullptr));
42-
m_baseURI = type == ServerHTTPS ? soup_uri_new("https://127.0.0.1/") : soup_uri_new("http://127.0.0.1/");
49+
m_baseURI = options & ServerHTTPS ? soup_uri_new("https://127.0.0.1/") : soup_uri_new("http://127.0.0.1/");
4350
soup_uri_set_port(m_baseURI, soup_server_get_port(m_soupServer.get()));
4451
}
4552

@@ -50,8 +57,15 @@ WebKitTestServer::~WebKitTestServer()
5057

5158
void WebKitTestServer::run(SoupServerCallback serverCallback)
5259
{
53-
soup_server_run_async(m_soupServer.get());
54-
soup_server_add_handler(m_soupServer.get(), 0, serverCallback, 0, 0);
60+
if (m_queue) {
61+
m_queue->dispatch([this, serverCallback] {
62+
soup_server_run_async(m_soupServer.get());
63+
soup_server_add_handler(m_soupServer.get(), nullptr, serverCallback, nullptr, nullptr);
64+
});
65+
} else {
66+
soup_server_run_async(m_soupServer.get());
67+
soup_server_add_handler(m_soupServer.get(), nullptr, serverCallback, nullptr, nullptr);
68+
}
5569
}
5670

5771
CString WebKitTestServer::getURIForPath(const char* path)

Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,20 @@
2222

2323
#include <libsoup/soup.h>
2424
#include <webkit2/webkit2.h>
25+
#include <wtf/WorkQueue.h>
2526
#include <wtf/glib/GRefPtr.h>
2627
#include <wtf/text/CString.h>
2728

2829
class WebKitTestServer {
2930
public:
3031

31-
enum ServerType {
32-
ServerHTTP,
33-
ServerHTTPS
32+
enum ServerOptions {
33+
ServerHTTP = 0,
34+
ServerHTTPS = 1 << 1,
35+
ServerRunInThread = 1 << 2,
3436
};
3537

36-
WebKitTestServer(ServerType = ServerHTTP);
38+
WebKitTestServer(ServerOptions = ServerHTTP);
3739
virtual ~WebKitTestServer();
3840

3941
SoupURI* baseURI() { return m_baseURI; }
@@ -44,6 +46,7 @@ class WebKitTestServer {
4446
private:
4547
GRefPtr<SoupServer> m_soupServer;
4648
SoupURI* m_baseURI;
49+
RefPtr<WorkQueue> m_queue;
4750
};
4851

4952
#endif // WebKitTestServer_h

0 commit comments

Comments
 (0)