Skip to content

Commit

Permalink
Add "make check" target (useful for automated tests).
Browse files Browse the repository at this point in the history
While there, add "-p" option to "hiredis-test", so that we could run
tests without interrupting Redis instance running on the default port.
  • Loading branch information
PiotrSikora authored and pietern committed May 22, 2011
1 parent 875a209 commit 5793b99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ hiredis-%: %.o $(STLIBNAME)
test: hiredis-test
./hiredis-test

check: hiredis-test
echo "daemonize yes\n pidfile /tmp/redis-check.pid\n port 56379" \
| redis-server -
./hiredis-test -p 56379 || (kill `cat /tmp/redis-check.pid` && false)
kill `cat /tmp/redis-check.pid`

.c.o:
$(CC) -std=c99 -pedantic -c $(CFLAGS) $(OBJARCH) $(DEBUG) $(COMPILE_TIME) $<

Expand Down
9 changes: 6 additions & 3 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ static long long usec(void) {
}

static int use_unix = 0;
static int port = 6379;
static redisContext *blocking_context = NULL;
static void __connect(redisContext **target) {
*target = blocking_context = (use_unix ?
redisConnectUnix("/tmp/redis.sock") : redisConnect((char*)"127.0.0.1", 6379));
redisConnectUnix("/tmp/redis.sock") : redisConnect((char*)"127.0.0.1", port));
if (blocking_context->err) {
printf("Connection error: %s\n", blocking_context->errstr);
exit(1);
Expand Down Expand Up @@ -128,7 +129,7 @@ static void test_blocking_connection(void) {
int major, minor;

test("Returns error when host cannot be resolved: ");
c = redisConnect((char*)"idontexist.local", 6379);
c = redisConnect((char*)"idontexist.local", port);
test_cond(c->err == REDIS_ERR_OTHER &&
strcmp(c->errstr,"Can't resolve: idontexist.local") == 0);
redisFree(c);
Expand Down Expand Up @@ -517,7 +518,7 @@ static void cleanup(void) {
// static redisContext *__connect_nonblock() {
// /* Reset callback flags */
// __test_callback_flags = 0;
// return redisConnectNonBlock("127.0.0.1", 6379, NULL);
// return redisConnectNonBlock("127.0.0.1", port, NULL);
// }
//
// static void test_nonblocking_connection() {
Expand Down Expand Up @@ -601,6 +602,8 @@ int main(int argc, char **argv) {
if (argc > 1) {
if (strcmp(argv[1],"-s") == 0)
use_unix = 1;
if ((strcmp(argv[1],"-p") == 0) && (argc == 3))
port = atoi(argv[2]);
}

signal(SIGPIPE, SIG_IGN);
Expand Down

0 comments on commit 5793b99

Please sign in to comment.