summaryrefslogtreecommitdiff
path: root/ctdb/tests
diff options
context:
space:
mode:
authorSwen Schillig <swen@linux.ibm.com>2019-03-18 15:25:54 +0100
committerChristof Schmitt <cs@samba.org>2019-04-10 00:17:37 +0000
commit9ee32f3a9654452e855bfa99801d977fa7168dec (patch)
tree0041795df13fad52ad3c853cd8716f0357d589eb /ctdb/tests
parent1f193174f21860b586eae1485e6d378441608e8d (diff)
downloadsamba-9ee32f3a9654452e855bfa99801d977fa7168dec.tar.gz
ctdb-test: Adding test case to verify queue resizeing
If a data packet arrives which exceeds the queue's current buffer size, the buffer needs to be increased to hold the full packet. Once the packet is processed the buffer size should be decreased to its standard size again. This test case verifies this process. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Christof Schmitt <cs@samba.org> Autobuild-User(master): Christof Schmitt <cs@samba.org> Autobuild-Date(master): Wed Apr 10 00:17:37 UTC 2019 on sn-devel-144
Diffstat (limited to 'ctdb/tests')
-rwxr-xr-xctdb/tests/cunit/ctdb_io_test_001.sh1
-rw-r--r--ctdb/tests/src/ctdb_io_test.c74
2 files changed, 75 insertions, 0 deletions
diff --git a/ctdb/tests/cunit/ctdb_io_test_001.sh b/ctdb/tests/cunit/ctdb_io_test_001.sh
index 6851d524bf5..b6d3bce4782 100755
--- a/ctdb/tests/cunit/ctdb_io_test_001.sh
+++ b/ctdb/tests/cunit/ctdb_io_test_001.sh
@@ -7,3 +7,4 @@ ok_null
unit_test ctdb_io_test 1
unit_test ctdb_io_test 2
unit_test ctdb_io_test 3
+unit_test ctdb_io_test 4
diff --git a/ctdb/tests/src/ctdb_io_test.c b/ctdb/tests/src/ctdb_io_test.c
index ec1d25859f0..9cd02aa0eaa 100644
--- a/ctdb/tests/src/ctdb_io_test.c
+++ b/ctdb/tests/src/ctdb_io_test.c
@@ -243,6 +243,76 @@ static void test3(void)
TALLOC_FREE(ctdb);
}
+static void test4(void)
+{
+ struct ctdb_context *ctdb;
+ struct ctdb_queue *queue;
+ uint32_t pkt_size;
+ char *request;
+ size_t req_len;
+ int fd;
+ int ret;
+
+ test_setup(test_cb, &fd, &ctdb, &queue);
+
+ req_len = queue->buffer_size << 1; /* double the buffer size */
+ request = talloc_zero_size(queue, req_len);
+
+ /* writing first part of packet exceeding standard buffer size */
+ pkt_size = sizeof(uint32_t) + req_len;
+
+ ret = write(fd, &pkt_size, sizeof(pkt_size));
+ assert(ret == sizeof(pkt_size));
+
+ ret = write(fd, request, req_len - (queue->buffer_size >> 1));
+ assert(ret == req_len - (queue->buffer_size >> 1));
+
+ /*
+ * process...
+ * this needs to be done to have things changed
+ */
+ tevent_loop_once(ctdb->ev);
+ /*
+ * needs to be called twice as an initial incomplete packet
+ * does not trigger a schedule_immediate
+ */
+ tevent_loop_once(ctdb->ev);
+
+ /* the buffer should be resized to packet size now */
+ assert(queue->buffer.size == pkt_size);
+
+ /* writing remaining data */
+ ret = write(fd, request, queue->buffer_size >> 1);
+ assert(ret == (queue->buffer_size >> 1));
+
+ /* process... */
+ tevent_loop_once(ctdb->ev);
+
+ /*
+ * the buffer was increased beyond its standard size.
+ * once packet got processed, the buffer has to be free'd
+ * and will be re-allocated with standard size on new request arrival.
+ */
+
+ assert(queue->buffer.size == 0);
+
+ /* writing new packet to verify standard buffer size */
+ pkt_size = sizeof(uint32_t) + (queue->buffer_size >> 1);
+
+ ret = write(fd, &pkt_size, sizeof(pkt_size));
+ assert(ret == sizeof(pkt_size));
+
+ ret = write(fd, request, (queue->buffer_size >> 1));
+ assert(ret == (queue->buffer_size >> 1));
+
+ /* process... */
+ tevent_loop_once(ctdb->ev);
+
+ /* back to standard buffer size */
+ assert(queue->buffer.size == queue->buffer_size);
+
+ TALLOC_FREE(ctdb);
+}
int main(int argc, const char **argv)
{
@@ -268,6 +338,10 @@ int main(int argc, const char **argv)
test3();
break;
+ case 4:
+ test4();
+ break;
+
default:
fprintf(stderr, "Unknown test number %s\n", argv[1]);
}