37 #include <sys/types.h>
39 #ifdef HAVE_SYS_TIME_H
42 #include <sys/queue.h>
44 #include <sys/socket.h>
61 #include "regress.gen.h"
68 http_setup(
short *pport)
75 for (i = 0; i < 50; ++
i) {
84 event_errx(1,
"Could not start web server");
96 static int need_input_hook = 0;
97 static int need_output_hook = 0;
102 struct kill* kill_reply = rpc->reply;
104 if (need_input_hook) {
106 const char *header = evhttp_find_header(
107 req->input_headers,
"X-Hook");
108 assert(strcmp(header,
"input") == 0);
112 EVTAG_ASSIGN(kill_reply, weapon,
"dagger");
113 EVTAG_ASSIGN(kill_reply, action,
"wave around like an idiot");
132 struct evhttp *http = NULL;
135 http = http_setup(&port);
136 base = evrpc_init(http);
146 need_output_hook = 0;
161 if (req->response_code != HTTP_SERVUNAVAIL) {
163 fprintf(stderr,
"FAILED (response code)\n");
168 event_loopexit(NULL);
179 struct evhttp *http = NULL;
184 fprintf(stdout,
"Testing Basic RPC Support: ");
186 rpc_setup(&http, &port, &base);
190 fprintf(stdout,
"FAILED\n");
201 fprintf(stdout,
"FAILED\n");
206 evhttp_add_header(req->output_headers,
"Host",
"somehost");
207 evbuffer_add_printf(req->output_buffer,
"Some Nonsense");
211 "/.rpc.Message") == -1) {
212 fprintf(stdout,
"FAILED\n");
225 fprintf(stdout,
"FAILED\n");
229 fprintf(stdout,
"OK\n");
237 struct kill* kill_reply = NULL;
239 if (req->response_code != HTTP_OK) {
241 fprintf(stderr,
"FAILED (response code)\n");
245 kill_reply = kill_new();
247 if ((kill_unmarshal(kill_reply, req->input_buffer)) == -1) {
248 fprintf(stderr,
"FAILED (unmarshal)\n");
252 kill_free(kill_reply);
255 event_loopexit(NULL);
259 rpc_basic_message(
void)
262 struct evhttp *http = NULL;
268 fprintf(stdout,
"Testing Good RPC Post: ");
270 rpc_setup(&http, &port, &base);
274 fprintf(stdout,
"FAILED\n");
285 fprintf(stdout,
"FAILED\n");
290 evhttp_add_header(req->output_headers,
"Host",
"somehost");
294 EVTAG_ASSIGN(msg, from_name,
"niels");
295 EVTAG_ASSIGN(msg, to_name,
"tester");
296 msg_marshal(req->output_buffer, msg);
301 "/.rpc.Message") == -1) {
302 fprintf(stdout,
"FAILED\n");
315 fprintf(stdout,
"FAILED\n");
319 fprintf(stdout,
"OK\n");
325 rpc_pool_with_connection(
short port)
330 pool = evrpc_pool_new(NULL);
331 assert(pool != NULL);
334 assert(evcon != NULL);
336 evrpc_pool_add_connection(pool, evcon);
343 struct msg *msg,
struct kill *
kill,
void *arg)
348 if (need_output_hook) {
350 const char *header = evhttp_find_header(
351 req->input_headers,
"X-Pool-Hook");
352 assert(strcmp(header,
"ran") == 0);
355 if (status->error != EVRPC_STATUS_ERR_NONE)
358 if (EVTAG_GET(kill, weapon, &weapon) == -1) {
359 fprintf(stderr,
"get weapon\n");
362 if (EVTAG_GET(kill, action, &action) == -1) {
363 fprintf(stderr,
"get action\n");
367 if (strcmp(weapon,
"dagger"))
370 if (strcmp(action,
"wave around like an idiot"))
376 event_loopexit(NULL);
381 struct msg *msg,
struct kill *kill,
void *arg)
386 if (status->error != EVRPC_STATUS_ERR_NONE)
389 if (EVTAG_GET(kill, weapon, &weapon) == -1) {
390 fprintf(stderr,
"get weapon\n");
393 if (EVTAG_GET(kill, action, &action) == -1) {
394 fprintf(stderr,
"get action\n");
398 if (strcmp(weapon,
"dagger"))
401 if (strcmp(action,
"wave around like an idiot"))
408 event_loopexit(NULL);
415 const char *hook_type = arg;
416 if (strcmp(
"input", hook_type) == 0)
417 evhttp_add_header(req->input_headers,
"X-Hook", hook_type);
419 evhttp_add_header(req->output_headers,
"X-Hook", hook_type);
427 const char *header = evhttp_find_header(req->input_headers,
"X-Hook");
428 assert(header != NULL);
429 assert(strcmp(header, arg) == 0);
430 evhttp_remove_header(req->input_headers,
"X-Hook");
431 evhttp_add_header(req->input_headers,
"X-Pool-Hook",
"ran");
437 rpc_basic_client(
void)
440 struct evhttp *http = NULL;
446 fprintf(stdout,
"Testing RPC Client: ");
448 rpc_setup(&http, &port, &base);
451 need_output_hook = 1;
453 assert(evrpc_add_hook(base,
EVRPC_INPUT, rpc_hook_add_header, (
void*)
"input")
455 assert(evrpc_add_hook(base,
EVRPC_OUTPUT, rpc_hook_add_header, (
void*)
"output")
458 pool = rpc_pool_with_connection(port);
460 assert(evrpc_add_hook(pool,
EVRPC_INPUT, rpc_hook_remove_header, (
void*)
"output"));
464 EVTAG_ASSIGN(msg, from_name,
"niels");
465 EVTAG_ASSIGN(msg, to_name,
"tester");
476 fprintf(stdout,
"FAILED (1)\n");
490 fprintf(stdout,
"FAILED (2)\n");
494 fprintf(stdout,
"OK\n");
499 evrpc_pool_free(pool);
508 rpc_basic_queued_client(
void)
511 struct evhttp *http = NULL;
515 struct kill *kill_one, *kill_two;
517 fprintf(stdout,
"Testing RPC (Queued) Client: ");
519 rpc_setup(&http, &port, &base);
521 pool = rpc_pool_with_connection(port);
525 EVTAG_ASSIGN(msg, from_name,
"niels");
526 EVTAG_ASSIGN(msg, to_name,
"tester");
528 kill_one = kill_new();
529 kill_two = kill_new();
541 fprintf(stdout,
"FAILED (1)\n");
545 fprintf(stdout,
"OK\n");
551 evrpc_pool_free(pool);
557 struct msg *msg,
struct kill *kill,
void *arg)
559 if (status->error != EVRPC_STATUS_ERR_TIMEOUT)
563 if (kill_complete(kill) == 0)
569 event_loopexit(NULL);
573 rpc_client_timeout(
void)
576 struct evhttp *http = NULL;
582 fprintf(stdout,
"Testing RPC Client Timeout: ");
584 rpc_setup(&http, &port, &base);
586 pool = rpc_pool_with_connection(port);
589 evrpc_pool_set_timeout(pool, 5);
593 EVTAG_ASSIGN(msg, from_name,
"niels");
594 EVTAG_ASSIGN(msg, to_name,
"tester");
610 fprintf(stdout,
"FAILED (1)\n");
614 fprintf(stdout,
"OK\n");
619 evrpc_pool_free(pool);
629 rpc_basic_queued_client();
630 rpc_client_timeout();