Skip to content

Conversation

@ejona86
Copy link
Member

@ejona86 ejona86 commented Aug 27, 2025

It's pretty annoying to see a test failure with
"expected:<DEADLINE_EXCEEDED> but was:<INTERNAL>" and not know the description or throwable cause of the status. Introduce a convenience to include the full status on unexpected Status.Code. There were two usages of assertWithMessage() that did give nice errors; those were converted to this new utility.

It'd be even better to make a StatusSubject, but that'd take more time and this was easy and still an improvement. This was created because we're seeing servlet test failures with INTERNAL code, and we need to see the details.

It's pretty annoying to see a test failure with
"expected:<DEADLINE_EXCEEDED> but was:<INTERNAL>" and not know the
description or throwable cause of the status. Introduce a convenience to
include the full status on unexpected Status.Code. There were two
usages of assertWithMessage() that did give nice errors; those were
converted to this new utility.

It'd be even better to make a StatusSubject, but that'd take more time
and this was easy and still an improvement. This was created because
we're seeing servlet test failures with INTERNAL code, and we need to
see the details.
@panchenko
Copy link
Contributor

Can be a truth extension like the following

@NullMarked
public final class StatusSubject extends Subject {

  private final @Nullable Status actual;

  private StatusSubject(FailureMetadata metadata, @Nullable Status actual) {
    super(metadata, actual);
    this.actual = actual;
  }

  public void hasCode(Code expectedCode) {
    if (actual == null) {
      failWithoutActual(
          fact("expected to have code", expectedCode),
          simpleFact("but was null"));
    } else {
      check("getCode()").that(actual.getCode()).isEqualTo(expectedCode);
    }
  }

  public void hasCodeAndDescription(Code expectedCode, String expectedDescription) {
    if (actual == null) {
      failWithoutActual(
          fact("expected to have code", expectedCode),
          fact("and description", expectedDescription),
          simpleFact("but was null"));
    } else {
      check("getCode()").that(actual.getCode()).isEqualTo(expectedCode);
      check("getDescription()").that(actual.getDescription()).isEqualTo(expectedDescription);
    }
  }

  public static Factory<StatusSubject, Status> statuses() {
    return StatusSubject::new;
  }
}

and then assertAbout(statuses()).that(status).hasCode(Code.INVALID_ARGUMENT)

@ejona86 ejona86 merged commit cdd3202 into grpc:master Aug 28, 2025
15 of 16 checks passed
@ejona86 ejona86 deleted the interop-status-on-failure branch August 28, 2025 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants