1220 Commits

Author SHA1 Message Date
Azat Khuzhin
6dbad0f671
test/dns: in solaris under EMFILE devpoll does not dispatch (due DP_POLL failure) 2019-02-04 22:43:47 +03:00
Azat Khuzhin
d234902da7
test/dns: in solaris under EMFILE the error is EAI_FAIL 2019-02-03 18:56:01 +03:00
Azat Khuzhin
ae9b285d2d
test/ssl/bufferevent_wm: explicitly break the loop once client/server received enough
There can be tricky cases (that can be reproduced by reducing
SO_RCVBUF/SO_SNDBUF to 6144, on linux, and be aware, since linux doubles
this const), when there is still write event pending, although we read
enough.

This should be fixed in a more sophisticated way, but to backport the
patch, let's simply break the loop manually.

The ssl/bufferevent_wm originally failed on solaris.
2019-02-03 18:51:28 +03:00
Azat Khuzhin
b29207dcee
Eliminate fd conversion warnings and introduce EVUTIL_INVALID_SOCKET (windows)
windows has intptr_t instead of regular int.

Also tt_fd_op() had been introduced, since we cannot use tt_int_op() for
comparing fd, since it is not always int.
2019-01-29 22:03:08 +03:00
Azat Khuzhin
0791a17204
test/et/et: use evutil_socket_t* over int* for pointer to the pair
Next code will not work correctly under win x64:
  evutil_socket_t very_long_pair_name[2];
  int *pair = very_long_pair_name; // <-- accessing the second word of the first element

Because sizeof(evutil_socket_t) == sizeof(intptr_t) == 8

P.S. in the 5334762f another test had been fixed instead of the one that
really fails.

Fixes: 5334762f ("test/et/et: fix it by using appropriate type for the SOCKET (evutil_socket_t)")
Refs: #750
2019-01-29 21:11:27 +03:00
Azat Khuzhin
5334762fcf
test/et/et: fix it by using appropriate type for the SOCKET (evutil_socket_t)
Fixes: #750
2019-01-29 10:54:22 +03:00
Azat Khuzhin
3e37fcd43c
test/et/et: verify return codes 2019-01-29 10:54:07 +03:00
Azat Khuzhin
b8ca5a6820
test: add logging for http/read_on_write_error and rearrange code 2019-01-29 00:51:46 +03:00
Azat Khuzhin
4ffc711617
test: adjust expecting error for getaddrinfo() under EMFILE
When getaddrinfo() cannot allocate file descriptor glibc/musl-libc on
linux report EAI_SYSTEM error. But this is not true for freebsd libc [1]
(and hence apple libc [2]), they report EAI_NONAME error instead, so
adjust expectation.

  [1]: https://github.com/freebsd/freebsd/blob/master/lib/libc/net/getaddrinfo.c
  [2]: https://opensource.apple.com/source/Libc/

Refs: #749
Refs: https://github.com/libevent/libevent/issues/749#issuecomment-457838159
2019-01-26 19:57:37 +03:00
Azat Khuzhin
91a2f1346e
test/nonpersist_readd: use assert helpers
To debug failure under win32 in appveyor:
  https://ci.appveyor.com/project/nmathewson/libevent/builds/21559140/job/dn16qdo1j6sr497t#L1620
2019-01-12 14:14:51 +03:00
Azat Khuzhin
e5ec52d100
test-fdleak: fix memory leaks
Fixes: #726
2018-12-08 17:35:53 +03:00
Azat Khuzhin
1d2ef90032
test: add TT_RETRIABLE for http/cancel_by_host_no_ns
Could fail from time to time in travis-ci:
  https://travis-ci.org/libevent/libevent/jobs/458554097#L1702

Follow-up-for: fe5b0719 ("Mark a lot of flacky tests with TT_RETRIABLE (for linux/win32 only)")
2018-11-23 00:43:40 +03:00
Azat Khuzhin
fe5b07199d
Mark a lot of flacky tests with TT_RETRIABLE (for linux/win32 only)
This patch mark testcases that only fail under travis-ci/appveyor with
TT_RETRIABLE, since otherwise there is too much noise, other issues
(like failures under vagrant boxes) would be investigated separatelly.

linux (from travis-ci only):
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_by_host_ns_timeout
- http/cancel_by_host_ns_timeout_inactive_server
- thread/conditions_simple
- util/monotonic_prc_precise
- util/usleep
- main/del_wait

