On Fri, Oct 02, 2015 at 01:55:29PM +0200, Petr Cech wrote:
Hi,
there is WiP attached. I removed some tests like this one some time ago.
They fail really often and we decided that the test logic was corrupted. Now
I am trying get it back to the codebase.
There is some kind of cmocka magic around data provider. I think it creates
test_user_1 during creation of filter.
In case of this type of tests, we need two users, one stored before filter
request and one stored after filter request. There is a special type of
filter which has time parameter which it search from. So the filter returns
only one user.
If this concept is right, I will send whole patch.
Regards
Petr
PS: I applied my patch after 000*-cache_req_*. Those patches are on list.
From aa0b0ab7c0a95ff47d5003907730c5432ff7bb85 Mon Sep 17 00:00:00
2001
From: Petr Cech <pcech(a)redhat.com>
Date: Fri, 2 Oct 2015 07:34:08 -0400
Subject: [PATCH] TEST: recent_valid filter testing
Some tests were removed in past. This is only WiP, not regular patch.
I rewrote one of the removed test. Is it this right way?
We speak about RECENT filter. It returns only records which
have been wrote or updated after filter was created (or another given
time). Some notes are written in comments of this patch.
Thank you, I think your approach is correct. Your test essentially tests
that testuser2 was on the server but was removed, so only testuser1 is
returned.
It's correct, but because the interface is able to return more users, I
would prefer if we tested that as well.
I have one more minor remark inline, but in general, please go
ahead and add back the other tests..
Resolves:
https://fedorahosted.org/sssd/ticket/2730
---
src/tests/cmocka/test_responder_cache_req.c | 60 ++++++++++++++++++++++++++++-
1 file changed, 58 insertions(+), 2 deletions(-)
diff --git a/src/tests/cmocka/test_responder_cache_req.c
b/src/tests/cmocka/test_responder_cache_req.c
index bb79fd10eefd7186f17a1f9306b57ddca2e3279f..c01d92fd9f3f078d853da1642e63cdbc3a1aed7b
100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -1239,6 +1239,58 @@ static void cache_req_user_by_filter_test_done(struct tevent_req
*req)
ctx->tctx->done = true;
}
+/* NOTE better name is filter_recent_valid */
+void test_users_by_filter_valid(void **state)
+{
+ struct cache_req_test_ctx *test_ctx = NULL;
+ TALLOC_CTX *req_mem_ctx = NULL;
+ struct tevent_req *req = NULL;
+ const char *ldbname = NULL;
+ errno_t ret;
+
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
+ test_ctx->create_user = true;
+
+ /* NOTE This user (#2) is stored before filter creation. */
+ ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME2, "pwd",
1001, 1001,
+ NULL, NULL, NULL,
"cn="TEST_USER_NAME2",dc=test", NULL,
+ NULL, 1000, time(NULL));
+ assert_int_equal(ret, EOK);
+
+ /* NOTE To make sure that the times of user/filter creation will vary.*/
+ sleep(1);
+
+ req_mem_ctx = talloc_new(global_talloc_context);
Please either allocate the context on test_ctx or just use test_ctx..
+ check_leaks_push(req_mem_ctx);
+
+ /* Filters always go to DP */
+ will_return(__wrap_sss_dp_get_account_send, test_ctx);
+ mock_account_recv_simple();
+
+ /* NOTE During this call the TEST_USER_NAME (#1) will be stored. */
+ req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
+ test_ctx->rctx,
+ test_ctx->tctx->dom->name,
+ "test*");
+ assert_non_null(req);
+
+ tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
+
+ ret = test_ev_loop(test_ctx->tctx);
+ assert_int_equal(ret, ERR_OK);
+ assert_true(check_leaks_pop(req_mem_ctx));
+
+ /* NOTE We receive only user #1, because #2 was stored before filter was created.
*/
+ assert_non_null(test_ctx->result);
+ assert_int_equal(test_ctx->result->count, 1);
+
+ ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
+ SYSDB_NAME, NULL);
+ assert_non_null(ldbname);
+ assert_string_equal(ldbname, TEST_USER_NAME);
+}
+
+