static void
_round_lock(sqlx_cache_t *cache)
{
	hashstr_t *hn0 = NULL, *hn1 = NULL;
	HASHSTR_ALLOCA(hn0, name0);
	HASHSTR_ALLOCA(hn1, name1);

	gint id0;
	GError *err = sqlx_cache_open_and_lock_base(cache, hn0, &id0);
	g_assert_no_error (err);

	for (int i=0; i<5 ;i++) {
		gint id = g_random_int();
		err = sqlx_cache_open_and_lock_base(cache, hn0, &id);
		g_assert_no_error (err);
		g_assert_cmpint(id0, ==, id);
	}
	for (int i=0; i<6 ;i++) {
		err = sqlx_cache_unlock_and_close_base(cache, id0, FALSE);
		g_assert_no_error (err);
	}
	err = sqlx_cache_unlock_and_close_base(cache, id0, FALSE);
	g_assert_error (err, GQ(), CODE_INTERNAL_ERROR);
	g_clear_error (&err);

	for (int i=0; i<5 ;i++) {
		gint id = g_random_int ();
		err = sqlx_cache_open_and_lock_base(cache, hn1, &id);
		g_assert_no_error (err);
		err = sqlx_cache_unlock_and_close_base(cache, id, FALSE);
		g_assert_no_error (err);
	}
}
Esempio n. 2
0
static void
test_regular(sqlx_cache_t *cache)
{
	gint bd = -1;
	GError *err;
	hashstr_t *hname = NULL;

	HASHSTR_ALLOCA(hname, name0);

	err = sqlx_cache_open_and_lock_base(cache, hname, &bd);
	if (err != NULL)
		FAIL(err);
	g_debug("open(%s) = %d OK", name0, bd);

	test_lock_unlock(cache, bd);

	err = sqlx_cache_unlock_and_close_base(cache, bd, FALSE);
	if (err != NULL)
		FAIL(err);
	g_debug("close(%d) OK", bd);
}