Sha256: b5cd5fc108412f9ab1167a139f7f95ea133a3fe59922b20d96535944b027b38c

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

#include "ev_dispatch.h"
#include "ev_http.h"

using namespace EVD;


// catch SIGINT to kill process 
static void  SIGINT_handler(int sig)
{
  exit(sig);
}

static int run_test(Dispatch& dispatcher)
{
  if( !dispatcher.start() ){
    fprintf( stderr, "Failed to start up dispatcher\n" );
    return 1;
  }

  printf( "dispatcher thread running...\n" );
  std::vector<request_t> ids;
  int TRIALS = 100;

  for( int i = 0; i < TRIALS; ++i ) {
    request_t id;
    if( i % 2 ) {
      id = dispatcher.request( new HttpRequest( dispatcher, "http://127.0.0.1:4044/bytes/1000" ) );
    }
    else {
      id = dispatcher.request( new HttpRequest( dispatcher, "http://127.0.0.1:4044/bytes/10" ) );
    }
    ids.push_back( id );
  }
  Response *res;
  for( int i = 0; i < ids.size(); ++i ) {
    request_t id = ids[i];
    while( dispatcher.wait_for_response_by_id( id, Timer(1,5) ) ){
      printf("waiting for %d...\n", i);
    } 
    res = dispatcher.response_for( id );
    if( res ) {
      printf("Recieved response from 2: %s, Content-Length: %d\n", res->name.c_str(), res->body.length() );
      delete res;
    }
  }
  dispatcher.stop();
  return 0;
}

int main(int argc, char **argv)
{
  Dispatch dispatcher;
  if (signal(SIGINT, SIGINT_handler) == SIG_ERR) {
    printf("SIGINT install error\n");
    return 1;
  }
  for( int i = 0; i < 10; ++i ) {
    run_test(dispatcher);
  }

  return 0;
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
evdispatch-0.3.0 ext/revdispatch/libdispatch-0.1/test/stress_test.cc
evdispatch-0.2.6 ext/revdispatch/libdispatch-0.1/test/stress_test.cc
evdispatch-0.3.1 ext/revdispatch/libdispatch-0.1/test/stress_test.cc