Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Commit

Permalink
the first ever real subrequests tests ;)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-leonov committed May 17, 2010
1 parent 87cd9a7 commit a851745
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
42 changes: 22 additions & 20 deletions js/tests/subrequests.js
Expand Up @@ -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)
})
Expand All @@ -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)
})
})
Expand Down
2 changes: 1 addition & 1 deletion nginx.conf
Expand Up @@ -74,7 +74,7 @@ http
return 403;
}

location /slow
location /loopback
{
proxy_pass http://127.0.0.1:19090/;
proxy_set_header Host "localhost";
Expand Down

0 comments on commit a851745

Please sign in to comment.