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

ClientFunction not working for returning large object/array #1110

Closed
thecodejack opened this issue Jan 4, 2017 · 8 comments
Closed

ClientFunction not working for returning large object/array #1110

thecodejack opened this issue Jan 4, 2017 · 8 comments
Labels
AREA: client STATE: Auto-locked An issue has been automatically locked by the Lock bot. SYSTEM: API TYPE: bug The described behavior is considered as wrong (bug).
Milestone

Comments

@thecodejack
Copy link

thecodejack commented Jan 4, 2017

Are you requesting a feature or reporting a bug?

Bug

What is the current behavior?

TestCafe keeps waiting at ClientFunction when returning object/array which is very large for following code.

const getFirstGridTotalRows = ClientFunction(() => {
    return window.gridRef[0].filteredRows();
});
const gridData = await getFirstGridTotalRows();

gridData is expected to have around 99k objects in an array. But while running tests, tests are not going forward. It is not even throwing any error. it just waits.

What is the expected behavior?

Should either throw error of memory limit or return the data.

How would you reproduce the current behavior (if this is a bug)?

Take any very large dataset and return it from application url through ClientFunction.

Provide the test code and the tested page URL (if applicable)

Tested page URL:

Test code

const getFirstGridTotalRows = ClientFunction(() => {
    return window.gridRef[0].filteredRows();
});
const gridData = await getFirstGridTotalRows();

Specify your

  • operating system: Windows 7
  • testcafe version: 0.11.1
  • node.js version: 6.9.1
@AlexanderMoskovkin
Copy link
Contributor

Hi, thanks for the report. We need some time to investigate it.

@inikulin
Copy link
Contributor

inikulin commented Jan 9, 2017

Hi @thecodejack,

I've tried to reproduce the issue on my side using the following code:
index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    window.rows = [];

    for (var i = 0; i < 100000; i++)
        window.rows.push({ name: 'row' + i, payload: 'Hey42' });
</script>
</body>
</html>

test.js

import { ClientFunction } from 'testcafe';

fixture `gh1110`
    .page `http://localhost:8080`;

const getRows = ClientFunction(() => window.rows);

test('Count rows', async t => {
    const rows = await getRows();

    await t.expect(rows.length).eql(100000);
});

While test run took some noticeable time, it's completed successfully. Is there something what I'm missing?

@thecodejack
Copy link
Author

This makes it failing in my PC:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    window.rows = [];

    for (var i = 0; i < 100000; i++) {
        var obj = {};
        for (var j=0; j< 100; j++) {
            obj['Super'+ j] = 'Check if object loaded' + j;
        }
        rows.push(obj);
    }
        
</script>
</body>
</html>

@inikulin
Copy link
Contributor

I was able to reproduce the issue. The cause of the problem is that browser runs out of memory when we try to serialize enormously large object. I guess the best option here will be a limit for the returned object size, let's just throw an error with some descriptive message.

@inikulin inikulin added AREA: client SYSTEM: API TYPE: bug The described behavior is considered as wrong (bug). labels Jan 10, 2017
@AlexanderMoskovkin AlexanderMoskovkin self-assigned this Jan 10, 2017
@AlexanderMoskovkin AlexanderMoskovkin added this to the Sprint #4 milestone Jan 23, 2017
@inikulin inikulin modified the milestones: Planned features, Sprint #5, Sprint #6 Mar 15, 2017
@AndreyBelym
Copy link
Contributor

Closing this issue in favor of #2618.

@dlangerenken
Copy link

@AndreyBelym is there another way for returning very large objects? #2618 is not sufficient since I need to transfer objects of that size. I do code-coverage analysis using istanbul-instrumenter. The coverage is logged in window.coverage and I need to access this after a successful test-run.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Feb 16, 2019
@dlangerenken
Copy link

dlangerenken commented Feb 16, 2019

Since I can stringify my object, I wrote a helper function that checks the size first, and then I call multiple times into the browser and copy the data I need:

const maximumObjectSize = 1024 * 1024 * 4.0; // 4 mb - to be sure
export const codeCoverageSize = ClientFunction(() => {
  const json = JSON.stringify((window as any).__coverage__);
  (window as any).__coverage_json__ = json;
  return json.length;
});

export const codeCoverage = ClientFunction((start: number, end: number) => {
  return (window as any).__coverage_json__.substring(start, end);
});

export const collectCodeCoverage = async (fileName = randomNotebookTag()) => {
  const size = await codeCoverageSize();
  const splits = Math.ceil(size / maximumObjectSize);
  let coverageJson = '';
  for (let i = 0; i < splits; i++) {
    const start = i * maximumObjectSize;
    coverageJson += await codeCoverage(start, start + maximumObjectSize);
  }
  console.log(coverageJson);
};

@miherlosev miherlosev removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 6, 2019
@lock
Copy link

lock bot commented Mar 27, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests. For TestCafe API, usage and configuration inquiries, we recommend asking them on StackOverflow.

@lock lock bot added the STATE: Auto-locked An issue has been automatically locked by the Lock bot. label Mar 27, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
AREA: client STATE: Auto-locked An issue has been automatically locked by the Lock bot. SYSTEM: API TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

6 participants