diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-03 18:51:21 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-03 18:51:21 +0000 |
commit | 9b9aa6efc85d4a71af2a287bbcdd4fccea5255be (patch) | |
tree | 84d6f747d5f6a67d9f67b9857adbc5cc92a83653 /test | |
parent | 5126e935664c63e1430c812dd7c05f0bea5ffc27 (diff) | |
download | rspamd-9b9aa6efc85d4a71af2a287bbcdd4fccea5255be.tar.gz rspamd-9b9aa6efc85d4a71af2a287bbcdd4fccea5255be.zip |
Rework upstreams library
Now each address has its own errors count, so rspamd will prefer upstream addrs with no errors to addrs with errors. This might help to resolve issues on systems where ipv6 does not work.
Diffstat (limited to 'test')
-rw-r--r-- | test/rspamd_upstream_test.c | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/test/rspamd_upstream_test.c b/test/rspamd_upstream_test.c index a446cc05d..61dcd02e9 100644 --- a/test/rspamd_upstream_test.c +++ b/test/rspamd_upstream_test.c @@ -84,6 +84,45 @@ rspamd_upstream_test_func (void) resolver = dns_resolver_init (NULL, ev_base, cfg); rspamd_upstreams_library_config (cfg, cfg->ups_ctx, ev_base, resolver->r); + /* + * Test v4/v6 priorities + */ + nls = rspamd_upstreams_create (cfg->ups_ctx); + g_assert (rspamd_upstreams_add_upstream (nls, "127.0.0.1", 0, NULL)); + up = rspamd_upstream_get (nls, RSPAMD_UPSTREAM_RANDOM, NULL, 0); + rspamd_parse_inet_address (&paddr, "127.0.0.2", 0); + g_assert (rspamd_upstream_add_addr (up, paddr)); + rspamd_parse_inet_address (&paddr, "::1", 0); + g_assert (rspamd_upstream_add_addr (up, paddr)); + /* Rewind to start */ + addr = rspamd_upstream_addr (up); + addr = rspamd_upstream_addr (up); + /* cur should be zero here */ + addr = rspamd_upstream_addr (up); + next_addr = rspamd_upstream_addr (up); + g_assert (rspamd_inet_address_get_af (addr) == AF_INET); + g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET); + next_addr = rspamd_upstream_addr (up); + g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET6); + next_addr = rspamd_upstream_addr (up); + g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET); + next_addr = rspamd_upstream_addr (up); + g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET); + next_addr = rspamd_upstream_addr (up); + g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET6); + /* Test errors with IPv6 */ + rspamd_upstream_fail (up); + /* Now we should have merely IPv4 addresses in rotation */ + addr = rspamd_upstream_addr (up); + for (i = 0; i < 256; i++) { + next_addr = rspamd_upstream_addr (up); + g_assert (rspamd_inet_address_get_af (addr) == AF_INET); + g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET); + g_assert (rspamd_inet_address_compare (addr, next_addr) != 0); + addr = next_addr; + } + rspamd_upstreams_destroy (nls); + ls = rspamd_upstreams_create (cfg->ups_ctx); g_assert (rspamd_upstreams_parse_line (ls, test_upstream_list, 443, NULL)); g_assert (rspamd_upstreams_count (ls) == 3); @@ -128,25 +167,6 @@ rspamd_upstream_test_func (void) rspamd_upstreams_destroy (nls); - /* - * Test v4/v6 priorities - */ - nls = rspamd_upstreams_create (cfg->ups_ctx); - g_assert (rspamd_upstreams_add_upstream (nls, "127.0.0.1", 0, NULL)); - up = rspamd_upstream_get (nls, RSPAMD_UPSTREAM_RANDOM, NULL, 0); - rspamd_parse_inet_address (&paddr, "127.0.0.2", 0); - g_assert (rspamd_upstream_add_addr (up, paddr)); - rspamd_parse_inet_address (&paddr, "::1", 0); - g_assert (rspamd_upstream_add_addr (up, paddr)); - addr = rspamd_upstream_addr (up); - for (i = 0; i < 256; i ++) { - next_addr = rspamd_upstream_addr (up); - g_assert (rspamd_inet_address_get_af (addr) == AF_INET); - g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET); - g_assert (rspamd_inet_address_compare (addr, next_addr) != 0); - addr = next_addr; - } - rspamd_upstreams_destroy (nls); /* Upstream fail test */ evtimer_set (&ev, rspamd_upstream_timeout_handler, resolver); |