Add a delay option to load-tester socket

This commit is contained in:
Martin Willi
2012-11-29 10:22:51 +01:00
parent cf85f6b296
commit fdd94fc846
2 changed files with 11 additions and 7 deletions
@@ -61,7 +61,7 @@ static FILE* make_connection()
/**
* Initiate load-tests
*/
static int initiate(unsigned int count)
static int initiate(unsigned int count, unsigned int delay)
{
FILE *stream;
char c;
@@ -72,7 +72,7 @@ static int initiate(unsigned int count)
return 1;
}
fprintf(stream, "%u\n", count);
fprintf(stream, "%u %u\n", count, delay);
while (1)
{
@@ -94,11 +94,11 @@ static int initiate(unsigned int count)
int main(int argc, char *argv[])
{
if (argc == 3 && strcmp(argv[1], "initiate") == 0)
if (argc >= 3 && strcmp(argv[1], "initiate") == 0)
{
return initiate(atoi(argv[2]));
return initiate(atoi(argv[2]), argc > 3 ? atoi(argv[3]) : 0);
}
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s initiate <count>\n", argv[0]);
fprintf(stderr, " %s initiate <count> [<delay in ms>]\n", argv[0]);
return 1;
}
@@ -223,7 +223,7 @@ static job_requeue_t initiate(FILE *stream)
enumerator_t *enumerator;
peer_cfg_t *peer_cfg;
child_cfg_t *child_cfg;
u_int i, count, failed = 0;
u_int i, count, failed = 0, delay = 0;
char buf[16] = "";
fflush(stream);
@@ -231,7 +231,7 @@ static job_requeue_t initiate(FILE *stream)
{
return JOB_REQUEUE_NONE;
}
if (sscanf(buf, "%u", &count) != 1)
if (sscanf(buf, "%u %u", &count, &delay) < 1)
{
return JOB_REQUEUE_NONE;
}
@@ -285,6 +285,10 @@ static job_requeue_t initiate(FILE *stream)
fprintf(stream, "!");
break;
}
if (delay)
{
usleep(delay * 1000);
}
fflush(stream);
}