Update Geary.Imap.ClientSession connect timeout handling

Allow specifying the connect greeting timeout length, ensure that
any connect errors are in place before releasing the connect waiter,
add unit test to ensure it works properly.
This commit is contained in:
Michael Gratton 2019-12-29 17:01:28 +10:30 committed by Michael James Gratton
parent 54156003b4
commit 13d43d41b2
5 changed files with 91 additions and 48 deletions

View file

@ -7,6 +7,7 @@
class Geary.Imap.ClientSessionTest : TestCase {
private const uint CONNECT_TIMEOUT = 2;
private TestServer? server = null;
@ -14,6 +15,9 @@ class Geary.Imap.ClientSessionTest : TestCase {
public ClientSessionTest() {
base("Geary.Imap.ClientSessionTest");
add_test("connect_disconnect", connect_disconnect);
if (GLib.Test.slow()) {
add_test("connect_timeout", connect_timeout);
}
add_test("login", login);
add_test("logout", logout);
add_test("login_logout", login_logout);
@ -37,7 +41,9 @@ class Geary.Imap.ClientSessionTest : TestCase {
var test_article = new ClientSession(new_endpoint());
assert_true(test_article.get_protocol_state(null) == NOT_CONNECTED);
test_article.connect_async.begin(null, this.async_complete_full);
test_article.connect_async.begin(
CONNECT_TIMEOUT, null, this.async_complete_full
);
test_article.connect_async.end(async_result());
assert_true(test_article.get_protocol_state(null) == UNAUTHORIZED);
@ -52,6 +58,27 @@ class Geary.Imap.ClientSessionTest : TestCase {
);
}
public void connect_timeout() throws GLib.Error {
this.server.add_script_line(WAIT_FOR_DISCONNECT, "");
var test_article = new ClientSession(new_endpoint());
GLib.Timer timer = new GLib.Timer();
timer.start();
test_article.connect_async.begin(
CONNECT_TIMEOUT, null, this.async_complete_full
);
try {
test_article.connect_async.end(async_result());
assert_not_reached();
} catch (GLib.IOError.TIMED_OUT err) {
assert_double(timer.elapsed(), CONNECT_TIMEOUT, 0.5);
}
TestServer.Result result = this.server.wait_for_script(this.main_loop);
assert_true(result.succeeded);
}
public void login() throws GLib.Error {
this.server.add_script_line(
SEND_LINE, "* OK localhost test server ready"
@ -63,7 +90,9 @@ class Geary.Imap.ClientSessionTest : TestCase {
var test_article = new ClientSession(new_endpoint());
assert_true(test_article.get_protocol_state(null) == NOT_CONNECTED);
test_article.connect_async.begin(null, this.async_complete_full);
test_article.connect_async.begin(
CONNECT_TIMEOUT, null, this.async_complete_full
);
test_article.connect_async.end(async_result());
assert_true(test_article.get_protocol_state(null) == UNAUTHORIZED);
@ -98,7 +127,9 @@ class Geary.Imap.ClientSessionTest : TestCase {
var test_article = new ClientSession(new_endpoint());
assert_true(test_article.get_protocol_state(null) == NOT_CONNECTED);
test_article.connect_async.begin(null, this.async_complete_full);
test_article.connect_async.begin(
CONNECT_TIMEOUT, null, this.async_complete_full
);
test_article.connect_async.end(async_result());
assert_true(test_article.get_protocol_state(null) == UNAUTHORIZED);
@ -127,7 +158,9 @@ class Geary.Imap.ClientSessionTest : TestCase {
var test_article = new ClientSession(new_endpoint());
assert_true(test_article.get_protocol_state(null) == NOT_CONNECTED);
test_article.connect_async.begin(null, this.async_complete_full);
test_article.connect_async.begin(
CONNECT_TIMEOUT, null, this.async_complete_full
);
test_article.connect_async.end(async_result());
assert_true(test_article.get_protocol_state(null) == UNAUTHORIZED);

View file

@ -41,7 +41,7 @@ class Integration.Imap.ClientSession : TestCase {
}
public void session_connect() throws GLib.Error {
this.session.connect_async.begin(null, async_complete_full);
this.session.connect_async.begin(2, null, async_complete_full);
this.session.connect_async.end(async_result());
this.session.disconnect_async.begin(null, async_complete_full);
@ -98,7 +98,7 @@ class Integration.Imap.ClientSession : TestCase {
}
private void do_connect() throws GLib.Error {
this.session.connect_async.begin(null, async_complete_full);
this.session.connect_async.begin(5, null, async_complete_full);
this.session.connect_async.end(async_result());
}