admin管理员组

文章数量:1296465

I have mutation request like this:

public static final String CREATE_DT_MUTATION = """
            mutation($dt: CreateDTInput,$file: Upload!) {
                    createDT(dt: $dt,file: $file) {
                        id
                        dtName
                      }
                }
            """;

and my Test method is like this:

void testBase() throws Exception {
          MockMultipartFile mockFile = new
                MockMultipartFile(
                "file",
                TR181_DT_XML,
                "application/xml",
                getResourceAsString(TR181_DT_XML).getBytes());
        String base64EncodedFile = Base64.getEncoder().encodeToString(mockFile.getBytes());
        
         GraphQlTester.Response response = graphQlTester.document(CREATE_DT_MUTATION)
                .variable("deviceType", buildBaseDT())
                .variable("file", base64EncodedFile)
                .execute();

Upon execute, a huge XML, with lots of parameters get stored on mariadb (container) since it's bit of time taking process. It gives me below error:

 java.lang.IllegalStateException: Timeout on blocking read for 5000000000 NANOSECONDS
    at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:129)
    at reactor.core.publisher.Mono.block(Mono.java:1807)
    at .springframework.test.web.reactive.server.DefaultWebTestClient$DefaultRequestBodyUriSpec.exchange(DefaultWebTestClient.java:369)
    at .springframework.graphql.test.tester.WebTestClientTransport.execute(WebTestClientTransport.java:60)
    at .springframework.graphql.test.tester.DefaultGraphQlTester$DefaultRequest.execute(DefaultGraphQlTester.java:179)

If I crop my XML i.e. make it little smaller file then all my tests run fine without any issues.

I run spring boot 3.4.0 and 1.3.3 version of spring-graphql-test

How can I increase the default timeout for WebTestClient?

Sometimes, not always, I get below error after "Timeout on blocking read" error

2025-02-12 20:06:56,013|INFO |                    |SpringApplicationShutdownHook|.quartz.core.QuartzScheduler|Scheduler quartzScheduler_$_NON_CLUSTERED paused.
2025-02-12 20:06:56,108|WARN |                    |http-nio-auto-1-exec-1|com.zaxxer.hikari.pool.ProxyConnection|HikariPool-1 - Connection .mariadb.jdbc.Connection@3ace955c marked as broken because of SQLSTATE(08000), ErrorCode(-1)
java.sql.SQLNonTransientConnectionException: (conn=6) Socket error
    at .mariadb.jdbc.export.ExceptionFactory.createException(ExceptionFactory.java:300)
    at .mariadb.jdbc.export.ExceptionFactory.create(ExceptionFactory.java:366)
    at .mariadb.jdbc.client.impl.StandardClient.readPacket(StandardClient.java:1259)
    at .mariadb.jdbc.client.impl.StandardClient.readResults(StandardClient.java:1174)
    at .mariadb.jdbc.client.impl.StandardClient.readResponse(StandardClient.java:1093)
    at .mariadb.jdbc.client.impl.StandardClient.execute(StandardClient.java:1017)
    at .mariadb.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:101)
    at .mariadb.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:313)
    at .mariadb.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:290)
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
    at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
    at .hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:194)
    at .hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.performNonBatchedMutation(AbstractMutationExecutor.java:134)
    at .hibernate.engine.jdbc.mutation.internal.MutationExecutorSingleNonBatched.performNonBatchedOperations(MutationExecutorSingleNonBatched.java:55)
    at .hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.execute(AbstractMutationExecutor.java:55)
    at .hibernate.persister.entity.mutation.InsertCoordinatorStandard.doStaticInserts(InsertCoordinatorStandard.java:194)
    at .hibernate.persister.entity.mutation.InsertCoordinatorStandard.coordinateInsert(InsertCoordinatorStandard.java:132)
    at .hibernate.persister.entity.mutation.InsertCoordinatorStandard.insert(InsertCoordinatorStandard.java:104)
    at .hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:110)
    at .hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:644)
    at .hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:511)
    at .hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:414)
    at .hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:41)
    at .hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127)
    at .hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1429)
    at .hibernate.internal.SessionImpl.flush(SessionImpl.java:1415)

I have mutation request like this:

public static final String CREATE_DT_MUTATION = """
            mutation($dt: CreateDTInput,$file: Upload!) {
                    createDT(dt: $dt,file: $file) {
                        id
                        dtName
                      }
                }
            """;

and my Test method is like this:

void testBase() throws Exception {
          MockMultipartFile mockFile = new
                MockMultipartFile(
                "file",
                TR181_DT_XML,
                "application/xml",
                getResourceAsString(TR181_DT_XML).getBytes());
        String base64EncodedFile = Base64.getEncoder().encodeToString(mockFile.getBytes());
        
         GraphQlTester.Response response = graphQlTester.document(CREATE_DT_MUTATION)
                .variable("deviceType", buildBaseDT())
                .variable("file", base64EncodedFile)
                .execute();

Upon execute, a huge XML, with lots of parameters get stored on mariadb (container) since it's bit of time taking process. It gives me below error:

 java.lang.IllegalStateException: Timeout on blocking read for 5000000000 NANOSECONDS
    at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:129)
    at reactor.core.publisher.Mono.block(Mono.java:1807)
    at .springframework.test.web.reactive.server.DefaultWebTestClient$DefaultRequestBodyUriSpec.exchange(DefaultWebTestClient.java:369)
    at .springframework.graphql.test.tester.WebTestClientTransport.execute(WebTestClientTransport.java:60)
    at .springframework.graphql.test.tester.DefaultGraphQlTester$DefaultRequest.execute(DefaultGraphQlTester.java:179)