vagrant/ubuntu box (this is the only exception):
- thread/no_events

win32 (from appveyor only):
- main/active_later
- main/persistent_active_timeout

And we should use TT_RETRIABLE over TT_OFF_BY_DEFAULT/TT_SKIP when it
make sense.

But there is still "test-ratelim__group_lim" left.
2018-11-20 23:02:56 +03:00
Azat Khuzhin
63b065be80
regress: introduce TT_RETRIABLE
We have some tests that has false-positive due to real/CPU time bound,
but they are pretty generic and we do not want to skip them by default.

TT_RETRIABLE is the flag that will indicate tinytest to retry the test
in case of failure, use it to avoid next possible false-positives:
- real time-related
- CPU time-related
Since I guess it is better to see/grepping RETRYING messages over
ignoring completely failed builds.

No configuration switch for number of retries was done on purpose (only
3 retries and no more).

And this is how it looks BTW:
  $ gcc ../test/tinytest_demo.c ../test/tinytest.c
  $ ./a.out --verbose --no-fork
  demo/timeout_retry
  demo/timeout_retry:
    FAIL ../test/tinytest_demo.c:201: assert(i != 1): 1 vs 1
    [timeout_retry FAILED]

    [RETRYING timeout_retry (3)]
  demo/timeout_retry:
           OK ../test/tinytest_demo.c:201: assert(i != 1): 2 vs 1
           OK ../test/tinytest_demo.c:213: assert(t2-t1 >= 4): 5 vs 4
           OK ../test/tinytest_demo.c:215: assert(t2-t1 <= 6): 5 vs 6
  1 tests ok.  (0 skipped)
2018-11-20 22:56:28 +03:00
Azat Khuzhin
3036f15a17
regress_http: fix compilation with !EVENT__HAVE_OPENSSL
Fixes: 811c63f7 ("regress: test for HTTP/HTTPS with IOCP enabled")
2018-11-20 06:22:27 +03:00
Azat Khuzhin
f8d510f617
regress_bufferevent: add TT_IOCP_LEGACY/TT_IOCP 2018-11-13 23:31:16 +03:00
Azat Khuzhin
903c6acea5
t/bench_http: disable buffering (win32 do not show anything otherwise)
Refs: #255
2018-11-13 23:31:16 +03:00
Azat Khuzhin
811c63f7bc
regress: test for HTTP/HTTPS with IOCP enabled
Next tests added:
- iocp/http/simple
- iocp/http/https_simple
2018-11-13 22:46:20 +03:00
Azat Khuzhin
b2d4fb4176
regress: add EVENT_NO_FILE_BUFFERING, to disable buffering for stdout/stderr
Useful for win32
2018-11-13 22:25:13 +03:00
Azat Khuzhin
1fc1c7ef1d
regress_ssl: fix ssl/bufferevent_wm_filter for non defered callbacks
Even after referenced patch there is still possible recursive callbacks
from evbuffer_drain(bev_input), i.e.:
  wm_transfer() -> evbuffer_drain() -> wm_transfer()
                   inc(ctx->get)

But if we will increment ctx->get before drain that we will not add more
data to buffer.

Refs: 54c6fe3c ("regress_ssl: make ssl/bufferevent_wm_filter more fault-tolerance")
CI: https://ci.appveyor.com/project/nmathewson/libevent/build/job/f0rv299i71wnuxdq#L2546
2018-11-08 00:46:13 +03:00
Azat Khuzhin
54c6fe3c06
regress_ssl: make ssl/bufferevent_wm_filter more fault-tolerance
Due to inplace callbacks (i.e. no BEV_OPT_DEFER_CALLBACKS) we cannot be
sure that wm_transfer() will not be called recursively and indeed it
still happens sometimes, and the referenced patch increase amount of
this times, especially for linux/poll.

