]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
pytests: nitpicks
authorTomas Krizek <tomas.krizek@nic.cz>
Fri, 30 Nov 2018 11:15:54 +0000 (12:15 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 4 Dec 2018 16:13:42 +0000 (17:13 +0100)
tests/pytests/README.rst
tests/pytests/conftest.py
tests/pytests/kresd.py
tests/pytests/rehandshake/array.h [changed from file to symlink]
tests/pytests/test_conn_mgmt.py

index 3f62adf85f383bd7f27395d01d5f19375b6e7f4c..cf682375abc225ba98f5ba37bf7a076a05457122 100644 (file)
@@ -40,6 +40,8 @@ the path to test file directly.
 
    $ pytest-3 conn_flood.py
 
+Note: some tests may fail without an internet connection.
+
 Developer notes
 ---------------
 
index 0a0431bff13b21886fadc86863734b150f5709a3..c1e309707a4f5b2a0fc426b0ecf699ea6758a44a 100644 (file)
@@ -30,6 +30,7 @@ def kresd_tt_expired(tmpdir):
     'ip6_tls_socket',
 ])
 def make_kresd_sock(request, kresd):
+    """Factory function to create sockets of the same kind."""
     sock_func = getattr(kresd, request.param)
 
     def _make_kresd_sock():
index 7f439434832c107893a18f80aa85432ff085b3f9..a184cb0f51e92714388106aefb7e374e4d286344 100644 (file)
@@ -144,6 +144,7 @@ class Kresd(ContextDecorator):
         raise RuntimeError("Unsupported socket family: {}".format(family))
 
     def stream_socket(self, family, tls=False, timeout=20):
+        """Initialize a socket and return it along with the destination without connecting."""
         sock = socket.socket(family, socket.SOCK_STREAM)
         sock.settimeout(timeout)
         sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
