Added "unique" test ids for message validation
This commit is contained in:
parent
2e769153fe
commit
c41b8a34f0
43
tests/test.c
43
tests/test.c
|
@ -35,7 +35,7 @@
|
|||
|
||||
|
||||
int test_level = 2;
|
||||
int test_seed;
|
||||
int test_seed = 0;
|
||||
|
||||
static void sig_alarm (int sig) {
|
||||
TEST_FAIL("Test timed out");
|
||||
|
@ -46,6 +46,24 @@ static void test_error_cb (rd_kafka_t *rk, int err,
|
|||
TEST_FAIL("rdkafka error: %s: %s", rd_kafka_err2str(err), reason);
|
||||
}
|
||||
|
||||
static void test_init (void) {
|
||||
int seed;
|
||||
char *tmp;
|
||||
|
||||
if (test_seed)
|
||||
return;
|
||||
|
||||
if ((tmp = getenv("TEST_LEVEL")))
|
||||
test_level = atoi(tmp);
|
||||
if ((tmp = getenv("TEST_SEED")))
|
||||
seed = atoi(tmp);
|
||||
else
|
||||
seed = test_clock() & 0xffffffff;
|
||||
|
||||
srand(seed);
|
||||
test_seed = seed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and sets up kafka configuration objects.
|
||||
|
@ -58,23 +76,13 @@ void test_conf_init (rd_kafka_conf_t **conf, rd_kafka_topic_conf_t **topic_conf,
|
|||
int line = 0;
|
||||
const char *test_conf = getenv("RDKAFKA_TEST_CONF") ? : "test.conf";
|
||||
char errstr[512];
|
||||
char *tmp;
|
||||
int seed;
|
||||
|
||||
test_init();
|
||||
|
||||
/* Limit the test run time. */
|
||||
alarm(timeout);
|
||||
signal(SIGALRM, sig_alarm);
|
||||
|
||||
if ((tmp = getenv("TEST_LEVEL")))
|
||||
test_level = atoi(tmp);
|
||||
if ((tmp = getenv("TEST_SEED")))
|
||||
seed = atoi(tmp);
|
||||
else
|
||||
seed = test_clock() & 0xffffffff;
|
||||
|
||||
srand(seed);
|
||||
test_seed = seed;
|
||||
|
||||
*conf = rd_kafka_conf_new();
|
||||
*topic_conf = rd_kafka_topic_conf_new();
|
||||
|
||||
|
@ -147,3 +155,12 @@ void test_wait_exit (int timeout) {
|
|||
TEST_FAIL("%i thread(s) still active in librdkafka", r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a "unique" test id.
|
||||
*/
|
||||
uint64_t test_id_generate (void) {
|
||||
test_init();
|
||||
return (((uint64_t)rand()) << 32) | (uint64_t)rand();
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ void test_conf_init (rd_kafka_conf_t **conf, rd_kafka_topic_conf_t **topic_conf,
|
|||
|
||||
void test_wait_exit (int timeout);
|
||||
|
||||
uint64_t test_id_generate (void);
|
||||
|
||||
|
||||
/**
|
||||
* A microsecond monotonic clock
|
||||
|
|
Loading…
Reference in New Issue