question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Runing http call in parallel and can't receive all, Action timeout exception

See original GitHub issue

Citrus Version 2.7.6

Question How to properly setup parallel test action that makes http calls and validate responses ?

What I’ve tried so far

parallel().actions(
        sendAction(),
        sendAction(),
        ...
        sendAction()
);
parallel().actions(
        receiveAction(),
        receiveAction(),
        ...
        receiveAction()
);

And even tried as below:

parallel().actions(
    sequential.actions(
        sendAction(),
        receiveAction()
    ),
    ...
    sequential.actions(
        sendAction(),
        receiveAction()
    )
);

where sendAction() is simply as below:

return http(x -> x.client(httpClient)
    .send()
    .post()
    .contentType(ContentType.APPLICATION_XML.getMimeType())
    .header("Authorization", "Basic citrus:encodeBase64('${user}:${pass}')")
    .payload(...)

receiveAction() is:

return http(x -> x.client(httpClient)
    .receive()
    .response(HttpStatus.OK)
    .validationCallback((m, c) -> {
        System.out.println(m.getPayload(String.class));
    }));

Additional information Unfortunately, it failed with timeout exception usually at 2nd or 3rd receiveAction() method call.

com.consol.citrus.exceptions.TestCaseFailedException: Action timeout while receiving synchronous reply message from http server

Running in synchronous way as below is working totally fine. But we need to run those calls in parallel.

sendAction();
receiveAction();
...
sendAction();
receiveAction();

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
svettwercommented, Sep 4, 2018

Hi!

I knew there was a better way to solve this but I couldn’t remember instantaneously.

public class TodoListIT extends TestNGCitrusTestRunner {

    @Autowired
    private HttpClient httpClient;

    @Test
    @CitrusTest
    public void testPost() {

        final String request1 = "request1";
        final String request2 = "request2";
        final String request3 = "request3";

        parallel().actions(
                sendAction(request1),
                sendAction(request2),
                sendAction(request3));
        parallel().actions(
                receiveAction(request1),
                receiveAction(request2),
                receiveAction(request3));
    }

    public TestAction sendAction(final String requestVariable){
       return http(x -> x.client(httpClient)
                .send()
                .get()
                .extractFromHeader("citrus_message_id", requestVariable));
    }

    public TestAction receiveAction(final String requestVariable){
       return http(x -> x.client(httpClient)
                .receive()
                .response(HttpStatus.OK)
                .selector(Collections.singletonMap("citrus_message_id", "${" + requestVariable +"}"))
                .validationCallback((m, c) -> {
                    System.out.println(m.getPayload(String.class));
                }));
    }
}

You could apply selectors to identify the messages by their citrus_message_id. This is still a manual mapping. I’ll open an enhancement issue so that citrus is able to handle those situations out of the box.

BR, Sven

0reactions
svettwercommented, Sep 4, 2018

Hi!

Unfortunately I can’t provide a schedule for #459 currently but it’s good to hear that the suggested solution worked for you as well.

BR, Sven

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Parallel executing NodeJS request causes timeout
You are setting an agressive timeout, so it makes sense that the requests are timing out. The longer I made the timeout, the...
Read more >
9. Cancellation and Timeouts - Parallel and Concurrent ...
The ThreadId is a value returned by a previous call to forkIO , and may refer to a thread in any state: running,...
Read more >
Handle HTTP request failures in Power Automate
Take actions based on HTTP status code:​​ The quick way to do this is get the HTTP status code of the HTTP request...
Read more >
How to avoid the timeout error in Rest API request
Solved: Hi All, When i am running the Rest API its getting below error, but its working fine in the Postman. Please help...
Read more >
Hi All,parallely i am sending the say some 10 requests to ...
you are getting the time out issue, because the server not able to responded the given time, so your HTTP Requester as Client...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found