]> git.ipfire.org Git - thirdparty/libvirt.git/commit
tests: rewrite socket to do something sensible and reliable
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 1 May 2018 10:55:02 +0000 (11:55 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Tue, 4 Sep 2018 12:22:06 +0000 (13:22 +0100)
commit39015a6f3a0d4f9ca2041b9227094f0bcc2217e9
treee55bfeb3f21b5a499fa1376740164fddaae6fba1
parent9e2fad87b429060842a536de26d6af61ea3d96ea
tests: rewrite socket to do something sensible and reliable

The current socket test is rather crazy in that it sets up a server
listening for sockets and then runs a client connect call, relying on
the fact that the kernel will accept this despite the application
not having called accept() yet. It then closes the client socket and
calls accept() on the server. On Linux accept() will always see that
the client has gone and so skip the rest of the code. On FreeBSD,
however, the accept sometimes succeeds, causing us to then go into
code that attempts to read and write to the client which will fail
aborting the test. The accept() never succeeds on FreeBSD guests
with a single CPU, but as you add more CPUs, accept() becomes more and
more likely to succeed, giving a 100% failure rate for the test when
using 8 CPUs.

This completely rewrites the test so that it is avoids this designed in
race condition. We simply spawn a background thread to act as the
client, which will read a byte from the server and write it back again.
The main thread can now properly listen and accept the client in a
synchronous manner avoiding any races.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
tests/virnetsockettest.c