Permalink
Browse files

cosocket: fixed ngx_log_debugN for non-debugging builds. also added a…

… passing test case for running Daniele Alessandri's lua-redis library by emulating LuaSocket via ngx.socket :)
  • Loading branch information...
1 parent 166a711 commit a5e501045a3d0bdbd14877b6221b15846bbc1e94 @agentzh agentzh committed Dec 22, 2011
Showing with 1,170 additions and 3 deletions.
  1. +2 −2 src/ngx_http_lua_socket.c
  2. +1 −1 t/060-lua-memcached.t
  3. +47 −0 t/061-lua-redis.t
  4. +1,120 −0 t/lib/Redis.lua
@@ -363,7 +363,7 @@ ngx_http_lua_socket_resolve_handler(ngx_resolver_ctx_t *ctx)
waiting = u->waiting;
if (ctx->state) {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, u->request->connection->log, 0,
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, u->request->connection->log, 0,
"lua socket resolver error: %s (waiting: %d)",
ngx_resolver_strerror(ctx->state), (int) u->waiting);
@@ -1018,7 +1018,7 @@ ngx_http_lua_socket_read(ngx_http_request_t *r,
rc = u->input_filter(u->input_filter_ctx, size);
if (rc == NGX_OK) {
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua socket receive done: wait:%d, eof:%d, "
"uri:\"%V?%V\"", (int) u->waiting, (int) u->eof,
&r->uri, &r->args);
View
@@ -19,7 +19,7 @@ run_tests();
__DATA__
-=== TEST 1: lua-memcached
+=== TEST 1: sanity
--- http_config
lua_package_path '$TEST_NGINX_PWD/t/lib/?.lua;;';
--- config
View
@@ -0,0 +1,47 @@
+# vim:set ft= ts=4 sw=4 et fdm=marker:
+
+use lib 'lib';
+use Test::Nginx::Socket;
+
+repeat_each(2);
+
+plan tests => blocks() * repeat_each() * 2;
+
+$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
+$ENV{TEST_NGINX_CLIENT_PORT} ||= server_port();
+
+#log_level "warn";
+#worker_connections(1024);
+#master_on();
+
+my $pwd = `pwd`;
+chomp $pwd;
+$ENV{TEST_NGINX_PWD} ||= $pwd;
+
+no_long_string();
+run_tests();
+
+__DATA__
+
+=== TEST 1: sanity
+--- http_config
+ lua_package_path '$TEST_NGINX_PWD/t/lib/?.lua;;';
+--- config
+ location /test {
+ content_by_lua '
+ package.loaded["socket"] = ngx.socket
+ local Redis = require "Redis"
+ -- Redis.socket = ngx.socket
+
+ local redis = Redis.connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
+
+ redis:set("some_key", "hello 1234")
+ local data = redis:get("some_key")
+ ngx.say("some_key: ", data)
+ ';
+ }
+--- request
+ GET /test
+--- response_body
+some_key: hello 1234
+
Oops, something went wrong.

0 comments on commit a5e5010

Please sign in to comment.