[rhythmbox/rhythmdb-barrier] tests: check that the pre-commit barrier actually works
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox/rhythmdb-barrier] tests: check that the pre-commit barrier actually works
- Date: Sat, 27 Mar 2021 09:36:19 +0000 (UTC)
commit 1ba61ccfb82ad20e455704eb1ef052ab74c75dfd
Author: Jonathan Matthew <jonathan d14n org>
Date: Sat Mar 27 19:35:37 2021 +1000
tests: check that the pre-commit barrier actually works
tests/test-rhythmdb.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
---
diff --git a/tests/test-rhythmdb.c b/tests/test-rhythmdb.c
index 1de5b052a..17b4aa3a2 100644
--- a/tests/test-rhythmdb.c
+++ b/tests/test-rhythmdb.c
@@ -402,6 +402,81 @@ START_TEST (test_rhythmdb_deserialisation3)
}
END_TEST
+typedef struct {
+ RhythmDBEntry *entry;
+ int committed;
+} BarrierTestData;
+
+static gpointer
+test_worker (gpointer xdata)
+{
+ BarrierTestData *data = xdata;
+ GValue val = {0, };
+ const char *str;
+
+ rb_debug ("worker thread");
+
+ g_value_init (&val, G_TYPE_STRING);
+ g_value_set_static_string (&val, "Bbb");
+ rhythmdb_entry_set (db, data->entry, RHYTHMDB_PROP_TITLE, &val);
+ g_value_unset (&val);
+
+ rb_debug ("checking");
+ str = rhythmdb_entry_get_string (data->entry, RHYTHMDB_PROP_TITLE);
+ ck_assert_msg (str && (strcmp (str, "Aaa") == 0), "changes should not be visible on worker thread
yet");
+
+ rb_debug ("committing");
+ rhythmdb_commit (db);
+
+ rb_debug ("checking again");
+ str = rhythmdb_entry_get_string (data->entry, RHYTHMDB_PROP_TITLE);
+ ck_assert_msg (str && (strcmp (str, "Bbb") == 0), "changes should be visible on worker thread now");
+
+ rb_debug ("done");
+ data->committed = 1;
+ return NULL;
+}
+
+START_TEST (test_rhythmdb_thread_barrier)
+{
+ BarrierTestData data;
+ GThread *thr;
+ const char *str;
+ GValue val = {0, };
+
+ data.committed = 0;
+ data.entry = rhythmdb_entry_new (db, RHYTHMDB_ENTRY_TYPE_IGNORE, "file:///bar.ogg");
+ ck_assert_msg (data.entry != NULL, "failed to create entry");
+
+ g_value_init (&val, G_TYPE_STRING);
+ g_value_set_static_string (&val, "Aaa");
+ rhythmdb_entry_set (db, data.entry, RHYTHMDB_PROP_TITLE, &val);
+ g_value_unset (&val);
+ rhythmdb_commit (db);
+
+ end_step ();
+
+ thr = g_thread_new ("test-worker", test_worker, &data);
+
+ rb_debug ("letting worker thread run");
+ g_usleep (G_USEC_PER_SEC / 10);
+
+ /* worker thread's commit shouldn't finish until we let the event queue run */
+ ck_assert_msg (data.committed == 0, "worker thread should not be able to commit");
+ str = rhythmdb_entry_get_string (data.entry, RHYTHMDB_PROP_TITLE);
+ ck_assert_msg (str && (strcmp (str, "Aaa") == 0), "worker thread changes should not be visible yet");
+
+ rb_debug ("processing events from worker thread");
+ end_step ();
+
+ rb_debug ("joining worker thread");
+ g_thread_join (thr);
+
+ rb_debug ("checking final state");
+ str = rhythmdb_entry_get_string (data.entry, RHYTHMDB_PROP_TITLE);
+ ck_assert_msg (str && (strcmp (str, "Bbb") == 0), "worker thread changes be visible now");
+}
+
START_TEST (test_rhythmdb_podcast_upgrade)
{
RhythmDBEntry *entry;
@@ -534,6 +609,9 @@ rhythmdb_suite (void)
tcase_add_test (tc_chain, test_rhythmdb_deserialisation3);
/*tcase_add_test (tc_chain, test_rhythmdb_serialisation);*/
+ /* tests for entry changes and commits from worker threads */
+ tcase_add_test (tc_chain, test_rhythmdb_thread_barrier);
+
/* tests for breakable bug fixes */
tcase_add_test (tc_chain, test_rhythmdb_podcast_upgrade);
tcase_add_test (tc_chain, test_rhythmdb_modify_after_delete);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]