Skip to content

Make dead Spock conditions in execution and directive tests run - #4565

Open
costajohnt wants to merge 1 commit into
graphql-java:masterfrom
costajohnt:fix-dead-spock-conditions
Open

costajohnt wants to merge 1 commit into
graphql-java:masterfrom
costajohnt:fix-dead-spock-conditions

Conversation

@costajohnt

Copy link
Copy Markdown

Several Spock checks in these tests were never evaluated as conditions, so they could not fail. Spock only asserts top-level expressions in then:/expect:; a comparison inside if/else is evaluated and discarded, and !x instanceof Y parses as (!x) instanceof Y, which is always false.

  • ExecutionStrategyTest (non-null scalar feature): the whole then: was an if/else, so it asserted nothing. Made live, all three rows failed, because the test passed the nullable type instead of the non-null typeInfo it built, completeValue reports the error through the field value future rather than throwing, and the no-error row expected an exception. The test now uses typeInfo, joins the future, and asserts the exception and error count against errorExpected.
  • SubscriptionExecutionStrategyTest: message.data == null was inside a closure. The actual payload is [newMessage: null] (newMessage is nullable, so the null bubbles up to it), which is now asserted.
  • DeferWithDataLoaderTest: the batch loader counter checks were inside if/else; they now use assert and pass in all three rows.
  • ValueTraverserTest, SchemaGeneratorDirectiveHelperTest: !x instanceof GraphQLObjectType becomes !(x instanceof GraphQLObjectType).

Test-only change. The five classes pass locally (151 tests). Found while testing a Groovy linter on the repo.

Spock only treats top-level expressions in then:/expect: blocks as
conditions. Checks nested in if/else or for loops were evaluated and
discarded, and "!x instanceof GraphQLObjectType" parses as
"(!x) instanceof GraphQLObjectType", which is always false.

- ExecutionStrategyTest: the non-null scalar feature asserted nothing.
  Once the checks ran, every row failed: the parameters used the nullable
  field type instead of the non-null typeInfo the test builds, and
  completeValue reports the NonNullableFieldWasNullException through the
  field value future rather than throwing it. The no-error row also
  expected an exception. Use typeInfo, unwrap the future and assert
  the exception and error count for each row.
- SubscriptionExecutionStrategyTest: the null-propagation event has
  data [newMessage: null] (newMessage is nullable), not null. Assert it.
- DeferWithDataLoaderTest: assert the batch loader call counts.
- ValueTraverserTest, SchemaGeneratorDirectiveHelperTest: fix the
  always-false instanceof guards.

This branch has not been deployed

No deployments
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.

1 participant