summaryrefslogtreecommitdiff
path: root/test/parallel/test-sync-io-option.js
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2015-05-14 11:46:54 -0600
committerTrevor Norris <trev.norris@gmail.com>2015-05-18 10:05:32 -0600
commitc1de6d249e9b17d53edc0a713c1e43ef9b457ea7 (patch)
treefba50f35b3a2266d52eb70cce48fcd7ac0eaf7cf /test/parallel/test-sync-io-option.js
parent066274794c077c9323109f95ff0efe53e17d323a (diff)
downloadandroid-node-v8-c1de6d249e9b17d53edc0a713c1e43ef9b457ea7.tar.gz
android-node-v8-c1de6d249e9b17d53edc0a713c1e43ef9b457ea7.tar.bz2
android-node-v8-c1de6d249e9b17d53edc0a713c1e43ef9b457ea7.zip
core: implement runtime flag to trace sync io
Use the --trace-sync-io flag to print a stack trace whenever a sync method is used after the first tick, excluding during the process exit event. (e.g. fs.readFileSync()) It does not track if the warning has occurred at a specific location in the past and so will print the warning every time. Reason for not printing during the first tick of the appication is so all necessary resources can be required. Also by excluding synchronous calls during exit is necessary in case any data needs to be logged out by the application before it shuts down. Fixes: https://github.com/nodejs/io.js/issues/1674 PR-URL: https://github.com/nodejs/io.js/pull/1707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Petka Antonov <petka_antonov@hotmail.com>
Diffstat (limited to 'test/parallel/test-sync-io-option.js')
-rw-r--r--test/parallel/test-sync-io-option.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/parallel/test-sync-io-option.js b/test/parallel/test-sync-io-option.js
new file mode 100644
index 0000000000..390710d265
--- /dev/null
+++ b/test/parallel/test-sync-io-option.js
@@ -0,0 +1,44 @@
+'use strict';
+
+const assert = require('assert');
+const spawn = require('child_process').spawn;
+
+
+if (process.argv[2] === 'child') {
+ setImmediate(function() {
+ require('fs').readFileSync(__filename);
+ process.exit();
+ });
+
+} else {
+ (function runTest(flags) {
+ var execArgv = [flags.pop()];
+ var args = [__filename, 'child'];
+ var child = spawn(process.execPath, execArgv.concat(args));
+ var cntr = 0;
+
+ child.stdout.on('data', function(chunk) {
+ throw new Error('UNREACHABLE');
+ });
+
+ child.stderr.on('data', function(chunk) {
+ // Prints twice for --trace-sync-io. First for the require() and second
+ // for the fs operation.
+ if (/^WARNING[\s\S]*fs\.readFileSync/.test(chunk.toString()))
+ cntr++;
+ });
+
+ child.on('exit', function() {
+ if (execArgv[0] === '--trace-sync-io')
+ assert.equal(cntr, 2);
+ else if (execArgv[0] === ' ')
+ assert.equal(cntr, 0);
+ else
+ throw new Error('UNREACHABLE');
+
+ if (flags.length > 0)
+ setImmediate(runTest, flags);
+ });
+ }(['--trace-sync-io', ' ']));
+}
+