Fixing test (not yet complete)

reviewable/pr11119/r1
Craig Tiller 8 years ago
parent 2d485f0396
commit 55a8213041
  1. 320
      test/core/iomgr/resource_quota_test.c

@ -43,11 +43,11 @@ static void inc_int_cb(grpc_exec_ctx *exec_ctx, void *a, grpc_error *error) {
++*(int *)a; ++*(int *)a;
} }
static void set_bool_cb(grpc_exec_ctx *exec_ctx, void *a, grpc_error *error) { static void set_event_cb(grpc_exec_ctx *exec_ctx, void *a, grpc_error *error) {
*(bool *)a = true; gpr_event_set((gpr_event *)a, (void *)1);
} }
grpc_closure *set_bool(bool *p) { grpc_closure *set_event(gpr_event *ev) {
return grpc_closure_create(set_bool_cb, p, grpc_schedule_on_exec_ctx); return grpc_closure_create(set_event_cb, ev, grpc_schedule_on_exec_ctx);
} }
typedef struct { typedef struct {
@ -154,11 +154,13 @@ static void test_simple_async_alloc(void) {
grpc_resource_quota_resize(q, 1024 * 1024); grpc_resource_quota_resize(q, 1024 * 1024);
grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); grpc_resource_user *usr = grpc_resource_user_create(q, "usr");
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@ -175,15 +177,18 @@ static void test_async_alloc_blocked_by_size(void) {
grpc_resource_quota_create("test_async_alloc_blocked_by_size"); grpc_resource_quota_create("test_async_alloc_blocked_by_size");
grpc_resource_quota_resize(q, 1); grpc_resource_quota_resize(q, 1);
grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); grpc_resource_user *usr = grpc_resource_user_create(q, "usr");
bool done = false; gpr_event ev;
gpr_event_init(&ev);
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(!done); GPR_ASSERT(gpr_event_wait(
&ev, grpc_timeout_milliseconds_to_deadline(100)) == NULL);
} }
grpc_resource_quota_resize(q, 1024); grpc_resource_quota_resize(q, 1024);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) != NULL);
;
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_resource_user_free(&exec_ctx, usr, 1024);
@ -200,11 +205,14 @@ static void test_scavenge(void) {
grpc_resource_user *usr1 = grpc_resource_user_create(q, "usr1"); grpc_resource_user *usr1 = grpc_resource_user_create(q, "usr1");
grpc_resource_user *usr2 = grpc_resource_user_create(q, "usr2"); grpc_resource_user *usr2 = grpc_resource_user_create(q, "usr2");
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@ -212,11 +220,14 @@ static void test_scavenge(void) {
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
} }
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@ -234,26 +245,31 @@ static void test_scavenge_blocked(void) {
grpc_resource_quota_resize(q, 1024); grpc_resource_quota_resize(q, 1024);
grpc_resource_user *usr1 = grpc_resource_user_create(q, "usr1"); grpc_resource_user *usr1 = grpc_resource_user_create(q, "usr1");
grpc_resource_user *usr2 = grpc_resource_user_create(q, "usr2"); grpc_resource_user *usr2 = grpc_resource_user_create(q, "usr2");
bool done; gpr_event ev;
{ {
done = false; gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
{ {
done = false; gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(!done); GPR_ASSERT(gpr_event_wait(
&ev, grpc_timeout_milliseconds_to_deadline(100)) == NULL);
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_free(&exec_ctx, usr1, 1024); grpc_resource_user_free(&exec_ctx, usr1, 1024);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@ -272,27 +288,35 @@ static void test_blocked_until_scheduled_reclaim(void) {
grpc_resource_quota_resize(q, 1024); grpc_resource_quota_resize(q, 1024);
grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); grpc_resource_user *usr = grpc_resource_user_create(q, "usr");
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
bool reclaim_done = false; gpr_event reclaim_done;
gpr_event_init(&reclaim_done);
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_post_reclaimer( grpc_resource_user_post_reclaimer(
&exec_ctx, usr, false, &exec_ctx, usr, false,
make_reclaimer(usr, 1024, set_bool(&reclaim_done))); make_reclaimer(usr, 1024, set_event(&reclaim_done)));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
} }
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(reclaim_done); GPR_ASSERT(gpr_event_wait(&reclaim_done,
GPR_ASSERT(done); grpc_timeout_seconds_to_deadline(5)) != NULL);
GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@ -311,27 +335,35 @@ static void test_blocked_until_scheduled_reclaim_and_scavenge(void) {
grpc_resource_user *usr1 = grpc_resource_user_create(q, "usr1"); grpc_resource_user *usr1 = grpc_resource_user_create(q, "usr1");
grpc_resource_user *usr2 = grpc_resource_user_create(q, "usr2"); grpc_resource_user *usr2 = grpc_resource_user_create(q, "usr2");
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr1, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
bool reclaim_done = false; gpr_event reclaim_done;
gpr_event_init(&reclaim_done);
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_post_reclaimer( grpc_resource_user_post_reclaimer(
&exec_ctx, usr1, false, &exec_ctx, usr1, false,
make_reclaimer(usr1, 1024, set_bool(&reclaim_done))); make_reclaimer(usr1, 1024, set_event(&reclaim_done)));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
} }
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr2, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(reclaim_done); GPR_ASSERT(gpr_event_wait(&reclaim_done,
GPR_ASSERT(done); grpc_timeout_seconds_to_deadline(5)) != NULL);
GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@ -350,27 +382,35 @@ static void test_blocked_until_scheduled_destructive_reclaim(void) {
grpc_resource_quota_resize(q, 1024); grpc_resource_quota_resize(q, 1024);
grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); grpc_resource_user *usr = grpc_resource_user_create(q, "usr");
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
bool reclaim_done = false; gpr_event reclaim_done;
gpr_event_init(&reclaim_done);
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_post_reclaimer( grpc_resource_user_post_reclaimer(
&exec_ctx, usr, true, &exec_ctx, usr, true,
make_reclaimer(usr, 1024, set_bool(&reclaim_done))); make_reclaimer(usr, 1024, set_event(&reclaim_done)));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
} }
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(reclaim_done); GPR_ASSERT(gpr_event_wait(&reclaim_done,
GPR_ASSERT(done); grpc_timeout_seconds_to_deadline(5)) != NULL);
GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@ -387,23 +427,31 @@ static void test_unused_reclaim_is_cancelled(void) {
grpc_resource_quota_create("test_unused_reclaim_is_cancelled"); grpc_resource_quota_create("test_unused_reclaim_is_cancelled");
grpc_resource_quota_resize(q, 1024); grpc_resource_quota_resize(q, 1024);
grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); grpc_resource_user *usr = grpc_resource_user_create(q, "usr");
bool benign_done = false; gpr_event benign_done;
bool destructive_done = false; gpr_event_init(&benign_done);
gpr_event destructive_done;
gpr_event_init(&destructive_done);
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_post_reclaimer( grpc_resource_user_post_reclaimer(
&exec_ctx, usr, false, make_unused_reclaimer(set_bool(&benign_done))); &exec_ctx, usr, false, make_unused_reclaimer(set_event(&benign_done)));
grpc_resource_user_post_reclaimer( grpc_resource_user_post_reclaimer(
&exec_ctx, usr, true, &exec_ctx, usr, true,
make_unused_reclaimer(set_bool(&destructive_done))); make_unused_reclaimer(set_event(&destructive_done)));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(!benign_done); GPR_ASSERT(gpr_event_wait(&benign_done,
GPR_ASSERT(!destructive_done); grpc_timeout_milliseconds_to_deadline(100)) ==
NULL);
GPR_ASSERT(gpr_event_wait(&destructive_done,
grpc_timeout_milliseconds_to_deadline(100)) ==
NULL);
} }
grpc_resource_quota_unref(q); grpc_resource_quota_unref(q);
destroy_user(usr); destroy_user(usr);
GPR_ASSERT(benign_done); GPR_ASSERT(gpr_event_wait(&benign_done,
GPR_ASSERT(destructive_done); grpc_timeout_seconds_to_deadline(5)) != NULL);
GPR_ASSERT(gpr_event_wait(&destructive_done,
grpc_timeout_seconds_to_deadline(5)) != NULL);
} }
static void test_benign_reclaim_is_preferred(void) { static void test_benign_reclaim_is_preferred(void) {
@ -412,35 +460,49 @@ static void test_benign_reclaim_is_preferred(void) {
grpc_resource_quota_create("test_benign_reclaim_is_preferred"); grpc_resource_quota_create("test_benign_reclaim_is_preferred");
grpc_resource_quota_resize(q, 1024); grpc_resource_quota_resize(q, 1024);
grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); grpc_resource_user *usr = grpc_resource_user_create(q, "usr");
bool benign_done = false; gpr_event benign_done;
bool destructive_done = false; gpr_event_init(&benign_done);
gpr_event destructive_done;
gpr_event_init(&destructive_done);
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_post_reclaimer( grpc_resource_user_post_reclaimer(
&exec_ctx, usr, false, &exec_ctx, usr, false,
make_reclaimer(usr, 1024, set_bool(&benign_done))); make_reclaimer(usr, 1024, set_event(&benign_done)));
grpc_resource_user_post_reclaimer( grpc_resource_user_post_reclaimer(
&exec_ctx, usr, true, &exec_ctx, usr, true,
make_unused_reclaimer(set_bool(&destructive_done))); make_unused_reclaimer(set_event(&destructive_done)));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(!benign_done); GPR_ASSERT(gpr_event_wait(&benign_done,
GPR_ASSERT(!destructive_done); grpc_timeout_milliseconds_to_deadline(100)) ==
NULL);
GPR_ASSERT(gpr_event_wait(&destructive_done,
grpc_timeout_milliseconds_to_deadline(100)) ==
NULL);
} }
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(benign_done); GPR_ASSERT(gpr_event_wait(&benign_done,
GPR_ASSERT(!destructive_done); grpc_timeout_seconds_to_deadline(5)) != NULL);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&destructive_done,
grpc_timeout_milliseconds_to_deadline(100)) ==
NULL);
GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@ -449,8 +511,10 @@ static void test_benign_reclaim_is_preferred(void) {
} }
grpc_resource_quota_unref(q); grpc_resource_quota_unref(q);
destroy_user(usr); destroy_user(usr);
GPR_ASSERT(benign_done); GPR_ASSERT(gpr_event_wait(&benign_done,
GPR_ASSERT(destructive_done); grpc_timeout_seconds_to_deadline(5)) != NULL);
GPR_ASSERT(gpr_event_wait(&destructive_done,
grpc_timeout_seconds_to_deadline(5)) != NULL);
} }
static void test_multiple_reclaims_can_be_triggered(void) { static void test_multiple_reclaims_can_be_triggered(void) {
@ -459,35 +523,49 @@ static void test_multiple_reclaims_can_be_triggered(void) {
grpc_resource_quota_create("test_multiple_reclaims_can_be_triggered"); grpc_resource_quota_create("test_multiple_reclaims_can_be_triggered");
grpc_resource_quota_resize(q, 1024); grpc_resource_quota_resize(q, 1024);
grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); grpc_resource_user *usr = grpc_resource_user_create(q, "usr");
bool benign_done = false; gpr_event benign_done;
bool destructive_done = false; gpr_event_init(&benign_done);
gpr_event destructive_done;
gpr_event_init(&destructive_done);
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_post_reclaimer( grpc_resource_user_post_reclaimer(
&exec_ctx, usr, false, &exec_ctx, usr, false,
make_reclaimer(usr, 512, set_bool(&benign_done))); make_reclaimer(usr, 512, set_event(&benign_done)));
grpc_resource_user_post_reclaimer( grpc_resource_user_post_reclaimer(
&exec_ctx, usr, true, &exec_ctx, usr, true,
make_reclaimer(usr, 512, set_bool(&destructive_done))); make_reclaimer(usr, 512, set_event(&destructive_done)));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(!benign_done); GPR_ASSERT(gpr_event_wait(&benign_done,
GPR_ASSERT(!destructive_done); grpc_timeout_milliseconds_to_deadline(100)) ==
NULL);
GPR_ASSERT(gpr_event_wait(&destructive_done,
grpc_timeout_milliseconds_to_deadline(100)) ==
NULL);
} }
{ {
bool done = false; gpr_event ev;
gpr_event_init(&ev);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&ev));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(benign_done); GPR_ASSERT(gpr_event_wait(&benign_done,
GPR_ASSERT(destructive_done); grpc_timeout_seconds_to_deadline(5)) != NULL);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&destructive_done,
grpc_timeout_seconds_to_deadline(5)) != NULL);
GPR_ASSERT(gpr_event_wait(&ev, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
;
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@ -496,8 +574,10 @@ static void test_multiple_reclaims_can_be_triggered(void) {
} }
grpc_resource_quota_unref(q); grpc_resource_quota_unref(q);
destroy_user(usr); destroy_user(usr);
GPR_ASSERT(benign_done); GPR_ASSERT(gpr_event_wait(&benign_done,
GPR_ASSERT(destructive_done); grpc_timeout_seconds_to_deadline(5)) != NULL);
GPR_ASSERT(gpr_event_wait(&destructive_done,
grpc_timeout_seconds_to_deadline(5)) != NULL);
} }
static void test_resource_user_stays_allocated_until_memory_released(void) { static void test_resource_user_stays_allocated_until_memory_released(void) {
@ -538,34 +618,44 @@ test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released(
grpc_resource_quota_resize(q, 1024); grpc_resource_quota_resize(q, 1024);
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); grpc_resource_user *usr = grpc_resource_user_create(q, "usr");
bool reclaimer_cancelled = false; gpr_event reclaimer_cancelled;
gpr_event_init(&reclaimer_cancelled);
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_post_reclaimer( grpc_resource_user_post_reclaimer(
&exec_ctx, usr, false, &exec_ctx, usr, false,
make_unused_reclaimer(set_bool(&reclaimer_cancelled))); make_unused_reclaimer(set_event(&reclaimer_cancelled)));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(!reclaimer_cancelled); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled,
grpc_timeout_milliseconds_to_deadline(100)) ==
NULL);
} }
{ {
bool allocated = false; gpr_event allocated;
gpr_event_init(&allocated);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&allocated)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&allocated));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(allocated); GPR_ASSERT(gpr_event_wait(&allocated,
GPR_ASSERT(!reclaimer_cancelled); grpc_timeout_seconds_to_deadline(5)) != NULL);
GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled,
grpc_timeout_milliseconds_to_deadline(100)) ==
NULL);
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_unref(&exec_ctx, usr); grpc_resource_user_unref(&exec_ctx, usr);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(!reclaimer_cancelled); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled,
grpc_timeout_milliseconds_to_deadline(100)) ==
NULL);
} }
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_free(&exec_ctx, usr, 1024); grpc_resource_user_free(&exec_ctx, usr, 1024);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(reclaimer_cancelled); GPR_ASSERT(gpr_event_wait(&reclaimer_cancelled,
grpc_timeout_seconds_to_deadline(5)) != NULL);
} }
} }
grpc_resource_quota_unref(q); grpc_resource_quota_unref(q);
@ -578,29 +668,37 @@ static void test_reclaimers_can_be_posted_repeatedly(void) {
grpc_resource_quota_resize(q, 1024); grpc_resource_quota_resize(q, 1024);
grpc_resource_user *usr = grpc_resource_user_create(q, "usr"); grpc_resource_user *usr = grpc_resource_user_create(q, "usr");
{ {
bool allocated = false; gpr_event allocated;
gpr_event_init(&allocated);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&allocated)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&allocated));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(allocated); GPR_ASSERT(gpr_event_wait(&allocated,
grpc_timeout_seconds_to_deadline(5)) != NULL);
} }
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
bool reclaimer_done = false; gpr_event reclaimer_done;
gpr_event_init(&reclaimer_done);
{ {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_post_reclaimer( grpc_resource_user_post_reclaimer(
&exec_ctx, usr, false, &exec_ctx, usr, false,
make_reclaimer(usr, 1024, set_bool(&reclaimer_done))); make_reclaimer(usr, 1024, set_event(&reclaimer_done)));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(!reclaimer_done); GPR_ASSERT(gpr_event_wait(&reclaimer_done,
grpc_timeout_milliseconds_to_deadline(100)) ==
NULL);
} }
{ {
bool allocated = false; gpr_event allocated;
gpr_event_init(&allocated);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&allocated)); grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_event(&allocated));
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(allocated); GPR_ASSERT(gpr_event_wait(&allocated,
GPR_ASSERT(reclaimer_done); grpc_timeout_seconds_to_deadline(5)) != NULL);
GPR_ASSERT(gpr_event_wait(&reclaimer_done,
grpc_timeout_seconds_to_deadline(5)) != NULL);
} }
} }
{ {

Loading…
Cancel
Save