Fixes: 66304a23cf748714159c988e78f35401c5352827 ("Fix
ssl/bufferevent_wm_filter when bev does not reach watermark on break")
2018-11-05 22:25:15 +03:00
Azat Khuzhin
9040707fb1
regress_http: disable http/read_on_write_error under win32
EVHTTP_CON_READ_ON_WRITE_ERROR works only if an error already read from
the socket, but if we already got EPIPE on write we cannot read from the
socket anymore, and win32 does not guarantee that read will happens
before (although it happens from time to time).

In the referenced patch I just replaced callback with not expecting 417,
but like I already wrote, this is not always true (i.e. it is flacky).

Fixes: 3b581693ac1967f7f8d98491cb772a1b415eb4cd ("test/http:
read_on_write_error: fix it for win32")
2018-11-05 21:37:07 +03:00
Azat Khuzhin
66304a23cf
Fix ssl/bufferevent_wm_filter when bev does not reach watermark on break
For the ssl/bufferevent_wm* we have next configuration:
- payload_len = 1024
- wm_high     = 5120
- limit       = 40960
- to_read     = 512

In this test we expect that with high watermark installed to "wm_high"
we will read "limit" bytes by reading "to_read" at a time, but adding
"payload_len" at a time (this "to_read"/"payload_len" limits is
installed to finally overflow watermark).

Once we read "limit" bytes we break, by disable EV_READ and reset
callbacks. Although this will not work if when we want to break we do
not reach watermark, this is because watermarks installs evbuffer
callback for the input buffer and if the watermark does not reached it
will enable EV_READ while be_openssl_enable() will read from the
underlying buffer (in case the openssl bufferevent created via
bufferevent_openssl_filter_new()) and call callback again (until it will
reach watermark or read al from the underlying buffer -- this is why it
stops in our caes).

And this is exactly what happened in win32, you can see this in the
following logs:

- win32 before:
    OK C:\vagrant\test\regress_ssl.c:829: wm_transfer-client(00DC2750): in: 4608, out: 0, got: 40960
    OK C:\vagrant\test\regress_ssl.c:834: wm_transfer-client(00DC2750): break
    OK C:\vagrant\test\regress_ssl.c:829: wm_transfer-client(00DC2750): in: 4608, out: 0, got: 41472
    OK C:\vagrant\test\regress_ssl.c:834: wm_transfer-client(00DC2750): break
    OK C:\vagrant\test\regress_ssl.c:829: wm_transfer-client(00DC2750): in: 4608, out: 0, got: 41984
    OK C:\vagrant\test\regress_ssl.c:834: wm_transfer-client(00DC2750): break
    OK C:\vagrant\test\regress_ssl.c:829: wm_transfer-client(00DC2750): in: 4608, out: 0, got: 42496
    OK C:\vagrant\test\regress_ssl.c:834: wm_transfer-client(00DC2750): break

- win32 after:
    OK C:\vagrant\test\regress_ssl.c:821: wm_transfer-client(00FC26F0): break
    OK C:\vagrant\test\regress_ssl.c:836: wm_transfer-client(00FC26F0): in: 4800, out: 0, got: 40960

- linux before:
    OK ../test/regress_ssl.c:829: wm_transfer-client(0x55555566f5e0): in: 5120, out: 0, got: 40960
    OK ../test/regress_ssl.c:834: wm_transfer-client(0x55555566f5e0): break

- linux after:
    OK ../test/regress_ssl.c:821: wm_transfer-client(0x55555566f5e0): break
    OK ../test/regress_ssl.c:836: wm_transfer-client(0x55555566f5e0): in: 5120, out: 0, got: 40960

(As you can see in linux case we already reach watermark hence it passed
before).

So fix the issue by breaking before draining.

But during fixing this I was thinking is this right? I.e. reading from
the be_openssl_enable(), maybe we should force deferred callbacks at
least?
2018-11-04 21:41:13 +03:00
Azat Khuzhin
e8c407e7b5
regress_ssl: cover watermarks with deferred callbacks 2018-11-04 21:41:13 +03:00
Azat Khuzhin
fb7f43f064
regress_ssl: improve bufferevent_wm/bufferevent_wm_filter logging
- add bev pointer
- use EV_SIZE_FMT over %zu (win32)
2018-11-04 21:41:13 +03:00
Azat Khuzhin
e29afd4b94
regress_http: make https_basic non time dependent
Fixes: #454
2018-11-04 01:56:46 +03:00
Azat Khuzhin
4cbdb39c27
regress: use non blocking descriptors whenever it is possible
Next tests uses fds without O_NONBLOCK flag
- main/free_active_base
- main/many_events
- et/et (has some other bits cleaned up by using TT_* flags and test
  setup/cleanup callbacks)

And hence they will fail in debug mode (EVENT_DEBUG_MODE=):
  Assertion flags & O_NONBLOCK failed in event_debug_assert_socket_nonblocking_
2018-11-04 01:15:24 +03:00
Isidor Kouvelas
77c0e51058
Cover ET with multiple events for same fd
[ azat: test cleanup ]
2018-10-31 01:21:07 +03:00
Azat Khuzhin
9cba915ee8
Introduce EVENT_VISIBILITY_WANT_DLLIMPORT
And use it in places where event_debug() should be called (since it
requires access to "event_debug_logging_mask_" and in win32 it is
tricky).

One of this places that is covered by this patch is the test for
event_debug().
2018-10-28 19:45:57 +03:00
Azat Khuzhin
5cfb612087
regress_http: use TT_BLAZER() over event_debug()
Later is pretty tricky due to exporting event_debug_logging_mask_ symbol
for win32.
2018-10-28 19:45:52 +03:00
Azat Khuzhin
fb42e0fac6
bench_cascase: include getopt.h only for _WIN32 (like in other places)
Fixes: #561
2018-10-28 02:00:58 +03:00
Azat Khuzhin
9fe952a0ae
regress_ssl: reset static variables on test setup/cleanup and eliminate leaks
One tricky bit is reply to the BIO_C_GET_FD command, since otherwise it
will try to close(0) and accepted bev in ssl/bufferevent_connect_sleep
will leak. Other seems more or less trivial.

This was done to make sure that for at least generic cases does not
leak (tricky cases was listed here nmathewson/Libevent#83).

And this will allow run ssl/.. with --no-fork
2018-10-28 01:25:43 +03:00
Azat Khuzhin
7cec9b95a3
test: export basic_test_setup/basic_test_cleanup to extend them 2018-10-28 01:21:35 +03:00
Azat Khuzhin
26ef859aa7
Add evhttp_parse_query_str_flags()
And a set of flags:
- EVHTTP_URI_QUERY_LAST
- EVHTTP_URI_QUERY_NONCONFORMANT

Fixes: #15
2018-10-27 17:59:11 +03:00
Azat Khuzhin
d161ec3842
regress_http: basic evhttp_parse_query_str() coverage 2018-10-27 17:58:12 +03:00
Azat Khuzhin
32349ab6f4
Cover evutil_v4addr_is_local_()/evutil_v6addr_is_local_() 2018-10-25 00:49:46 +03:00
Azat Khuzhin
5f1b4dfa02
Fix http https_basic/https_filter_basic under valgrind (increase timeout) 2018-10-23 00:12:10 +03:00
Azat Khuzhin
15bfe712a7
http: cover various non RFC3986 conformant URIs
- http/basic_trailing_space -- covers cases when there is trailing space
  after the request line (nginx handles this)
- http/simple_nonconformant -- covers non RFC3986 conformant URIs
2018-10-23 00:12:10 +03:00
Azat Khuzhin
6ac8e775bb
Simplify bufferevent timeout tests to reduce CPU usage in between start/compare
Between start (setting "started_at") and comparing the time when
timeouts triggered with the start (test_timeval_diff_eq), there is too
much various things that can introduce extra delays and eventually could
fail the test on machine with shortage of CPU.

And this is exactly what happend on:
- travis-ci
- #262

Here is a simple reproducer that I came up with for this issue:
  docker run --cpus=0.01 -e LD_LIBRARY_PATH=$PWD/lib -e PATH=/usr/bin:/bin:$PWD/bin -v $PWD:$PWD --rm -it debian:testing regress --no-fork --verbose bufferevent/bufferevent_timeout

Under limited CPU (see reproducer) the test almost always has problems
with that "write_timeout_at" exceed default timeval diff tolerance
(test_timeval_diff_eq() has 50 tolerance), i.e.:
  FAIL ../test/regress_bufferevent.c:1040: assert(labs(timeval_msec_diff(((&started_at)), ((&res1.write_timeout_at))) - (100)) <= 50): 101 vs 50

But under some setup write timeout can even not triggered, and the
reason for this is that we write to the bufferevent 1024*1024 bytes, and
hence if evbuffer_write_iovec() will has some delay after writev() and
not send more then one vector at a time [1], it is pretty simple to
trigger, i.e.:
  FAIL ../test/regress_bufferevent.c:1040: assert(labs(timeval_msec_diff(((&started_at)), ((&res1.write_timeout_at))) - (100)) <= 50): 1540155888478 vs 50

  [1]: https://gist.github.com/azat/b72773dfe7549fed865d439e03de05c1

So this patch just send static small payload for all cases (plus a few
more asserts added).

The outcome of this patch is that all regression tests passed on
travis-ci for linux box [2]. While before it fails almost always [3].
Also reproducer with CPU limiting via docker also survive some
iterations (and strictly speaking it should has less CPU then travis-ci
workers I guess).

  [2]: https://travis-ci.org/azat/libevent/builds/444391481
  [3]: https://travis-ci.org/libevent/libevent/builds/444336505
2018-10-22 00:53:07 +03:00
Azat Khuzhin
2cb8eae795
Do not rely on getservbyname() for most of the dns regression tests
There is only one test that uses service name getaddrinfo_async, which
manually check whether it works or not, other should not assume that it
is available and works.

There was already an attempt to overcome some possible limitations, like
lack of "http" in /etc/services in
d6bafbbeb27ff3943d6f3b6783bcded76384c31e ("test/dns: replace servname
since solaris does not have "http"")
2018-10-21 03:12:24 +03:00
Azat Khuzhin
7198bbb8f1
Turn off dns/getaddrinfo_race_gotresolve by default
It is:
- pretty internal regression
- CPU bound
- right now failed on travis-ci machines
2018-10-21 03:11:00 +03:00
Azat Khuzhin
09c74f7121
Fix an error for debug locking in dns/getaddrinfo_race_gotresolve
When there is no /etc/services file evdns_getaddrinfo() will fail (with
service="ssh") and hence it will go to then "end" label with locked
rp.lock which in case of debug locking checks will bail with:
  [err] ../evthread.c:220: Assertion lock->count == 0 failed in debug_lock_free

So add rp.locked flag, and unlock the lock before freeing it if it is in
locked state.

And here is how you can reproduce the issue:
  $ docker run -e LD_LIBRARY_PATH=$PWD/lib -e PATH=/usr/bin:/bin:$PWD/bin -v $PWD:$PWD --rm -it debian:testing regress dns/getaddrinfo_race_gotresolve
(since debian:testing does not have /etc/services)
2018-10-21 03:10:12 +03:00
Azat Khuzhin
a5b2ed56c3
test: cover watermarks (with some corner cases) in ssl bufferevent 2018-10-17 11:23:51 +03:00
Azat Khuzhin
8483c5351a
evrpc: avoid NULL dereference on request is not EVHTTP_REQ_POST
Fixes: #660
2018-09-14 02:27:13 +03:00
Carlo Marcelo Arenas Belón
7af974eeaa
test: make sure pthread is defined
avoid warnings with any modern C99 compiler due to implicit function
declaration for pthread_create, as shown by the following :

test/regress_dns.c:2226:2: warning: implicit declaration of function
      'pthread_create' is invalid in C99 [-Wimplicit-function-declaration]
        THREAD_START(thread[0], race_base_run, &rp);
        ^
test/regress_thread.h:35:2: note: expanded from macro 'THREAD_START'
        pthread_create(&(threadvar), NULL, fn, arg)
        ^
test/regress_dns.c:2226:2: warning: this function declaration is not a prototype
      [-Wstrict-prototypes]
test/regress_thread.h:35:2: note: expanded from macro 'THREAD_START'
        pthread_create(&(threadvar), NULL, fn, arg)
        ^

$ clang --version
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Closes: #686 (cherry-picked)
2018-09-14 02:17:45 +03:00
Philip Prindeville
be37116302
Eliminate compiler warnings (at least for gcc/linux)
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Closes: #646 # cherry-picked from the PR
2018-08-17 03:21:49 +03:00
Sergey Fionov
4802c132a2
evdns: add regress test for getaddrinfo race 2018-08-02 09:26:51 +03:00
Leo Zhang
d9ffd22137
test: make regress_dns C89 compatible
Closes: #635 (cherry-picked)
2018-06-21 03:07:55 +03:00
Azat Khuzhin
c57f5c3490 Make rpc headers self-compilable
Fixes: #633
2018-05-07 02:40:16 +03:00
Azat Khuzhin
23c2914f6b Notify event base if there are no more events, so it can exit without delay
Fixes: #623
2018-04-26 01:14:49 +03:00