summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/test_udp.py19
-rw-r--r--tests/t_socket.c19
2 files changed, 37 insertions, 1 deletions
diff --git a/tests/integration/test_udp.py b/tests/integration/test_udp.py
index b60bd56..8a255ec 100644
--- a/tests/integration/test_udp.py
+++ b/tests/integration/test_udp.py
@@ -9,7 +9,7 @@ import socket
9import struct 9import struct
10import unittest 10import unittest
11 11
12from harness import TrackerTestCase 12from harness import Tracker, TrackerTestCase
13 13
14MAGIC = 0x41727101980 14MAGIC = 0x41727101980
15 15
@@ -199,3 +199,20 @@ class UdpWorkersConfiguredAfterTheListener(TrackerTestCase):
199 199
200if __name__ == "__main__": 200if __name__ == "__main__":
201 unittest.main() 201 unittest.main()
202
203
204class UdpAddressAlreadyTaken(TrackerTestCase):
205 def test_a_second_tracker_on_the_same_udp_address_says_so(self):
206 """Linux lets it start all the same, and from then on the two take
207 each other's packets. FreeBSD refuses the bind that follows, and the
208 warning is then what explains the refusal."""
209 try:
210 second = Tracker("listen.udp 127.0.0.1:%d\n" % self.tracker.port)
211 except AssertionError as refused:
212 said = str(refused)
213 else:
214 said = second.output()
215 second.stop()
216 second._cleanup()
217 self.assertIn("is already in use", said)
218 self.assertNotIn("is already in use", self.tracker.output())
diff --git a/tests/t_socket.c b/tests/t_socket.c
index 8e917a3..6f07f95 100644
--- a/tests/t_socket.c
+++ b/tests/t_socket.c
@@ -342,6 +342,24 @@ static void case_bind_failure(void) {
342 CHECK_INT(next_descriptor(), before); 342 CHECK_INT(next_descriptor(), before);
343} 343}
344 344
345/* The holder binds the way the tracker does, which lets a second socket in
346 beside it, and that is what the probe is there to see through. */
347static void case_a_taken_udp_address_is_noticed(void) {
348 char ip[16];
349 uint16_t port;
350 int holder;
351
352 test_case("a udp address somebody holds is reported as taken");
353 holder = socket_udp_bind(ip_loopback, 0, SOCKET_SHARED);
354 CHECK(holder != -1);
355 bound_address(holder, ip, &port);
356 CHECK_INT(socket_udp_is_taken(ip_loopback, port), 1);
357
358 test_case("and as free again once it is let go");
359 close(holder);
360 CHECK_INT(socket_udp_is_taken(ip_loopback, port), 0);
361}
362
345#ifdef WANT_SYNC_LIVE 363#ifdef WANT_SYNC_LIVE
346/* Reading an IPv4 multicast option back: Linux answers with an int, the BSDs 364/* Reading an IPv4 multicast option back: Linux answers with an int, the BSDs
347 with a single byte, so ask how much was written. */ 365 with a single byte, so ask how much was written. */
@@ -391,6 +409,7 @@ void test_socket(void) {
391 case_deferred_accept(); 409 case_deferred_accept();
392 case_connect_refused(); 410 case_connect_refused();
393 case_bind_failure(); 411 case_bind_failure();
412 case_a_taken_udp_address_is_noticed();
394#ifdef WANT_SYNC_LIVE 413#ifdef WANT_SYNC_LIVE
395 case_mcast_sender(); 414 case_mcast_sender();
396#endif 415#endif