From 3156b530afe14c8d14b82b9cb4fde9d7921c4e32 Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Mon, 11 Nov 2013 13:40:33 +0200 Subject: [PATCH 1/6] Allow test programs use custom port using environment variable or command-line argument --- tests/basic.py | 6 +++--- tests/bench.sh | 8 ++++++-- tests/limits.py | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/basic.py b/tests/basic.py index 87c8dc6..89d664e 100755 --- a/tests/basic.py +++ b/tests/basic.py @@ -6,9 +6,9 @@ try: except: msgpack = None - -host = '127.0.0.1' -port = 7379 +import os +host = os.getenv('WEBDIS_HOST', '127.0.0.1') +port = int(os.getenv('WEBDIS_PORT', 7379)) class TestWebdis(unittest.TestCase): diff --git a/tests/bench.sh b/tests/bench.sh index b7e8c01..0761696 100755 --- a/tests/bench.sh +++ b/tests/bench.sh @@ -1,8 +1,12 @@ #!/bin/bash CLIENTS=100 REQUESTS=100000 -HOST=127.0.0.1 -PORT=7379 + +HOST=$WEBDIS_HOST +PORT=$WEBDIS_PORT + +[ -n $HOST ] && HOST=127.0.0.1 +[ -n $PORT ] && PORT=7379 info() { echo "Testing on $HOST:$PORT with $CLIENTS clients in parallel, for a total of $REQUESTS requests per benchmark." diff --git a/tests/limits.py b/tests/limits.py index 0e7adff..1fdecc8 100755 --- a/tests/limits.py +++ b/tests/limits.py @@ -2,8 +2,9 @@ import socket import unittest -HOST = "127.0.0.1" -PORT = 7379 +import os +HOST = os.getenv('WEBDIS_HOST', '127.0.0.1') +PORT = int(os.getenv('WEBDIS_PORT', 7379)) class BlockingSocket: From b1cda7e376d6103b7fa7d96143a06fe357bc9cce Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Mon, 11 Nov 2013 15:14:56 +0200 Subject: [PATCH 2/6] Add makefile targets to run tests --- Makefile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Makefile b/Makefile index 3657532..ae56947 100644 --- a/Makefile +++ b/Makefile @@ -49,3 +49,17 @@ clean: install: $(OUT) $(INSTALL_DIRS) cp $(OUT) $(DESTDIR)/$(PREFIX)/bin cp webdis.prod.json $(CONFDIR) + + +WEBDIS_PORT ?= 7379 + +test_all: test perftest + +test: + python tests/basic.py + python tests/limits.py + ./tests/pubsub -p $(WEBDIS_PORT) + +perftest: + # This is a performance test that requires apache2-utils and curl + ./tests/bench.sh From 46e872a090f0bacc2bbe9b8a6f04dd70667b40c2 Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Mon, 11 Nov 2013 14:49:46 +0200 Subject: [PATCH 3/6] Allow setting CFLAGS and LDFLAGS from environment variables --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ae56947..910fd38 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,8 @@ JANSSON_OBJ=jansson/src/dump.o jansson/src/error.o jansson/src/hashtable.o janss FORMAT_OBJS=formats/json.o formats/raw.o formats/common.o formats/custom-type.o HTTP_PARSER_OBJS=http-parser/http_parser.o -CFLAGS=-O0 -ggdb -Wall -Wextra -I. -Ijansson/src -Ihttp-parser -LDFLAGS=-levent -pthread +CFLAGS ?= -O0 -ggdb -Wall -Wextra -I. -Ijansson/src -Ihttp-parser +LDFLAGS ?= -levent -pthread # check for MessagePack MSGPACK_LIB=$(shell ls /usr/lib/libmsgpack.so 2>/dev/null) From 8deffc7403dd2e0017bca6af7e4d261bd1c6e880 Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Mon, 11 Nov 2013 14:51:29 +0200 Subject: [PATCH 4/6] Rename libb64 to b64 for compatibility reasons, move to DEPS. --- Makefile | 5 +++-- {libb64 => b64}/cencode.c | 0 {libb64 => b64}/cencode.h | 0 conf.c | 2 +- websocket.c | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) rename {libb64 => b64}/cencode.c (100%) rename {libb64 => b64}/cencode.h (100%) diff --git a/Makefile b/Makefile index 910fd38..53b1f4a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ OUT=webdis HIREDIS_OBJ=hiredis/hiredis.o hiredis/sds.o hiredis/net.o hiredis/async.o JANSSON_OBJ=jansson/src/dump.o jansson/src/error.o jansson/src/hashtable.o jansson/src/load.o jansson/src/strbuffer.o jansson/src/utf.o jansson/src/value.o jansson/src/variadic.o +B64_OBJS=b64/cencode.o FORMAT_OBJS=formats/json.o formats/raw.o formats/common.o formats/custom-type.o HTTP_PARSER_OBJS=http-parser/http_parser.o @@ -16,8 +17,8 @@ ifneq ($(strip $(MSGPACK_LIB)),) endif -DEPS=$(FORMAT_OBJS) $(HIREDIS_OBJ) $(JANSSON_OBJ) $(HTTP_PARSER_OBJS) -OBJS=webdis.o cmd.o worker.o slog.o server.o libb64/cencode.o acl.o md5/md5.o sha1/sha1.o http.o client.o websocket.o pool.o conf.o $(DEPS) +DEPS=$(FORMAT_OBJS) $(HIREDIS_OBJ) $(JANSSON_OBJ) $(HTTP_PARSER_OBJS) $(B64_OBJS) +OBJS=webdis.o cmd.o worker.o slog.o server.o acl.o md5/md5.o sha1/sha1.o http.o client.o websocket.o pool.o conf.o $(DEPS) diff --git a/libb64/cencode.c b/b64/cencode.c similarity index 100% rename from libb64/cencode.c rename to b64/cencode.c diff --git a/libb64/cencode.h b/b64/cencode.h similarity index 100% rename from libb64/cencode.h rename to b64/cencode.h diff --git a/conf.c b/conf.c index 43c6be1..4fce300 100644 --- a/conf.c +++ b/conf.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include "conf.h" #include "acl.h" diff --git a/websocket.c b/websocket.c index ff5cd70..9b0223c 100644 --- a/websocket.c +++ b/websocket.c @@ -1,5 +1,5 @@ #include "sha1/sha1.h" -#include "libb64/cencode.h" +#include #include "websocket.h" #include "client.h" #include "cmd.h" From b616c37b5f20c4428b092889d3b5dac98ce1e1ed Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Mon, 11 Nov 2013 15:23:10 +0200 Subject: [PATCH 5/6] Remove comments mentioning borrowing code from redis repository. This is no longer true. Files slog.[ch] were introduced in webdis codebase by mrb and were merged into master branch by upstream developer in commit bec19d06. This file originally contained one function void slog(...) with 13 statements. 12 of these statements were copied from function void redisLog(...) from redis-server codebase (https://github.com/antirez/redis, commit aa81e4d5, file src/redis.c, 18 statements). Since that time these files were refactored and have nothing to do with the codebase it was originally based on. Not to mention current src/redis.c from redis repository greatly differs from the mentioned commit where code was borrowed from. --- slog.c | 1 - 1 file changed, 1 deletion(-) diff --git a/slog.c b/slog.c index 087d61b..0d7fd21 100644 --- a/slog.c +++ b/slog.c @@ -1,4 +1,3 @@ -/* A slog is a simple log. Basically extracted from antirez/redis. */ #include #include #include From a712b078b33f7e21ee0e8e77bc82e4bf0168ffb8 Mon Sep 17 00:00:00 2001 From: Andriy Senkovych Date: Mon, 11 Nov 2013 16:57:11 +0200 Subject: [PATCH 6/6] Make dependencies' *_OBJS variables overridable via environment variables. --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 53b1f4a..e2b4b58 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ OUT=webdis -HIREDIS_OBJ=hiredis/hiredis.o hiredis/sds.o hiredis/net.o hiredis/async.o -JANSSON_OBJ=jansson/src/dump.o jansson/src/error.o jansson/src/hashtable.o jansson/src/load.o jansson/src/strbuffer.o jansson/src/utf.o jansson/src/value.o jansson/src/variadic.o -B64_OBJS=b64/cencode.o -FORMAT_OBJS=formats/json.o formats/raw.o formats/common.o formats/custom-type.o -HTTP_PARSER_OBJS=http-parser/http_parser.o +HIREDIS_OBJ?=hiredis/hiredis.o hiredis/sds.o hiredis/net.o hiredis/async.o +JANSSON_OBJ?=jansson/src/dump.o jansson/src/error.o jansson/src/hashtable.o jansson/src/load.o jansson/src/strbuffer.o jansson/src/utf.o jansson/src/value.o jansson/src/variadic.o +B64_OBJS?=b64/cencode.o +FORMAT_OBJS?=formats/json.o formats/raw.o formats/common.o formats/custom-type.o +HTTP_PARSER_OBJS?=http-parser/http_parser.o CFLAGS ?= -O0 -ggdb -Wall -Wextra -I. -Ijansson/src -Ihttp-parser LDFLAGS ?= -levent -pthread