If I crop my XML i.e. make it little smaller file then all my tests run fine without any issues.

I run spring boot 3.4.0 and 1.3.3 version of spring-graphql-test

How can I increase the default timeout for WebTestClient?

Sometimes, not always, I get below error after "Timeout on blocking read" error

2025-02-12 20:06:56,013|INFO |                    |SpringApplicationShutdownHook|.quartz.core.QuartzScheduler|Scheduler quartzScheduler_$_NON_CLUSTERED paused.
2025-02-12 20:06:56,108|WARN |                    |http-nio-auto-1-exec-1|com.zaxxer.hikari.pool.ProxyConnection|HikariPool-1 - Connection .mariadb.jdbc.Connection@3ace955c marked as broken because of SQLSTATE(08000), ErrorCode(-1)
java.sql.SQLNonTransientConnectionException: (conn=6) Socket error
    at .mariadb.jdbc.export.ExceptionFactory.createException(ExceptionFactory.java:300)
    at .mariadb.jdbc.export.ExceptionFactory.create(ExceptionFactory.java:366)
    at .mariadb.jdbc.client.impl.StandardClient.readPacket(StandardClient.java:1259)
    at .mariadb.jdbc.client.impl.StandardClient.readResults(StandardClient.java:1174)
    at .mariadb.jdbc.client.impl.StandardClient.readResponse(StandardClient.java:1093)
    at .mariadb.jdbc.client.impl.StandardClient.execute(StandardClient.java:1017)
    at .mariadb.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:101)
    at .mariadb.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:313)
    at .mariadb.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:290)
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
    at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
    at .hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:194)
    at .hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.performNonBatchedMutation(AbstractMutationExecutor.java:134)
    at .hibernate.engine.jdbc.mutation.internal.MutationExecutorSingleNonBatched.performNonBatchedOperations(MutationExecutorSingleNonBatched.java:55)
    at .hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.execute(AbstractMutationExecutor.java:55)
    at .hibernate.persister.entity.mutation.InsertCoordinatorStandard.doStaticInserts(InsertCoordinatorStandard.java:194)
    at .hibernate.persister.entity.mutation.InsertCoordinatorStandard.coordinateInsert(InsertCoordinatorStandard.java:132)
    at .hibernate.persister.entity.mutation.InsertCoordinatorStandard.insert(InsertCoordinatorStandard.java:104)
    at .hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:110)
    at .hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:644)
    at .hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:511)
    at .hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:414)
    at .hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:41)
    at .hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127)
    at .hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1429)
    at .hibernate.internal.SessionImpl.flush(SessionImpl.java:1415)
Share Improve this question edited Feb 12 at 14:43 user3300534 asked Feb 12 at 13:25 user3300534user3300534 13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can configure this on the GraphQlTester builder directly, or mutate an existing tester like so:

GraphQlTester newGraphQlTester = existingGraphQlTester.mutate()
          .responseTimeout(Duration.ofSeconds(10))
          .build();

Edit:

I have just tested this behavior successfully with the following controller:

import .springframework.graphql.data.method.annotation.QueryMapping;
import .springframework.stereotype.Controller;

@Controller
public class GreetingController {

    @QueryMapping
    public String greeting() throws InterruptedException {
        Thread.sleep(10000);
        return "Hello World!";
    }
}

and this test:

package .example.timeout;

import java.time.Duration;
import .junit.jupiter.api.Test;

import .springframework.beans.factory.annotation.Autowired;
import .springframework.boot.test.autoconfigure.graphql.GraphQlTest;
import .springframework.graphql.test.tester.GraphQlTester;

@GraphQlTest(GreetingController.class)
public class TimeoutTests {

    @Autowired
    private GraphQlTester graphQlTester;

    @Test
    void shouldWaitLongerThanTenSeconds() {
        GraphQlTester tester = this.graphQlTester.mutate()
                .responseTimeout(Duration.ofSeconds(12)).build();
        tester.document("{greeting}").execute()
                .path("greeting").entity(String.class).isEqualTo("Hello World!");
    }

}

And here are the logs as requested:

16:43:18.598 [Test worker] INFO .springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [.example.timeout.TimeoutTests]: TimeoutTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
16:43:18.653 [Test worker] INFO .springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration .example.timeout.TimeoutApplication for test class .example.timeout.TimeoutTests

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.4.2)

2025-02-12T16:43:18.812+01:00  INFO 78502 --- [timeout] [    Test worker] .example.timeout.TimeoutTests         : Starting TimeoutTests using Java 17.0.14 with PID 78502
2025-02-12T16:43:18.812+01:00  INFO 78502 --- [timeout] [    Test worker] .example.timeout.TimeoutTests         : No active profile set, falling back to 1 default profile: "default"
2025-02-12T16:43:19.021+01:00  INFO 78502 --- [timeout] [    Test worker] efaultSchemaResourceGraphQlSourceBuilder : Loaded 1 resource(s) in the GraphQL schema.
2025-02-12T16:43:19.121+01:00  INFO 78502 --- [timeout] [    Test worker] o.s.b.a.g.GraphQlAutoConfiguration       : GraphQL schema inspection:
    Unmapped fields: {}
    Unmapped registrations: {}
    Unmapped arguments: {}
    Skipped types: []
2025-02-12T16:43:19.157+01:00  INFO 78502 --- [timeout] [    Test worker] .example.timeout.TimeoutTests         : Started TimeoutTests in 0.47 seconds (process running for 0.903)
2025-02-12T16:43:29.605+01:00  INFO 78502 --- [timeout] [    Test worker] .example.timeout.TimeoutTests         : Test is done

本文标签: Can I increase a timeout on spring GraphQlTester executeStack Overflow