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

Optimize NUnit file check by reading only initial portion of file to find <test-run tag #288

Open
GabLeRoux opened this issue Nov 11, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@GabLeRoux
Copy link
Member

To enhance performance in the CI workflow, we propose optimizing the NUnit XML file check in results-check.ts by reading only the initial 4KB of each file when verifying the presence of the <test-run> tag. This change will reduce unnecessary I/O operations on large files and prevent processing of non-NUnit XML files in the artifacts directory. This improvement is particularly useful for projects with large test suites that produce sizeable XML files, as it minimizes memory usage and enhances CI performance.

For more details, refer to the discussion on the GitHub pull request here.

Proposed Code Change

Replace the current full-file read logic with the following snippet to implement the optimization:

try {
  const filePath = path.join(artifactsPath, filepath);
  const fd = fs.openSync(filePath, 'r');
  const bufferSize = 4096; // Read the first 4KB
  const buffer = Buffer.alloc(bufferSize);
  const bytesRead = fs.readSync(fd, buffer, 0, bufferSize, 0);
  fs.closeSync(fd);

  const contentStart = buffer.toString('utf8', 0, bytesRead);
  if (!contentStart.includes('<test-run')) {
    core.warning(`File does not appear to be a NUnit XML file: ${filepath}`);
    return;
  }

  const fileData = await ResultsParser.parseResults(filePath);
  core.info(fileData.summary);
  runs.push(fileData);
} catch (error: any) {
  core.warning(`Failed to parse ${filepath}: ${error.message}`);
}

Benefits

  • Performance Boost: Minimizes I/O operations and memory usage by only reading a small portion of each file.
  • Improved Efficiency: Enhances processing speed for large projects with extensive XML test results.
  • Streamlined Workflow: Reduces CI workflow interruptions by logging warnings for non-NUnit files instead of failing the entire run.

This improvement streamlines error handling and increases the resilience of file parsing in CI environments, benefiting large-scale Unity projects.

@GabLeRoux GabLeRoux changed the title Optimize NUnit File Check by Reading Only Initial Portion for <test-run Tag Optimize NUnit File Check by Reading Only Initial Portion of file to find <test-run Tag Nov 11, 2024
@GabLeRoux GabLeRoux changed the title Optimize NUnit File Check by Reading Only Initial Portion of file to find <test-run Tag Optimize NUnit file check by reading only initial portion of file to find <test-run tag Nov 11, 2024
@GabLeRoux GabLeRoux added enhancement New feature or request good first issue Good for newcomers labels Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant