Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST requests don't resolve in the browser if the response's status code is 204 #6005

Closed
liwanma opened this issue Mar 3, 2021 · 15 comments
Closed
Assignees
Labels
STATE: Need clarification An issue lacks information for further research.

Comments

@liwanma
Copy link

liwanma commented Mar 3, 2021

What is your Test Scenario?

My project is a React SPA. I'm testing a form consisting of a password field and a submit button. When the submit button is clicked, I wait for a 204 response with an HTTPOnly cookie, then hide the form and show a table. If the cookie is already set when the page is loaded, the form is not shown.

What is the Current behavior?

Currently, the request hangs in the browser. In the network tab in devtools, the status is stuck on PENDING.

I created a custom request hook to see if I am actually getting a response. I am, but the client says the request is still pending.

Also, if I refresh the page while waiting for the request to resolve, the form is no longer shown (as if the request was in fact resolved and the cookie was set).

To further test my suspicions, I changed my API server to return a 200 status code (instead of 204) and the request resolved in the browser as expected.

What is the Expected behavior?

I expected the request to resolve in the browser.

What is your web application and your TestCafe test code?

Your complete test code (or attach your test files):
import { RequestHook, RequestLogger, Selector } from 'testcafe';

export class Hook extends RequestHook {
  constructor(requestFilterRules, responseEventConfigureOpts) {
    super(requestFilterRules, responseEventConfigureOpts);
  }
  async onRequest(event) {}

  async onResponse(event) {
    console.log(event);
  }
}

const hook = new Hook([/https?:\/\/localhost:3051\/api\/verify_password/]);
const logger = RequestLogger();

fixture`Getting Started`;

test.page(`http://localhost:3051`).requestHooks(logger, hook)(
  'Password Form',
  async (t) => {
    const passwordInput = Selector('input[data-testid="textfield-input"]');
    const submitBtn = Selector('button').withText('Submit');

    await t
      .expect(submitBtn.hasAttribute('disabled'))
      .ok()
      .typeText(passwordInput, 'asdf')
      .expect(submitBtn.hasAttribute('disabled'))
      .notOk()
      .click(submitBtn)
      .expect(Selector('table[data-testid="item-table"]').exists)
      .ok();
  },
);
Your complete test report:
 Running tests in:
 - Chrome 88.0.4324.192 / macOS 11.2.1

 Getting Started
 ✖ Password Form

   1) AssertionError: expected false to be truthy
      
      + expected - actual
      
      -false
      +undefined
      

      Browser: Chrome 88.0.4324.192 / macOS 11.2.1

         30 |      .typeText(passwordInput, 'asdf')
         31 |      .expect(submitBtn.hasAttribute('disabled'))
         32 |      .notOk()
         33 |      .click(submitBtn)
         34 |      .expect(Selector('table[data-testid="item-table"]').exists)
       > 35 |      .ok();
         36 |  },
         37 |);

Your Environment details:

  • testcafe version: 1.11.0
  • node.js version: 14.7.0
  • command-line arguments: testcafe chrome -e test.js
  • browser name and version: Chrome 88.0.4324.192
  • platform and version: macOS 11.2.1
  • other:
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 3, 2021
@felis2803 felis2803 added the STATE: Need simple sample A simple sample is required to examine the issue. label Mar 3, 2021
@github-actions
Copy link

github-actions bot commented Mar 3, 2021

Thank you for submitting this issue. We would love to assist you and diagnose it. However, we need a simple sample that we can easily run on our side in order to replicate the issue and research its cause. Without a sample, we are not able to figure out what's going on and why this issue occurs. We look forward to your response.

@github-actions github-actions bot added STATE: Need clarification An issue lacks information for further research. and removed STATE: Need response An issue that requires a response or attention from the team. STATE: Need simple sample A simple sample is required to examine the issue. labels Mar 3, 2021
@liwanma
Copy link
Author

liwanma commented Mar 4, 2021

email sent with sample

@no-response no-response bot removed the STATE: Need clarification An issue lacks information for further research. label Mar 4, 2021
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 4, 2021
@felis2803
Copy link
Contributor

We have received your email. We need some time to research the issue.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 4, 2021
@felis2803
Copy link
Contributor

@liwanma,
Can I add here the link to the repository with the test that you sent by email? This will make it easier for my colleagues to explore the issue.

