示例#1
0
static void test_unused_reclaim_is_cancelled(void) {
  gpr_log(GPR_INFO, "** test_unused_reclaim_is_cancelled **");
  grpc_resource_quota *q =
      grpc_resource_quota_create("test_unused_reclaim_is_cancelled");
  grpc_resource_quota_resize(q, 1024);
  grpc_resource_user usr;
  grpc_resource_user_init(&usr, q, "usr");
  bool benign_done = false;
  bool destructive_done = false;
  {
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_post_reclaimer(
        &exec_ctx, &usr, false, make_unused_reclaimer(set_bool(&benign_done)));
    grpc_resource_user_post_reclaimer(
        &exec_ctx, &usr, true,
        make_unused_reclaimer(set_bool(&destructive_done)));
    grpc_exec_ctx_finish(&exec_ctx);
    GPR_ASSERT(!benign_done);
    GPR_ASSERT(!destructive_done);
  }
  grpc_resource_quota_unref(q);
  destroy_user(&usr);
  GPR_ASSERT(benign_done);
  GPR_ASSERT(destructive_done);
}
示例#2
0
static void test_multiple_reclaims_can_be_triggered(void) {
  gpr_log(GPR_INFO, "** test_multiple_reclaims_can_be_triggered **");
  grpc_resource_quota *q =
      grpc_resource_quota_create("test_multiple_reclaims_can_be_triggered");
  grpc_resource_quota_resize(q, 1024);
  grpc_resource_user usr;
  grpc_resource_user_init(&usr, q, "usr");
  bool benign_done = false;
  bool destructive_done = false;
  {
    bool done = false;
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done));
    grpc_exec_ctx_finish(&exec_ctx);
    GPR_ASSERT(done);
  }
  {
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_post_reclaimer(
        &exec_ctx, &usr, false,
        make_reclaimer(&usr, 512, set_bool(&benign_done)));
    grpc_resource_user_post_reclaimer(
        &exec_ctx, &usr, true,
        make_reclaimer(&usr, 512, set_bool(&destructive_done)));
    grpc_exec_ctx_finish(&exec_ctx);
    GPR_ASSERT(!benign_done);
    GPR_ASSERT(!destructive_done);
  }
  {
    bool done = false;
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&done));
    grpc_exec_ctx_finish(&exec_ctx);
    GPR_ASSERT(benign_done);
    GPR_ASSERT(destructive_done);
    GPR_ASSERT(done);
  }
  {
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_free(&exec_ctx, &usr, 1024);
    grpc_exec_ctx_finish(&exec_ctx);
  }
  grpc_resource_quota_unref(q);
  destroy_user(&usr);
  GPR_ASSERT(benign_done);
  GPR_ASSERT(destructive_done);
}
示例#3
0
static void
test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_released(
    void) {
  gpr_log(GPR_INFO,
          "** "
          "test_resource_user_stays_allocated_and_reclaimers_unrun_until_"
          "memory_released **");
  grpc_resource_quota *q = grpc_resource_quota_create(
      "test_resource_user_stays_allocated_and_reclaimers_unrun_until_memory_"
      "released");
  grpc_resource_quota_resize(q, 1024);
  for (int i = 0; i < 10; i++) {
    grpc_resource_user usr;
    grpc_resource_user_init(&usr, q, "usr");
    bool done = false;
    bool reclaimer_cancelled = false;
    {
      grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
      grpc_resource_user_post_reclaimer(
          &exec_ctx, &usr, false,
          make_unused_reclaimer(set_bool(&reclaimer_cancelled)));
      grpc_exec_ctx_finish(&exec_ctx);
      GPR_ASSERT(!reclaimer_cancelled);
    }
    {
      bool allocated = false;
      grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
      grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&allocated));
      grpc_exec_ctx_finish(&exec_ctx);
      GPR_ASSERT(allocated);
      GPR_ASSERT(!reclaimer_cancelled);
    }
    {
      grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
      grpc_resource_user_shutdown(&exec_ctx, &usr, set_bool(&done));
      grpc_exec_ctx_finish(&exec_ctx);
      GPR_ASSERT(!done);
      GPR_ASSERT(!reclaimer_cancelled);
    }
    {
      grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
      grpc_resource_user_free(&exec_ctx, &usr, 1024);
      grpc_exec_ctx_finish(&exec_ctx);
      GPR_ASSERT(done);
      GPR_ASSERT(reclaimer_cancelled);
    }
    {
      grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
      grpc_resource_user_destroy(&exec_ctx, &usr);
      grpc_exec_ctx_finish(&exec_ctx);
    }
  }
  grpc_resource_quota_unref(q);
}
示例#4
0
static void test_reclaimers_can_be_posted_repeatedly(void) {
  gpr_log(GPR_INFO, "** test_reclaimers_can_be_posted_repeatedly **");
  grpc_resource_quota *q =
      grpc_resource_quota_create("test_reclaimers_can_be_posted_repeatedly");
  grpc_resource_quota_resize(q, 1024);
  grpc_resource_user usr;
  grpc_resource_user_init(&usr, q, "usr");
  {
    bool allocated = false;
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&allocated));
    grpc_exec_ctx_finish(&exec_ctx);
    GPR_ASSERT(allocated);
  }
  for (int i = 0; i < 10; i++) {
    bool reclaimer_done = false;
    {
      grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
      grpc_resource_user_post_reclaimer(
          &exec_ctx, &usr, false,
          make_reclaimer(&usr, 1024, set_bool(&reclaimer_done)));
      grpc_exec_ctx_finish(&exec_ctx);
      GPR_ASSERT(!reclaimer_done);
    }
    {
      bool allocated = false;
      grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
      grpc_resource_user_alloc(&exec_ctx, &usr, 1024, set_bool(&allocated));
      grpc_exec_ctx_finish(&exec_ctx);
      GPR_ASSERT(allocated);
      GPR_ASSERT(reclaimer_done);
    }
  }
  {
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_free(&exec_ctx, &usr, 1024);
    grpc_exec_ctx_finish(&exec_ctx);
  }
  destroy_user(&usr);
  grpc_resource_quota_unref(q);
}
示例#5
0
static void test_blocked_until_scheduled_reclaim_and_scavenge(void) {
  gpr_log(GPR_INFO, "** test_blocked_until_scheduled_reclaim_and_scavenge **");
  grpc_resource_quota *q = grpc_resource_quota_create(
      "test_blocked_until_scheduled_reclaim_and_scavenge");
  grpc_resource_quota_resize(q, 1024);
  grpc_resource_user usr1;
  grpc_resource_user usr2;
  grpc_resource_user_init(&usr1, q, "usr1");
  grpc_resource_user_init(&usr2, q, "usr2");
  {
    bool done = false;
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_alloc(&exec_ctx, &usr1, 1024, set_bool(&done));
    grpc_exec_ctx_finish(&exec_ctx);
    GPR_ASSERT(done);
  }
  bool reclaim_done = false;
  {
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_post_reclaimer(
        &exec_ctx, &usr1, false,
        make_reclaimer(&usr1, 1024, set_bool(&reclaim_done)));
    grpc_exec_ctx_finish(&exec_ctx);
  }
  {
    bool done = false;
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_alloc(&exec_ctx, &usr2, 1024, set_bool(&done));
    grpc_exec_ctx_finish(&exec_ctx);
    GPR_ASSERT(reclaim_done);
    GPR_ASSERT(done);
  }
  {
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_free(&exec_ctx, &usr2, 1024);
    grpc_exec_ctx_finish(&exec_ctx);
  }
  grpc_resource_quota_unref(q);
  destroy_user(&usr1);
  destroy_user(&usr2);
}
示例#6
0
static void test_blocked_until_scheduled_destructive_reclaim(void) {
  gpr_log(GPR_INFO, "** test_blocked_until_scheduled_destructive_reclaim **");
  grpc_resource_quota *q = grpc_resource_quota_create(
      "test_blocked_until_scheduled_destructive_reclaim");
  grpc_resource_quota_resize(q, 1024);
  grpc_resource_user *usr = grpc_resource_user_create(q, "usr");
  {
    bool done = false;
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done));
    grpc_exec_ctx_finish(&exec_ctx);
    GPR_ASSERT(done);
  }
  bool reclaim_done = false;
  {
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_post_reclaimer(
        &exec_ctx, usr, true,
        make_reclaimer(usr, 1024, set_bool(&reclaim_done)));
    grpc_exec_ctx_finish(&exec_ctx);
  }
  {
    bool done = false;
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_alloc(&exec_ctx, usr, 1024, set_bool(&done));
    grpc_exec_ctx_finish(&exec_ctx);
    GPR_ASSERT(reclaim_done);
    GPR_ASSERT(done);
  }
  {
    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
    grpc_resource_user_free(&exec_ctx, usr, 1024);
    grpc_exec_ctx_finish(&exec_ctx);
  }
  grpc_resource_quota_unref(q);
  destroy_user(usr);
}