]> git.ozlabs.org Git - ccan-lca-2011.git/blobdiff - ccan/oserver/test/run.c
lca2011: dump on SIGHUP.
[ccan-lca-2011.git] / ccan / oserver / test / run.c
index b093a560c56fa273745134d4e360799328c57ec6..a8eb6f24391042b064cddaa243fe2c3ac80c2762 100644 (file)
@@ -1,4 +1,5 @@
 #include <ccan/oserver/oserver.c>
+#include <ccan/oserver/oserver_cdump.c>
 #include <ccan/oserver/oserver.h>
 #include <ccan/str/str.h>
 #include <ccan/tap/tap.h>
@@ -19,13 +20,13 @@ static void run_server(int readyfd, int exitfd)
 {
        struct tevent_context *ev = tevent_context_init(NULL);
 
-       if (oserver_setup(ev, OSERVER_PORT) == NULL)
+       if (oserver_setup(ev, OSERVER_PORT, NULL) == NULL)
                exit(1);
 
+       tevent_add_fd(ev, ev, exitfd, TEVENT_FD_READ, exit_quietly, NULL);
        /* Tell parent we are ready to go. */
        write(readyfd, "", 1);
 
-       tevent_add_fd(ev, ev, exitfd, TEVENT_FD_READ, exit_quietly, NULL);
        while (tevent_loop_wait(ev) == 0);
 }      
 
@@ -75,7 +76,7 @@ int main(int argc, char *argv[])
        char c;
 
        /* This is how many tests you plan to run */
-       plan_tests(15);
+       plan_tests(20);
 
        pipe(readyfd);
        pipe(exitfd);
@@ -106,17 +107,31 @@ int main(int argc, char *argv[])
        ok1(input_is(sfd1, "Welcome.  Please ask your question.\n"));
        ok1(input_is(sfd2, "Welcome.  Please ask your question.\n"));
 
-       ok1(write_sall(sfd1, "question"));
-       ok1(write_sall(sfd2, "question"));
-       /* It shouldn't say anything until we've finished! */
+       ok1(write_sall(sfd1, "QUESTION"));
+       ok1(write_sall(sfd2, "QUESTION"));
+       ok1(write_sall(sfd1, " 1\n"));
+
+       /* It can't ask a question yet, since client 2 isn't finished. */
        ok1(no_input(sfd1));
-       ok1(no_input(sfd2));
 
-       ok1(write_sall(sfd1, " 1\n"));
+       /* Make sure that arrives first! */
+       sleep(1);
        ok1(write_sall(sfd2, " 2\n"));
 
-       ok1(input_is(sfd1, "Our answer is:\nQUESTION 1\n"));
-       ok1(input_is(sfd2, "Our answer is:\nQUESTION 2\n"));
+       ok1(input_is(sfd1, "While the Oracle ponders,"
+                    " please answer the following question:\nQUESTION 2\n"));
+       ok1(input_is(sfd2, "While the Oracle ponders,"
+                    " please answer the following question:\nQUESTION 1\n"));
+
+       ok1(write_sall(sfd1, "ANSWER 2\n"));
+       ok1(write_sall(sfd2, "ANSWER 1"));
+
+       /* Nothing, until client 2 answers. */ 
+       ok1(no_input(sfd1));
+       ok1(write_sall(sfd2, "\n"));
+
+       ok1(input_is(sfd1, "The Oracle spake thus:\nANSWER 1\n"));
+       ok1(input_is(sfd2, "The Oracle spake thus:\nANSWER 2\n"));
 
        /* Sockets should be dead now. */
        ok1(read(sfd1, &c, 1) == 0);