changeset 1044:1fe8d33f75ad

Tests: split out geo tests with binary base and skip by default. These tests require configuration with a large number of geo entries, which may cause long configuration parsing and enrage waitforfile().
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 30 Sep 2016 20:31:09 +0300
parents b82f54728e14
children 3667fe923239
files geo.t geo_binary.t stream_geo.t stream_geo_binary.t
diffstat 4 files changed, 158 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/geo.t
+++ b/geo.t
@@ -158,16 +158,6 @@ http {
         127.0.0.1-127.0.0.255  loopback;
      }
 
-    geo $geo_base_create {
-        ranges;
-        include  base.conf;
-    }
-
-    geo $geo_base_include {
-        ranges;
-        include  base.conf;
-    }
-
     server {
         listen       127.0.0.1:8080;
         server_name  localhost;
@@ -184,8 +174,6 @@ http {
             add_header X-Ins  $geo_insert;
             add_header X-IBe  $geo_insert_before;
             add_header X-IAf  $geo_insert_after;
-            add_header X-GBc  $geo_base_create;
-            add_header X-GBi  $geo_base_include;
             add_header X-Arg  $geo_from_arg;
             add_header X-ARa  $geo_arg_ranges;
             add_header X-XFF  $geo_proxy;
@@ -205,17 +193,13 @@ EOF
 $t->write_file('2', '');
 $t->write_file('geo.conf', '127.0.0.0/8  loopback;');
 $t->write_file('geo-ranges.conf', '127.0.0.0-127.255.255.255  loopback;');
-$t->write_file('base.conf', join('', map {
-	"127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." . $_ % 256 .
-	"-127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." .$_ % 256 . " " .
-	($_ == 1 ? "loopback" : "range$_") . ";" } (0 .. 100000)));
 
 $t->run();
 
 plan(skip_all => 'no 127.0.0.1 on host')
 	if http_get('/1') !~ /X-IP: 127.0.0.1/m;
 
-$t->plan(24);
+$t->plan(22);
 
 ###############################################################################
 
@@ -240,8 +224,6 @@ like($r, qr/^X-AAf: loopback/m, 'geo ran
 like($r, qr/^X-Ins: loopback/m, 'geo ranges insert');
 like($r, qr/^X-IBe: loopback/m, 'geo ranges insert before');
 like($r, qr/^X-IAf: loopback/m, 'geo ranges insert after');
-like($r, qr/^X-GBc: loopback/m, 'geo binary base create');
-like($r, qr/^X-GBi: loopback/m, 'geo binary base include');
 
 like(http_get('/1?ip=192.0.2.1'), qr/^X-Arg: test/m, 'geo from variable');
 like(http_get('/1?ip=10.0.0.1'), qr/^X-Arg: default/m, 'geo default');
new file mode 100644
--- /dev/null
+++ b/geo_binary.t
@@ -0,0 +1,84 @@
+#!/usr/bin/perl
+
+# (C) Andrey Zelenkov
+# (C) Nginx, Inc.
+
+# Tests for nginx geo module with binary base.
+
+###############################################################################
+
+use warnings;
+use strict;
+
+use Test::More;
+
+BEGIN { use FindBin; chdir($FindBin::Bin); }
+
+use lib 'lib';
+use Test::Nginx;
+
+###############################################################################
+
+select STDERR; $| = 1;
+select STDOUT; $| = 1;
+
+plan(skip_all => 'long configuration parsing') unless $ENV{TEST_NGINX_UNSAFE};
+
+my $t = Test::Nginx->new()->has(qw/http geo/);
+
+$t->write_file_expand('nginx.conf', <<'EOF');
+
+%%TEST_GLOBALS%%
+
+daemon off;
+
+events {
+}
+
+http {
+    %%TEST_GLOBALS_HTTP%%
+
+    geo $geo_base_create {
+        ranges;
+        include  base.conf;
+    }
+
+    geo $geo_base_include {
+        ranges;
+        include  base.conf;
+    }
+
+    server {
+        listen       127.0.0.1:8080;
+        server_name  localhost;
+
+        location / {
+            add_header X-IP   $remote_addr;
+            add_header X-GBc  $geo_base_create;
+            add_header X-GBi  $geo_base_include;
+        }
+    }
+}
+
+EOF
+
+$t->write_file('1', '');
+$t->write_file('base.conf', join('', map {
+	"127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." . $_ % 256 .
+	"-127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." .$_ % 256 . " " .
+	($_ == 1 ? "loopback" : "range$_") . ";" } (0 .. 100000)));
+
+$t->run();
+
+plan(skip_all => 'no 127.0.0.1 on host')
+	if http_get('/1') !~ /X-IP: 127.0.0.1/m;
+
+$t->plan(2);
+
+###############################################################################
+
+my $r = http_get('/1');
+like($r, qr/^X-GBc: loopback/m, 'geo binary base create');
+like($r, qr/^X-GBi: loopback/m, 'geo binary base include');
+
+###############################################################################
--- a/stream_geo.t
+++ b/stream_geo.t
@@ -162,16 +162,6 @@ stream {
         127.0.0.1-127.0.0.255  loopback;
      }
 
-    geo $geo_base_create {
-        ranges;
-        include  base.conf;
-    }
-
-    geo $geo_base_include {
-        ranges;
-        include  base.conf;
-    }
-
     server {
         listen  127.0.0.1:8080;
         return  "geo:$geo
@@ -184,8 +174,6 @@ stream {
                  geo_insert:$geo_insert
                  geo_insert_before:$geo_insert_before
                  geo_insert_after:$geo_insert_after
-                 geo_base_create:$geo_base_create
-                 geo_base_include:$geo_base_include
                  geo_from_addr:$geo_from_addr
                  geo_from_var:$geo_from_var";
     }
@@ -230,12 +218,8 @@ EOF
 
 $t->write_file('geo.conf', '127.0.0.0/8  loopback;');
 $t->write_file('geo-ranges.conf', '127.0.0.0-127.255.255.255  loopback;');
-$t->write_file('base.conf', join('', map {
-	"127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." . $_ % 256 .
-	"-127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." .$_ % 256 . " " .
-	($_ == 1 ? "loopback" : "range$_") . ";" } (0 .. 100000)));
 
-$t->try_run('no stream geo')->plan(21);
+$t->try_run('no stream geo')->plan(19);
 
 ###############################################################################
 
@@ -260,8 +244,6 @@ is($data{geo_after}, 'loopback', 'geo ra
 is($data{geo_insert}, 'loopback', 'geo ranges insert');
 is($data{geo_insert_before}, 'loopback', 'geo ranges insert before');
 is($data{geo_insert_after}, 'loopback', 'geo ranges insert after');
-is($data{geo_base_create}, 'loopback', 'geo binary base create');
-is($data{geo_base_include}, 'loopback', 'geo binary base include');
 
 is($data{geo_from_addr}, 'loopback', 'geo from addr');
 is($data{geo_from_var}, 'test', 'geo from var');
new file mode 100644
--- /dev/null
+++ b/stream_geo_binary.t
@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+
+# (C) Andrey Zelenkov
+# (C) Nginx, Inc.
+
+# Tests for stream geo module with binary base.
+
+###############################################################################
+
+use warnings;
+use strict;
+
+use Test::More;
+
+BEGIN { use FindBin; chdir($FindBin::Bin); }
+
+use lib 'lib';
+use Test::Nginx;
+use Test::Nginx::Stream qw/ stream /;
+
+###############################################################################
+
+select STDERR; $| = 1;
+select STDOUT; $| = 1;
+
+plan(skip_all => 'long configuration parsing') unless $ENV{TEST_NGINX_UNSAFE};
+
+my $t = Test::Nginx->new()->has(qw/stream stream_return stream_geo/);
+
+$t->write_file_expand('nginx.conf', <<'EOF');
+
+%%TEST_GLOBALS%%
+
+daemon off;
+
+events {
+}
+
+stream {
+    geo $geo_base_create {
+        ranges;
+        include  base.conf;
+    }
+
+    geo $geo_base_include {
+        ranges;
+        include  base.conf;
+    }
+
+    server {
+        listen  127.0.0.1:8080;
+        return  "geo_base_create:$geo_base_create
+                 geo_base_include:$geo_base_include";
+    }
+}
+
+EOF
+
+$t->write_file('base.conf', join('', map {
+	"127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." . $_ % 256 .
+	"-127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." .$_ % 256 . " " .
+	($_ == 1 ? "loopback" : "range$_") . ";" } (0 .. 100000)));
+
+$t->try_run('no stream geo')->plan(2);
+
+###############################################################################
+
+my %data = stream()->read() =~ /(\w+):(\w+)/g;
+is($data{geo_base_create}, 'loopback', 'geo binary base create');
+is($data{geo_base_include}, 'loopback', 'geo binary base include');
+
+###############################################################################