Skip to content

Commit

Permalink
ctdb-test: Adding test case to verify queue resizeing
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Martin Schwenke <[email protected]>
Reviewed-by: Christof Schmitt <[email protected]>

Autobuild-User(master): Christof Schmitt <[email protected]>
Autobuild-Date(master): Wed Apr 10 00:17:37 UTC 2019 on sn-devel-144
  • Loading branch information
sswen authored and chs committed Apr 10, 2019
1 parent 1f19317 commit 9ee32f3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions ctdb/tests/cunit/ctdb_io_test_001.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 74 additions & 0 deletions ctdb/tests/src/ctdb_io_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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]);
}
Expand Down

0 comments on commit 9ee32f3

Please sign in to comment.