proxy_store.t 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/perl
  2. # (C) Maxim Dounin
  3. # Tests for proxy_store functionality.
  4. ###############################################################################
  5. use warnings;
  6. use strict;
  7. use Test::More;
  8. BEGIN { use FindBin; chdir($FindBin::Bin); }
  9. use lib 'lib';
  10. use Test::Nginx;
  11. ###############################################################################
  12. select STDERR; $| = 1;
  13. select STDOUT; $| = 1;
  14. my $t = Test::Nginx->new();
  15. $t->write_file_expand('nginx.conf', <<'EOF')->has(qw/http proxy ssi/)->plan(7);
  16. %%TEST_GLOBALS%%
  17. master_process off;
  18. daemon off;
  19. events {
  20. }
  21. http {
  22. %%TEST_GLOBALS_HTTP%%
  23. server {
  24. listen 127.0.0.1:8080;
  25. server_name localhost;
  26. location /store- {
  27. proxy_pass http://127.0.0.1:8080/;
  28. proxy_store on;
  29. }
  30. location /ssi.html {
  31. ssi on;
  32. }
  33. location /index-nostore.html {
  34. add_header X-Accel-Expires 0;
  35. }
  36. location /index-big.html {
  37. limit_rate 200k;
  38. }
  39. }
  40. }
  41. EOF
  42. $t->write_file('index.html', 'SEE-THIS');
  43. $t->write_file('index-nostore.html', 'SEE-THIS');
  44. $t->write_file('index-big.html', 'x' x (100 << 10));
  45. $t->write_file('ssi.html',
  46. '<!--#include virtual="/store-index-big.html?1" -->' .
  47. '<!--#include virtual="/store-index-big.html?2" -->'
  48. );
  49. $t->run();
  50. ###############################################################################
  51. like(http_get('/store-index.html'), qr/SEE-THIS/, 'proxy request');
  52. ok(-e $t->testdir() . '/store-index.html', 'result stored');
  53. like(http_get('/store-index-nostore.html'), qr/SEE-THIS/,
  54. 'proxy request with x-accel-expires');
  55. TODO: {
  56. local $TODO = 'patch under review';
  57. ok(!-e $t->testdir() . '/store-index-nostore.html', 'result not stored');
  58. }
  59. ok(scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]} == 0, 'no temp files');
  60. http_get('/store-index-big.html', aborted => 1, sleep => 0.1);
  61. sleep(1);
  62. ok(scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]} == 0,
  63. 'no temp files after aborted request');
  64. TODO: {
  65. local $TODO = 'not fixed yet';
  66. http_get('/ssi.html', aborted => 1, sleep => 0.1);
  67. sleep(1);
  68. ok(scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]} == 0,
  69. 'no temp files after aborted ssi');
  70. }
  71. ###############################################################################