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

cy.writeFile timesout but also runs writeFile beyond the timeout. #3350

Closed
SDESkowronski opened this issue Feb 6, 2019 · 12 comments · Fixed by #19015
Closed

cy.writeFile timesout but also runs writeFile beyond the timeout. #3350

SDESkowronski opened this issue Feb 6, 2019 · 12 comments · Fixed by #19015
Assignees
Labels
good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory pkg/server This is due to an issue in the packages/server directory type: bug type: enhancement Requested enhancement of existing feature

Comments

@SDESkowronski
Copy link

SDESkowronski commented Feb 6, 2019

Current behavior:

The documentation says it is technically possible for cy.writeFile to timeout but it shouldn't, however, it did for me today. I know it was the cy.writeFile that timedout because it is the only cy.Command in my aftereach hook.

The Error Output:

  20) EditAndBranching
       "after each" hook for "Tag And Frog":
     Error: Cypress command timeout of '4000ms' exceeded.

Because this error occurred during a 'after each' hook we are skipping all of the remaining tests.
      at http://localhost:5050/__cypress/runner/cypress_runner.js:66264:25

Desired behavior:

I think Cypress should provide a way to override the timeout or fix it so it can't timeout.

I also think Cypress should not stop running the remaining tests when one fails in the aftereach hook. That is a harsh punishment for an intermittent failure. In fact that also is a good case for not failing all tests in the aftereach since one failure does not necessarily mean they all will fail. Perhaps this needs a rethink as well.

Steps to reproduce: (app code and test code)

"Issues without reproducible steps will get closed." -- How am I supposed to give you code to reproduce this? Do I have to write some OS hook to intercept the writeFile command and make it take longer than 4 seconds?

Sorry but I don't have the time to work up some sort of repro steps...this requirement on obvious flaws is an impedance to filing a bug. I've reported the bug, if you all want to just close and do nothing then so be it.

Versions

Cypress package version: 3.0.3
Cypress binary version: 3.0.3
OS Name: Microsoft Windows 10 Enterprise
OS Version: 10.0.17763 Build 17763
Browser: Electron 59 (headless)

@jennifer-shehane
Copy link
Member

Was able to reproduce from code below:

it('writes until timeout', () => {
  cy.writeFile('./fixtures/my-long-file.txt', Cypress._.times(900000, '😈'))
})

screen shot 2019-02-07 at 5 16 04 pm

This write:file event actually seems to run forever:
screen shot 2019-02-07 at 5 11 20 pm

The writeFile code can be found here:

https://github.com/cypress-io/cypress/blob/renovate/develop/packages/driver/src/cy/commands/files.coffee#L66

@jennifer-shehane jennifer-shehane added type: unexpected behavior User expected result, but got another type: enhancement Requested enhancement of existing feature stage: ready for work The issue is reproducible and in scope pkg/driver This is due to an issue in the packages/driver directory pkg/server This is due to an issue in the packages/server directory good first issue Good for newcomers and removed type: unexpected behavior User expected result, but got another labels Feb 7, 2019
@SDESkowronski
Copy link
Author

Thanks Jennifer, I'm glad you were able to come up with repro steps.

@JoshMcAloone
Copy link

Hi @jennifer-shehane do you know if this issue was ever fixed or is planned to be fixed? We are facing a lot of random timeouts with cy.writeFile when running tests on Azure build agents. The timeout occurs in the before all or after all hook and the remaining tests all fail.

@lisophorm
Copy link

lisophorm commented Apr 15, 2020

Hi,
I am having the same issue and this is becoming a major blocker. Is this going to be solved? @jennifer-shehane

@JoshMcAloone
Copy link

JoshMcAloone commented Apr 15, 2020

Hi,
I am having the same issue and this is becoming a major blocker. Is this going to be solved? @jennifer-shehane

@lisophorm I found a workaround for this issue which I thought I would share in case it helps.

I stopped using cy.writeFile and instead used fs.writeFileSync.

Firstly I added a task in index.js like:

const fs = require('fs');

module.exports = (on, config) => {
  on('task', {
    writeFile({ filename, data }) {
      fs.writeFileSync(filename, data);
      return null;
    }
  })
}

Then in my before/after all hooks in the cypress tests I now just use the following to write to the files:

cy.task('writeFile', { filename: <some filename>, data: <some data> });

This works well and the cypress tests are stable and run very consistently on Azure build agents. Hope this helps whilst we wait for this issue to be fixed.

@jennifer-shehane jennifer-shehane added stage: ready for work The issue is reproducible and in scope and removed stage: backlog labels Apr 23, 2020
@amitguptagwl
Copy link

Any update on this?

@amitguptagwl
Copy link

I tried like this and it worked for me

it('writes until timeout', () => {
  cy.then( () => cy.writeFile('./fixtures/my-long-file.txt', Cypress._.times(900000, '😈')) );
})

@jennifer-shehane
Copy link
Member

This issue is still open, so no work has been done on it. We are welcome to PRs to fix the issue.

@jennifer-shehane jennifer-shehane changed the title cy.writeFile Does Timeout cy.writeFile timesout but also runs writeFile beyond the timeout. Aug 27, 2021
@cypress-bot cypress-bot bot added stage: backlog and removed stage: ready for work The issue is reproducible and in scope labels Oct 15, 2021
@mjhenkes
Copy link
Member

A couple of notes here:

To recreate this issue I added an extra zero to @jennifer-shehane 's test to recreate the issue.

it('writes until timeout', () => {
  cy.writeFile('./fixtures/my-long-file.txt', Cypress._.times(9000000, '😈'))
})

The websocket request the server to write files1 times out after 4000 MS, but the actual fs writeFile operation that is kicked off in the server is never canceled2. This actually seems to lead to some unresponsiveness in the cypress app ui.

Fix Proposal:

  • Update cy.writeFile to have a configurable timeout option that would apply to both the websocket and the write operation in the server.
  • Update the server to read and honor the timeout. There is an option3 to do with with the abortController but it's only available experimentally in node 14, so there is some digging to do there.

Footnotes

  1. https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/files.ts#L127

  2. https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/files.js#L29

  3. https://nodejs.org/docs/latest-v14.x/api/fs.html#fs_fs_writefile_file_data_options_callback

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: product review and removed stage: work in progress stage: needs review The PR code is done & tested, needs review labels Nov 19, 2021
@tbiethman
Copy link
Contributor

tbiethman commented Nov 23, 2021

Summarizing the plan of action here:

  1. We will be introducing a timeout option to readFile/writeFile commands and setting a sensible default (larger than the default timeout of 4 seconds). The default of 4s remains for now to maximize passivity
  2. We will introduce better error handling for scenarios where large reads/writes were silently failing and causing the reporter to hang (as shown in the investigations above). We will also investigate increasing our internal transmission limits to mitigate this further.
  3. Failures within afterEach and other hooks are expected to fail the tests within that context; if the setup/teardown has failed in some way, it is hard to ensure the validity of subsequent test executions. We will not be making changes to this behavior with this work. However, as far as writeFile is concerned, the changes we are making should significantly reduce the amount of failures occurring due to large file sizes.

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: work in progress and removed stage: product review stage: needs review The PR code is done & tested, needs review labels Nov 24, 2021
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: needs review The PR code is done & tested, needs review stage: work in progress labels Nov 30, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 6, 2021

The code for this is done in cypress-io/cypress#19015, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Dec 6, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 21, 2021

Released in 9.2.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v9.2.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Dec 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory pkg/server This is due to an issue in the packages/server directory type: bug type: enhancement Requested enhancement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants