Add "make check" target (useful for automated tests).
While there, add "-p" option to "hiredis-test", so that we could run tests without interrupting Redis instance running on the default port.
This commit is contained in:
parent
875a209399
commit
5793b999a9
6
Makefile
6
Makefile
@ -105,6 +105,12 @@ hiredis-%: %.o $(STLIBNAME)
|
|||||||
test: hiredis-test
|
test: hiredis-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:
|
.c.o:
|
||||||
$(CC) -std=c99 -pedantic -c $(CFLAGS) $(OBJARCH) $(DEBUG) $(COMPILE_TIME) $<
|
$(CC) -std=c99 -pedantic -c $(CFLAGS) $(OBJARCH) $(DEBUG) $(COMPILE_TIME) $<
|
||||||
|
|
||||||
|
9
test.c
9
test.c
@ -22,10 +22,11 @@ static long long usec(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int use_unix = 0;
|
static int use_unix = 0;
|
||||||
|
static int port = 6379;
|
||||||
static redisContext *blocking_context = NULL;
|
static redisContext *blocking_context = NULL;
|
||||||
static void __connect(redisContext **target) {
|
static void __connect(redisContext **target) {
|
||||||
*target = blocking_context = (use_unix ?
|
*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) {
|
if (blocking_context->err) {
|
||||||
printf("Connection error: %s\n", blocking_context->errstr);
|
printf("Connection error: %s\n", blocking_context->errstr);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -128,7 +129,7 @@ static void test_blocking_connection(void) {
|
|||||||
int major, minor;
|
int major, minor;
|
||||||
|
|
||||||
test("Returns error when host cannot be resolved: ");
|
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 &&
|
test_cond(c->err == REDIS_ERR_OTHER &&
|
||||||
strcmp(c->errstr,"Can't resolve: idontexist.local") == 0);
|
strcmp(c->errstr,"Can't resolve: idontexist.local") == 0);
|
||||||
redisFree(c);
|
redisFree(c);
|
||||||
@ -517,7 +518,7 @@ static void cleanup(void) {
|
|||||||
// static redisContext *__connect_nonblock() {
|
// static redisContext *__connect_nonblock() {
|
||||||
// /* Reset callback flags */
|
// /* Reset callback flags */
|
||||||
// __test_callback_flags = 0;
|
// __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() {
|
// static void test_nonblocking_connection() {
|
||||||
@ -601,6 +602,8 @@ int main(int argc, char **argv) {
|
|||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
if (strcmp(argv[1],"-s") == 0)
|
if (strcmp(argv[1],"-s") == 0)
|
||||||
use_unix = 1;
|
use_unix = 1;
|
||||||
|
if ((strcmp(argv[1],"-p") == 0) && (argc == 3))
|
||||||
|
port = atoi(argv[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
Loading…
Reference in New Issue
Block a user