summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/test_config.py29
-rw-r--r--tests/t_event.c32
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/integration/test_config.py b/tests/integration/test_config.py
new file mode 100644
index 0000000..1a84fa7
--- /dev/null
+++ b/tests/integration/test_config.py
@@ -0,0 +1,29 @@
1"""Settings the tracker has to accept, and still work with.
2
3An unrecognised key makes opentracker refuse to start, so a test that it
4comes up at all is a test that the key was understood.
5"""
6
7import unittest
8
9from harness import Tracker, TrackerTestCase, free_port
10
11
12class TcpWorkers(TrackerTestCase):
13 config = "listen.tcp.workers 2\n"
14
15 def test_the_tracker_serves_with_tcp_workers_asked_for(self):
16 self.assertEqual(self.tracker.announce(self.hash_for("tcpworkers"))[b"complete"], 1)
17
18
19class WorkersOnAListenStatement(unittest.TestCase):
20 def test_a_listen_statement_may_carry_a_worker_count(self):
21 """The option is read off the statement rather than inherited."""
22 second = free_port()
23 tracker = Tracker("listen.tcp 127.0.0.1:%d workers=2\n" % second)
24 try:
25 self.assertEqual(tracker.announce(b"listenopts\0\0\0\0\0\0\0\0\0\0")[b"complete"], 1)
26 complaints = tracker.stop()
27 self.assertEqual(complaints, [], "the tracker reported:\n" + "\n".join(complaints))
28 finally:
29 tracker._cleanup()
diff --git a/tests/t_event.c b/tests/t_event.c
index ad3948f..1908dc9 100644
--- a/tests/t_event.c
+++ b/tests/t_event.c
@@ -241,9 +241,40 @@ static void case_close_takes_it_out(void) {
241 pair_close(); 241 pair_close();
242} 242}
243 243
244/* A descriptor can be taken on before anybody waits for anything on it: the
245 full scrape parks a connection while a worker thread builds the reply. The
246 mechanisms disagree about what registering nothing means, so what is
247 checked is that asking for a filter afterwards still works. */
248static void case_add_nothing_then_ask(void) {
249 test_case("a descriptor added with no interest can be given some later");
250 pair_open();
251 CHECK(sv[0] != -1);
252 CHECK_INT(event_add(sv[0], 0, 7), 0);
253 CHECK_INT((int)write(sv[1], "x", 1), 1);
254 CHECK_INT(wait_for(sv[0], EVENT_IN, 200, NULL), 0);
255
256 CHECK_INT(event_modify(sv[0], EVENT_IN, 7), 0);
257 {
258 uint32_t generation = 0;
259 CHECK_INT(wait_for(sv[0], EVENT_IN, 500, &generation), 1);
260 CHECK_INT((int)generation, 7);
261 }
262 event_del(sv[0]);
263 pair_close();
264}
265
266/* Whether a worker thread may register a descriptor while this one waits
267 depends on who keeps the set. Tying the answer to the mechanism's name
268 here means a backend added later cannot quietly forget to say. */
269static void case_sharing_matches_the_mechanism(void) {
270 test_case("only a set the kernel keeps may be changed from another thread");
271 CHECK_INT(event_can_share(), strcmp(event_mechanism(), "poll") ? 1 : 0);
272}
273
244void test_event(void) { 274void test_event(void) {
245 CHECK_INT(event_init(), 0); 275 CHECK_INT(event_init(), 0);
246 CHECK(event_mechanism() != NULL); 276 CHECK(event_mechanism() != NULL);
277 case_sharing_matches_the_mechanism();
247 278
248 case_readable(); 279 case_readable();
249 case_writable(); 280 case_writable();
@@ -254,6 +285,7 @@ void test_event(void) {
254 case_timeout(); 285 case_timeout();
255 case_unknown_descriptor(); 286 case_unknown_descriptor();
256 case_close_takes_it_out(); 287 case_close_takes_it_out();
288 case_add_nothing_then_ask();
257 289
258 event_deinit(); 290 event_deinit();
259} 291}