GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: fix test-sync-io-option by evanlucas · Pull Request #1840 · nodejs/node

test: fix test-sync-io-option #1840

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.

Sign up for GitHub

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

Merged
evanlucas merged 1 commit into nodejs:master from evanlucas:fix-sync-io-test
Jun 3, 2015

Uh oh!

There was an error while loading. Please reload this page.

Merged

test: fix test-sync-io-option #1840

Changes from all commits
Commits
Show all changes
1 commit
Select commit
43a82f8
test: fix test-sync-io-option
evanlucas May 29, 2015
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
test: fix test-sync-io-option
This test was failing occasionally both locally and on CI. Switched
from using spawn to execFile for a more reliable test.

Fixes: #1837
PR-URL: #1840
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas
evanlucas committed Jun 3, 2015
commit 43a82f8a718a91ede0a360ee2c4078e01befcd2b

There are no files selected for viewing

40 changes: 14 additions & 26 deletions 40 test/parallel/test-sync-io-option.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

const assert = require('assert');
const spawn = require('child_process').spawn;

const execFile = require('child_process').execFile;

if (process.argv[2] === 'child') {
setImmediate(function() {
Expand All @@ -14,34 +13,23 @@ if (process.argv[2] === 'child') {
(function runTest(flags) {
var execArgv = [flags.pop()];
var args = [__filename, 'child'];
var child = spawn(process.execPath, execArgv.concat(args));
var stderr = '';

child.stdout.on('data', function(chunk) {
throw new Error('UNREACHABLE');
});

child.stderr.on('data', function(chunk) {
stderr += chunk.toString();
});

child.on('close', function() {
var cntr1 = (stderr.match(/WARNING/g) || []).length;
var cntr2 = (stderr.match(/fs\.readFileSync/g) || []).length;
assert.equal(cntr1, cntr2);
if (execArgv[0] === '--trace-sync-io') {
// Prints 4 WARNINGS for --trace-sync-io. 1 for each sync call
// inside readFileSync
assert.equal(cntr1, 4);
} else if (execArgv[0] === ' ') {
assert.equal(cntr1, 0);
var cntr = 0;
args = execArgv.concat(args);
if (!args[0]) args.shift();
execFile(process.execPath, args, function(err, stdout, stderr) {
assert.equal(err, null);
assert.equal(stdout, '');
if (/^WARNING[\s\S]*fs\.readFileSync/.test(stderr))
cntr++;
if (args[0] === '--trace-sync-io') {
assert.equal(cntr, 1);
Comment thread

@silverwind silverwind Jun 3, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this change from 4 to 1 warning?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@evanlucas evanlucas Jun 3, 2015

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It changed because we only get stderr in the callback one time for each call. Previously it was in a data event which was emit more than once.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
} else if (args[0] === __filename) {
assert.equal(cntr, 0);
} else {
throw new Error('UNREACHABLE');
}

if (flags.length > 0)
setImmediate(runTest, flags);
});
}(['--trace-sync-io', ' ']));
}(['--trace-sync-io', '']));
Comment thread

@benjamingr benjamingr Jun 2, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this flags game and IIFE required?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@trevnorris trevnorris Jun 2, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I wrote it I wanted each run to have it's own running context. So I kept most variables local to the IIFE so there wouldn't be any accidental interference. Just a technique to help write more reliable tests.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
}

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.