From a851745140c93c5af018fde3c3bc9932833e4d67 Mon Sep 17 00:00:00 2001 From: Peter Leonov Date: Mon, 17 May 2010 16:59:52 +0400 Subject: [PATCH] the first ever real subrequests tests ;) --- js/tests/subrequests.js | 42 +++++++++++++++++++++-------------------- nginx.conf | 2 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/js/tests/subrequests.js b/js/tests/subrequests.js index 8432ef7..802800e 100644 --- a/js/tests/subrequests.js +++ b/js/tests/subrequests.js @@ -11,17 +11,12 @@ NginxTests.subrequests = function (r) { function callback (sr, body, rc) { - var body = String(body) - r.puts('callback with rc=' + rc + ', body=' + JSON.stringify(body) + ', header=' + sr.headersOut['X-Lalala']) - r.flush() - t.done() + t.match(String(body), /403 Forbidden/i, 'body') + t.eq(rc, 403, 'rc') - return Nginx.DONE + t.done() } - // r.setTimeout(function () { t.done() }, 500) - // t.wait(3000) - r.subrequest('/quick', callback) t.wait(3000) }) @@ -30,37 +25,44 @@ NginxTests.subrequests = function (r) { function callback (sr, body, rc) { - var body = String(body) - r.puts('callback with rc=' + rc + ', body=' + JSON.stringify(body) + ', header=' + sr.headersOut['X-Lalala']) - r.flush() + t.match(String(body), /welcome to nginx/i, 'body') + t.done() + } + + r.subrequest('/loopback/', callback) + t.wait(3000) + }) + + t.test('JS handler', function (t) + { + function callback (sr, body, rc) + { + t.eq(sr.headersOut['X-Lalala'], 'lololo', 'headersOut["X-Lalala"]') - return Nginx.DONE + t.done() } // r.setTimeout(function () { t.done() }, 500) // t.wait(3000) - r.subrequest('/slow', callback) + r.subrequest('/run/subrequests-headers', callback) t.wait(3000) }) - t.test('/run/subrequests-headers', function (t) + t.test('JS handler via proxy pass', function (t) { function callback (sr, body, rc) { - var body = String(body) - r.puts('callback with rc=' + rc + ', body=' + JSON.stringify(body) + ', header=' + sr.headersOut['X-Lalala']) - r.flush() - t.done() + t.eq(sr.headersOut['X-Lalala'], 'lololo', 'headersOut["X-Lalala"]') - return Nginx.DONE + t.done() } // r.setTimeout(function () { t.done() }, 500) // t.wait(3000) - r.subrequest('/slow', callback) + r.subrequest('/loopback/run/subrequests-headers', callback) t.wait(3000) }) }) diff --git a/nginx.conf b/nginx.conf index 8a711f2..8595a58 100644 --- a/nginx.conf +++ b/nginx.conf @@ -74,7 +74,7 @@ http return 403; } - location /slow + location /loopback { proxy_pass http://127.0.0.1:19090/; proxy_set_header Host "localhost";