summaryrefslogtreecommitdiff
path: root/testapp.c
diff options
context:
space:
mode:
authorTrond Norbye <Trond.Norbye@sun.com>2009-09-22 12:34:58 +0200
committerDustin Sallings <dustin@spy.net>2009-09-22 10:57:19 -0700
commit2c7bfeb83c0f247b9f6ee9678a681658eaf8535b (patch)
treea8c7b6011ca4fc619f4344c47e0c78a0f6af6d3b /testapp.c
parent7af0829ced0ff7220cd7e5fb274150087b2d6407 (diff)
downloadmemcached-2c7bfeb83c0f247b9f6ee9678a681658eaf8535b.tar.gz
Issue 92: stats cachedump should respond CLIENT_ERROR for illegal slab ids
Diffstat (limited to 'testapp.c')
-rw-r--r--testapp.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/testapp.c b/testapp.c
index fe6e050..33b1063 100644
--- a/testapp.c
+++ b/testapp.c
@@ -493,6 +493,71 @@ static enum test_return test_issue_72(void) {
return TEST_PASS;
}
+static void send_ascii_command(const char *buf) {
+ off_t offset = 0;
+ const char* ptr = buf;
+ size_t len = strlen(buf);
+
+ do {
+ ssize_t nw = write(sock, ptr + offset, len - offset);
+ if (nw == -1) {
+ if (errno != EINTR) {
+ fprintf(stderr, "Failed to write: %s\n", strerror(errno));
+ abort();
+ }
+ } else {
+ offset += nw;
+ }
+ } while (offset < len);
+}
+
+/*
+ * This is a dead slow single byte read, but it should only read out
+ * _one_ response and I don't have an input buffer... The current
+ * implementation only supports single-line responses, so if you want to use
+ * it for get commands you need to implement that first ;-)
+ */
+static void read_ascii_response(char *buffer, size_t size) {
+ off_t offset = 0;
+ bool need_more = true;
+ do {
+ ssize_t nr = read(sock, buffer + offset, 1);
+ if (nr == -1) {
+ if (errno != EINTR) {
+ fprintf(stderr, "Failed to read: %s\n", strerror(errno));
+ abort();
+ }
+ } else {
+ assert(nr == 1);
+ if (buffer[offset] == '\n') {
+ need_more = false;
+ buffer[offset + 1] = '\0';
+ }
+ offset += nr;
+ assert(offset + 1 < size);
+ }
+ } while (need_more);
+}
+
+static enum test_return test_issue_92(void) {
+ char buffer[1024];
+
+ close(sock);
+ sock = connect_server("127.0.0.1", port);
+
+ send_ascii_command("stats cachedump 1 0 0\r\n");
+ read_ascii_response(buffer, sizeof(buffer));
+ assert(strncmp(buffer, "END", strlen("END")) == 0);
+
+ send_ascii_command("stats cachedump 200 0 0\r\n");
+ read_ascii_response(buffer, sizeof(buffer));
+ assert(strncmp(buffer, "CLIENT_ERROR", strlen("CLIENT_ERROR")) == 0);
+
+ close(sock);
+ sock = connect_server("127.0.0.1", port);
+ return TEST_PASS;
+}
+
static enum test_return start_memcached_server(void) {
server_pid = start_server(&port, false, 600);
sock = connect_server("127.0.0.1", port);
@@ -1627,6 +1692,7 @@ struct testcase testcases[] = {
{ "vperror", test_vperror },
/* The following tests all run towards the same server */
{ "start_server", start_memcached_server },
+ { "issue_92", test_issue_92 },
{ "binary_noop", test_binary_noop },
{ "binary_quit", test_binary_quit },
{ "binary_quitq", test_binary_quitq },