deleted file mode 100644 (file)
index ece4dd147667162ecd412db00e7b37c4f1a2b855..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*  Copyright (C) 2015-2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
-
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program 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 General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-/**
- *
- * @file array.h
- * @brief A set of simple macros to make working with dynamic arrays easier.
- *
- * @note The C has no generics, so it is implemented mostly using macros.
- * Be aware of that, as direct usage of the macros in the evaluating macros
- * may lead to different expectations:
- *
- * @code{.c}
- *     MIN(array_push(arr, val), other)
- * @endcode
- *
- * May evaluate the code twice, leading to unexpected behaviour.
- * This is a price to pay for the absence of proper generics.
- *
- * # Example usage:
- *
- * @code{.c}
- *      array_t(const char*) arr;
- *      array_init(arr);
- *
- *      // Reserve memory in advance
- *      if (array_reserve(arr, 2) < 0) {
- *          return ENOMEM;
- *      }
- *
- *      // Already reserved, cannot fail
- *      array_push(arr, "princess");
- *      array_push(arr, "leia");
- *
- *      // Not reserved, may fail
- *      if (array_push(arr, "han") < 0) {
- *          return ENOMEM;
- *      }
- *
- *      // It does not hide what it really is
- *      for (size_t i = 0; i < arr.len; ++i) {
- *          printf("%s\n", arr.at[i]);
- *      }
- *
- *      // Random delete
- *      array_del(arr, 0);
- * @endcode
- * \addtogroup generics
- * @{
- */
-
-#pragma once
-#include <stdlib.h>
-
-/** Simplified Qt containers growth strategy. */
-static inline size_t array_next_count(size_t want)
-{
-       if (want < 2048) {
-               return (want < 20) ? want + 4 : want * 2;
-       } else {
-               return want + 2048;
-       }
-}
-
-/** @internal Incremental memory reservation */
-static inline int array_std_reserve(void *baton, char **mem, size_t elm_size, size_t want, size_t *have)
-{
-       if (*have >= want) {
-               return 0;
-       }
-       /* Simplified Qt containers growth strategy */
-       size_t next_size = array_next_count(want);
-       void *mem_new = realloc(*mem, next_size * elm_size);
-       if (mem_new != NULL) {
-               *mem = mem_new;
-               *have = next_size;
-               return 0;
-       }
-       return -1;
-}
-
-/** @internal Wrapper for stdlib free. */
-static inline void array_std_free(void *baton, void *p)
-{
-       free(p);
-}
-
-/** Declare an array structure. */
-#define array_t(type) struct {type * at; size_t len; size_t cap; }
-
-/** Zero-initialize the array. */
-#define array_init(array) ((array).at = NULL, (array).len = (array).cap = 0)
-
-/** Free and zero-initialize the array (plain malloc/free). */
-#define array_clear(array) \
-       array_clear_mm(array, array_std_free, NULL)
-
-/** Make the array empty and free pointed-to memory.
- * Mempool usage: pass mm_free and a knot_mm_t* . */
-#define array_clear_mm(array, free, baton) \
-       (free)((baton), (array).at), array_init(array)
-
-/** Reserve capacity for at least n elements.
- * @return 0 if success, <0 on failure */
-#define array_reserve(array, n) \
-       array_reserve_mm(array, n, array_std_reserve, NULL)
-
-/** Reserve capacity for at least n elements.
- * Mempool usage: pass kr_memreserve and a knot_mm_t* .
- * @return 0 if success, <0 on failure */
-#define array_reserve_mm(array, n, reserve, baton) \
-       (reserve)((baton), (char **) &(array).at, sizeof((array).at[0]), (n), &(array).cap)
-
-/**
- * Push value at the end of the array, resize it if necessary.
- * Mempool usage: pass kr_memreserve and a knot_mm_t* .
- * @note May fail if the capacity is not reserved.
- * @return element index on success, <0 on failure
- */
-#define array_push_mm(array, val, reserve, baton) \
-       (int)((array).len < (array).cap ? ((array).at[(array).len] = val, (array).len++) \
-               : (array_reserve_mm(array, ((array).cap + 1), reserve, baton) < 0 ? -1 \
-                       : ((array).at[(array).len] = val, (array).len++)))
-
-/**
- * Push value at the end of the array, resize it if necessary (plain malloc/free).
- * @note May fail if the capacity is not reserved.
- * @return element index on success, <0 on failure
- */
-#define array_push(array, val) \
-       array_push_mm(array, val, array_std_reserve, NULL)
-
-/**
- * Pop value from the end of the array.
- */
-#define array_pop(array) \
-       (array).len -= 1
-
-/**
- * Remove value at given index.
- * @return 0 on success, <0 on failure
- */
-#define array_del(array, i) \
-       (int)((i) < (array).len ? ((array).len -= 1,(array).at[i] = (array).at[(array).len], 0) : -1)
-
-/**
- * Return last element of the array.
- * @warning Undefined if the array is empty.
- */
-#define array_tail(array) \
-    (array).at[(array).len - 1]
-
-/** @} */
new file mode 120000 (symlink)
index 0000000000000000000000000000000000000000..33f18f447d902a093546c92f1825606aa67a8247
--- /dev/null
@@ -0,0 +1 @@
+../../../lib/generic/array.h
\ No newline at end of file
index b5ff92b6c2fa5373ffb725504b76791e3b02d53a..9982aedf3f6bd2dce12228e838685b5286dfff74 100644 (file)
@@ -49,7 +49,11 @@ def test_ignore_garbage(kresd_sock, garbage_lengths, single_buffer, query_before
 
 
 def test_pipelining(kresd_sock):
-    """First query takes longer to resolve - answer to second query should arrive sooner."""
+    """
+    First query takes longer to resolve - answer to second query should arrive sooner.
+
+    This test requires internet connection.
+    """
     buff1, msgid1 = utils.get_msgbuff('1000.delay.getdnsapi.net.', msgid=1)
     buff2, msgid2 = utils.get_msgbuff('1.delay.getdnsapi.net.', msgid=2)
     buff = buff1 + buff2
@@ -184,11 +188,6 @@ def test_query_flood_no_recv(make_kresd_sock):
 ])
 def test_query_flood_garbage(make_kresd_sock, glength, gcount, delay, query_before):
     """Flood resolver with prefixed garbage."""
-    # TODO - despite the fact that kresd closes TCP connection, it seems to be
-    # error in TCP stream parsing. Kresd closes TCP connection because of
-    # message length in TCP prefix is lesser then length of the fixed message
-    # header, it shouldn't happen.
-
     sock1 = make_kresd_sock()
     if query_before:
         utils.ping_alive(sock1)