@liwanma
Copy link
Author

liwanma commented Mar 4, 2021

Can I add here the link to the repository with the test that you sent by email? This will make it easier for my colleagues to explore the issue.

Yes

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 4, 2021
@felis2803
Copy link
Contributor

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 4, 2021
@miherlosev miherlosev added FREQUENCY: level 1 TYPE: bug The described behavior is considered as wrong (bug). labels Mar 11, 2021
@miherlosev miherlosev self-assigned this Dec 20, 2021
@miherlosev miherlosev added STATE: Need clarification An issue lacks information for further research. and removed TYPE: bug The described behavior is considered as wrong (bug). FREQUENCY: level 1 labels Dec 21, 2021
@miherlosev
Copy link
Contributor

Hi @liwanma,

The https://github.com/liwanma/testcafe-6005 repository is not accessible right now. Could you please restore access to it?

@no-response
Copy link

no-response bot commented Dec 31, 2021

This issue was automatically closed because there was no response to our request for more information from the original author. Currently, we don't have enough information to take action. Please reach out to us if you find the necessary information and are able to share it. We are also eager to know if you resolved the issue on your own and can share your findings with everyone.

@no-response no-response bot closed this as completed Dec 31, 2021
@tipy01
Copy link

tipy01 commented Mar 8, 2022

I had the same with a 204 response to a GET that have also a content-length header to 0

what is not recommended in rfc .

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 8, 2022
@VasilyStrelyaev
Copy link
Collaborator

Thank you for the additional information.

Since the original example posted by the issue author is no longer accessible, could you please share an example that reproduces the issue (include the test code and the tested page URL)?

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 9, 2022
@tipy01
Copy link

tipy01 commented Mar 9, 2022

It is a backend issue in my case so I requested change in my backend.
Most people can not share their backend publicly.
Maybe the best thing you can do for this is to display an error in the console to explain what is wrong in the server responses rather than keeping the request in pending state, it would help to debug faster.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 9, 2022
@VasilyStrelyaev
Copy link
Collaborator

I am glad that you were able to modify the backend to work around this issue. Unfortunately, we cannot research this issue further without an example, which we could run on our side to reproduce the problematic behavior.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 10, 2022
@suryap666
Copy link

I have a similar issue.

Front-end: react.
Back-end: Flask API.

Test cafe has an issue with the Delete API call.

Steps to reproduce

  1. Fill a form
  2. Then delete the record, which should return 204 or 202.

After clicking the delete button, I can see the server has completed the delete request but in Chrome, it's not getting resolved while using TestCafe, it's working without the TestCafe server.

Note: I have changed the Delete API to use the 200 status code. It started working.

Delete request headers
image

The difference in header between 204 and 200 was content type and content length.

According to the standards, Content type is not mandatory: https://www.rfc-editor.org/rfc/rfc2616#section-7.2.1

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Jan 19, 2024
@suryap666
Copy link

suryap666 commented Jan 20, 2024

Server Log and Chrome Dev tools
image

Same Test code

test.only('can create and delete category', async () => {
  const categoryName = 'CT_' + randomGenerator.GetRandomNineDigit();
  await categorisationPage.CreateCategory(categoryName, [
    {
      color: LabelColor.Cyan,
      value: 'label_' + randomGenerator.GetRandomNineDigit()
    },
    {
      color: LabelColor.DodgerBlue,
      value: 'label_' + randomGenerator.GetRandomNineDigit()
    }
  ])

  await categorisationPage.DeleteCategory(categoryName);
});

Sample controller code

@controller.route("/categories/<category_id>", methods=["DELETE"])
def delete_categories(category_id):

    {statements}

    response = make_response('', 204) // this was return before test
    response.headers["Content-Type"] = "text/plain" // I added this to test
    response.headers["Content-Length"] = "0" // I add this to test
    return response

Note: we run the application using socket.io (socketio.run(app_name, host=app.config['FLASK_HOST']))

@PavelMor25
Copy link
Collaborator

Hello @suryap666,

Please create a separate ticket using this template.

@PavelMor25 PavelMor25 removed the STATE: Need response An issue that requires a response or attention from the team. label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATE: Need clarification An issue lacks information for further research.
Projects
None yet
Development

No branches or pull requests

7 participants