]> git.ozlabs.org Git - ccan-lca-2011.git/blobdiff - ccan/oserver/test/run.c
lca2011: make our server parrot the last answer it got.
[ccan-lca-2011.git] / ccan / oserver / test / run.c
index f99e40bde103e57d511fd4830d916b24115e548a..e553f3d6a75494ba1ceb882899190c17e1ecc11f 100644 (file)
@@ -22,10 +22,10 @@ static void run_server(int readyfd, int exitfd)
        if (oserver_setup(ev, OSERVER_PORT) == 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 +75,7 @@ int main(int argc, char *argv[])
        char c;
 
        /* This is how many tests you plan to run */
-       plan_tests(13);
+       plan_tests(15);
 
        pipe(readyfd);
        pipe(exitfd);
@@ -103,6 +103,9 @@ int main(int argc, char *argv[])
        ok1(connect(sfd1, &u.addr, sizeof(u.in)) == 0);
        ok1(connect(sfd2, &u.addr, sizeof(u.in)) == 0);
 
+       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! */
@@ -110,10 +113,12 @@ int main(int argc, char *argv[])
        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, "QUESTION 1\n"));
-       ok1(input_is(sfd2, "QUESTION 2\n"));
+       ok1(input_is(sfd1, "I believe a better question is how many manly men mendaciously mention mending mansions?\n"));
+       ok1(input_is(sfd2, "I believe a better question is question 1\n"));
 
        /* Sockets should be dead now. */
        ok1(read(sfd1, &c, 1) == 0);