URL: https://github.com/SSSD/sssd/pull/29
Author: jhrozek
 Title: #29: tests: Add a regression test for upstream ticket #3131
Action: opened

PR body:
"""
Tests that running two duplicate SRV resolution queries succeeds
and returns a valid host name.
"""

To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/29/head:pr29
git checkout pr29
From fbf5e6d8dad85c07d7677d19a9f058675059bf5c Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhro...@redhat.com>
Date: Wed, 21 Sep 2016 10:44:36 +0200
Subject: [PATCH] tests: Add a regression test for upstream ticket #3131

Tests that running two duplicate SRV resolution queries succeeds
and returns a valid host name.
---
 src/tests/cmocka/test_fo_srv.c | 68 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/src/tests/cmocka/test_fo_srv.c b/src/tests/cmocka/test_fo_srv.c
index a84ce43..53f6380 100644
--- a/src/tests/cmocka/test_fo_srv.c
+++ b/src/tests/cmocka/test_fo_srv.c
@@ -203,6 +203,8 @@ struct test_fo_ctx {
     int ttl;
 
     struct fo_server *srv;
+
+    int num_done;
 };
 
 int test_fo_srv_data_cmp(void *ud1, void *ud2)
@@ -691,6 +693,67 @@ static void test_fo_hostlist(void **state)
     assert_int_equal(ret, ERR_OK);
 }
 
+static void test_fo_srv_dup_done(struct tevent_req *req);
+
+/* Test that running two parallel SRV queries doesn't return an error.
+ * This is a regression test for https://fedorahosted.org/sssd/ticket/3131
+ */
+void test_fo_srv_duplicates(void **state)
+{
+    errno_t ret;
+    struct tevent_req *req;
+    struct test_fo_ctx *test_ctx =
+        talloc_get_type(*state, struct test_fo_ctx);
+
+    test_fo_srv_mock_dns(test_ctx, test_ctx->ttl);
+    test_fo_srv_mock_dns(test_ctx, test_ctx->ttl);
+
+    ret = fo_add_srv_server(test_ctx->fo_svc, "_ldap", "sssd.com",
+                            "sssd.local", "tcp", test_ctx);
+    assert_int_equal(ret, ERR_OK);
+
+    ret = fo_add_server(test_ctx->fo_svc, "ldap1.sssd.com",
+                        389, (void *) discard_const("ldap://ldap1.sssd.com";),
+                        true);
+    assert_int_equal(ret, ERR_OK);
+
+    req = fo_resolve_service_send(test_ctx, test_ctx->ctx->ev,
+                                  test_ctx->resolv, test_ctx->fo_ctx,
+                                  test_ctx->fo_svc);
+    assert_non_null(req);
+    tevent_req_set_callback(req, test_fo_srv_dup_done, test_ctx);
+
+    req = fo_resolve_service_send(test_ctx, test_ctx->ctx->ev,
+                                  test_ctx->resolv, test_ctx->fo_ctx,
+                                  test_ctx->fo_svc);
+    assert_non_null(req);
+    tevent_req_set_callback(req, test_fo_srv_dup_done, test_ctx);
+
+    ret = test_ev_loop(test_ctx->ctx);
+    assert_int_equal(ret, ERR_OK);
+}
+
+static void test_fo_srv_dup_done(struct tevent_req *req)
+{
+    struct test_fo_ctx *test_ctx = \
+        tevent_req_callback_data(req, struct test_fo_ctx);
+    errno_t ret;
+    const char *name;
+
+    ret = fo_resolve_service_recv(req, test_ctx, &test_ctx->srv);
+    talloc_zfree(req);
+    assert_int_equal(ret, EOK);
+
+    name = fo_get_server_name(test_ctx->srv);
+    assert_string_equal(name, "ldap1.sssd.com");
+
+    test_ctx->num_done++;
+    if (test_ctx->num_done == 2) {
+        test_ctx->ctx->error = ERR_OK;
+        test_ctx->ctx->done = true;
+    }
+}
+
 int main(int argc, const char *argv[])
 {
     int rv;
@@ -703,6 +766,7 @@ int main(int argc, const char *argv[])
     };
 
     const struct CMUnitTest tests[] = {
+#if 0
         cmocka_unit_test_setup_teardown(test_fo_hostlist,
                                         test_fo_setup,
                                         test_fo_teardown),
@@ -715,6 +779,10 @@ int main(int argc, const char *argv[])
         cmocka_unit_test_setup_teardown(test_fo_srv_ttl_zero,
                                         test_fo_srv_setup,
                                         test_fo_srv_teardown),
+#endif
+        cmocka_unit_test_setup_teardown(test_fo_srv_duplicates,
+                                        test_fo_srv_setup,
+                                        test_fo_srv_teardown),
     };
 
     /* Set debug level to invalid value so we can deside if -d 0 was used. */
_______________________________________________
sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org
To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org

Reply via email to