From 04b30abb398bb269d29701da833315f9f04e0818 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 8 Dec 2011 16:44:51 +0000 Subject: [PATCH] tests: Add a test case for bgo#665728 Ported from a C test case by Guillaume Desmottes . See: bgo#665728 --- tests/folks/Makefile.am | 6 +++ tests/folks/init.vala | 99 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 tests/folks/init.vala diff --git a/tests/folks/Makefile.am b/tests/folks/Makefile.am index b8b97f7..5a4852f 100644 --- a/tests/folks/Makefile.am +++ b/tests/folks/Makefile.am @@ -50,6 +50,7 @@ noinst_PROGRAMS = \ aggregation \ avatar-cache \ object-cache \ + init \ $(NULL) SESSION_CONF = $(top_builddir)/tests/lib/telepathy/contactlist/session.conf @@ -91,6 +92,10 @@ object_cache_SOURCES = \ object-cache.vala \ $(NULL) +init_SOURCES = \ + init.vala \ + $(NULL) + CLEANFILES = \ *.pid \ *.address \ @@ -105,6 +110,7 @@ MAINTAINERCLEANFILES = \ utils_vala.stamp \ avatar_cache_vala.stamp \ object_cache_vala.stamp \ + init_vala.stamp \ $(NULL) EXTRA_DIST = \ diff --git a/tests/folks/init.vala b/tests/folks/init.vala new file mode 100644 index 0000000..be0090c --- /dev/null +++ b/tests/folks/init.vala @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + * + * Authors: Guillaume Desmottes + */ + +using Gee; +using Folks; + +public class InitTests : Folks.TestCase +{ + private KfTest.Backend _kf_backend; + private TpTest.Backend _tp_backend; + private int _test_timeout = 5; + + public InitTests () + { + base ("Init"); + + this._kf_backend = new KfTest.Backend (); + this._tp_backend = new TpTest.Backend (); + + /* Set up the tests */ + this.add_test ("looped", this.test_looped); + } + + public override void set_up () + { + this._tp_backend.set_up (); + } + + public override void tear_down () + { + this._tp_backend.tear_down (); + } + + /* Prepare a load of aggregators in a tight loop, without waiting for any of + * the prepare() calls to finish. Since the aggregators share a common + * BackendStore, this tests the mutual exclusion of prepare() methods in the + * backends. See: bgo#665728. */ + public void test_looped () + { + var main_loop = new GLib.MainLoop (null, false); + + this._kf_backend.set_up (""); + + void* account1_handle = this._tp_backend.add_account ("protocol", + "me@example.com", "cm", "account"); + void* account2_handle = this._tp_backend.add_account ("protocol", + "me2@example.com", "cm", "account2"); + + /* Wreak havoc. */ + for (uint i = 0; i < 10; i++) + { + var aggregator = new IndividualAggregator (); + aggregator.prepare (); /* Note: We don't yield for this to complete */ + aggregator = null; + } + + /* Kill the main loop after a few seconds. */ + Timeout.add_seconds (this._test_timeout, () => + { + main_loop.quit (); + return false; + }); + + main_loop.run (); + + /* Clean up for the next test */ + this._tp_backend.remove_account (account2_handle); + this._tp_backend.remove_account (account1_handle); + this._kf_backend.tear_down (); + } +} + +public int main (string[] args) +{ + Test.init (ref args); + + TestSuite root = TestSuite.get_root (); + root.add_suite (new InitTests ().get_suite ()); + + Test.run (); + + return 0; +} -- 2.7.4