Exemplo n.º 1
0
void cq_verify(cq_verifier *v) {
  const gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10);
  while (v->first_expectation != NULL) {
    grpc_event ev = grpc_completion_queue_next(v->cq, deadline, NULL);
    if (ev.type == GRPC_QUEUE_TIMEOUT) {
      fail_no_event_received(v);
      break;
    }
    expectation *e;
    expectation *prev = NULL;
    for (e = v->first_expectation; e != NULL; e = e->next) {
      if (e->tag == ev.tag) {
        verify_matches(e, &ev);
        if (e == v->first_expectation) v->first_expectation = e->next;
        if (prev != NULL) prev->next = e->next;
        gpr_free(e);
        break;
      }
      prev = e;
    }
    if (e == NULL) {
      char *s = grpc_event_string(&ev);
      gpr_log(GPR_ERROR, "cq returned unexpected event: %s", s);
      gpr_free(s);
      gpr_strvec expectations;
      gpr_strvec_init(&expectations);
      expectations_to_strvec(&expectations, v);
      s = gpr_strvec_flatten(&expectations, NULL);
      gpr_strvec_destroy(&expectations);
      gpr_log(GPR_ERROR, "expected tags:\n%s", s);
      gpr_free(s);
      abort();
    }
  }
}
Exemplo n.º 2
0
void cq_verify(cq_verifier *v) {
  gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10);
  grpc_event ev;
  expectation *e;
  char *s;
  gpr_strvec have_tags;

  gpr_strvec_init(&have_tags);

  while (v->expect.next != &v->expect) {
    ev = grpc_completion_queue_next(v->cq, deadline, NULL);
    if (ev.type == GRPC_QUEUE_TIMEOUT) {
      fail_no_event_received(v);
      break;
    }

    for (e = v->expect.next; e != &v->expect; e = e->next) {
      gpr_asprintf(&s, " %p", e->tag);
      gpr_strvec_add(&have_tags, s);
      if (e->tag == ev.tag) {
        verify_matches(e, &ev);
        e->next->prev = e->prev;
        e->prev->next = e->next;
        gpr_free(e);
        break;
      }
    }
    if (e == &v->expect) {
      s = grpc_event_string(&ev);
      gpr_log(GPR_ERROR, "event not found: %s", s);
      gpr_free(s);
      s = gpr_strvec_flatten(&have_tags, NULL);
      gpr_log(GPR_ERROR, "have tags:%s", s);
      gpr_free(s);
      gpr_strvec_destroy(&have_tags);
      abort();
    }
  }

  gpr_strvec_destroy(&have_tags);
}