-
Notifications
You must be signed in to change notification settings - Fork 93
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
fix: delete for _rmdirRecursiveSync #63
Conversation
@voltrevo Could you please add a test case for this as well? |
dirs.push(file); | ||
} else { | ||
fs.unlinkSync(file); | ||
} | ||
} | ||
} |
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.
Please remove the unnecessary whitespace.
Need any help here? Just hit the same bug |
Is this PR still using or not? I got this problem today and I also made a fix( a little different ), than I saw this PR. Need this bug fix ASAP, pretty critical. |
Duplicate PR as raszi#63 , but that PR is frozen. This is a very critical matter, so I made this.
@AaronJan Working on this now. |
@silkentrance @raszi I'm having a lot of trouble with the way testing works for this project:
Am I going about using this setup the wrong way? How do you guys debug this stuff? |
A little more context for the above comment: I've put some code into if (unsafe) {
// structure from issue 62
['foo', 'bar'].forEach(function(dir) {
fs.mkdirSync(join(result.name, dir));
fs.writeFileSync(join(result.name, dir, 'baz.txt'), '');
});
} Everything was good when I added that code in my branch, but I was scratching my head when all the tests passed when I restored the version of rmdirRecursiveSync with the bug in it and the tests still passed. However, by wrapping rmdirRecursiveSync in a try catch block and doing a fs.writeFileSync on an error (and re-throwing the error) I was able to get this output:
This means that errors thrown inside the node sub-processes are not propagating into the main test process. There could be other lurking issues that are being swallowed this way. |
There we go. I added an assertion for the removal of the
|
Awesome, cheers 👍. |
👍 |
👍 i also have this issue LGTM! |
@voltrevo as far as I understand the test cases that spawn external processes is that the output on stdout is recorded and passed to calling test case´s callback. The output is then evaluated by the test case. If you now add additional content to that output via console.log, these test cases will naturally fail. as for debugging the external processes: http://stackoverflow.com/questions/16840623/how-to-debug-node-js-child-forked-process |
@voltrevo and of course, spawning the child processes is required for tmp to automatically clean up after that the process exits. |
@voltrevo in your test case you create a new assertion in dir-test which tests the asynchronous interface and you also add additional code to unsafe-sync, which is meant for the synchronous interface. as a hint: dir-test.js and unsafe.js are used in testing the asynchronous part of the api and dir-sync-test.js and unsafe-sync.js are used in testing the synchronous part of the api. for starters, create two separate test cases, one in dir-sync-test and one in dir-test, that will each spawn a child process using the available functions in test/base.js that will then create a tmp dir either synchronously or asynchronously. In the child process you will then create a tree structure of sub directories and files just like you did in the test cases that you hooked your tests into. the child process would then console.log(path) the path to the temporary directory and simply exits. in the test cases you would then receive the path via your provided callback and then will assert that that path, i.e. the tmp directory, no longer exists. of course you need to invoke it so that it will forward any error occurring in the child processes to your test cases. would this be of any help to you? |
@silkentrance Hmmm ok I'll have another crack at this. |
@silkentrance @raszi Would you prefer the issue62 dir to be added to the structures made in unsafe.js and unsafe-sync.js and those tests added to the I think right now I'm going to just use the existing topics, since it appears that's more consistent with the rest of the project, but if you get a chance please interrupt me if you'd like me to make separate topics. |
@silkentrance On second thought, it definitely sounds like you want separate topics. Switching to that. |
Ok this should be much better now, there are actually additional tests now that fail on master: # master version is setup correctly, passes its own tests:
$ cd ../node-tmp-clean/
$ npm test
> tmp@0.0.27 test /Users/andrew/workspaces/node-tmp-issue-62/node-tmp-clean
> vows test/*-test.js
··············································· ····················································· ········································ ················································ ···············
✓ OK » 203 honored (1.171s) # using the master copy of lib/tmp.js in the new version fails the added tests:
$ cd ../node-tmp
$ cp ../node-tmp-clean/lib/tmp.js lib/tmp.js
$ npm test
> tmp@0.0.27 test /Users/andrew/workspaces/node-tmp-issue-62/node-tmp
> vows test/*-test.js
·················································✗ ····················································✗··· ········································ ················································ ···············
unsafeCleanup === true with issue62 structure
✗ should not exist
» Directory should be removed // dir-sync-test.js:199
✗ should not exist
» Directory should be removed // dir-test.js:193
✗ Broken » 207 honored ∙ 2 broken (1.254s)
npm ERR! Test failed. See above for more details. # Using the new version of lib/tmp.js passes the added tests:
$ git checkout lib/tmp.js
$ npm test
> tmp@0.0.27 test /Users/andrew/workspaces/node-tmp-issue-62/node-tmp
> vows test/*-test.js
·················································· ························································ ········································ ················································ ···············
✓ OK » 209 honored (1.197s) |
@raszi @silkentrance I'm a bit too invested to let this change go now if there are more problems with it, so I'll definitely address them if there's anything else you need me to fix up. If you like you can reach me via facebook, which you can find via an icon on the website I've listed on github. I'm much more likely to respond on there because I don't have github notifications setup very well, plus if we get a chance to chat semi-synchronously we could sort it out much faster. Also, would you guys be interested in me doing a bit of refactoring of these tests? It would be great to have linting set up because I burned more time than I should have on an undefined reference error which wasn't propagating properly to the test output, and there was a big delay in orienting myself in the test directory because it's not really structured and there's a lot of duplicated code that could be tidied up. Can't make any promises but much more likely to submit a pr if you guys would be receptive to it. |
@voltrevo thanks for your effort! just extend upon the existing test cases as it belongs there and is part of the standard functionality that tmp.dirSync() and tmp.dir() have to offer. |
@voltrevo as for facebook, I am not even a member and never will be... as for the refactoring: would be fine with me, however, since I am not the one with commit rights on this repo, you will have to ask raszi 😁 |
@silkentrance I had some trouble triggering the bug using the existing test cases. In the original test I provided it managed to clean up the structure I added but caused it to fail to clean up the tmp dir itself. I think it's much better if the tests I add the ones that fail under the master version, rather than have the new test interfere with an existing test and cause it to fail. If you insist I can look into why that happened and if there is a way to trigger just the added tests within those topics, but imo it is cleaner to do it this way anyway. |
@silkentrance Also it sounds like maybe you just want the tests to remain in dir-test.js and dir-sync-test.js? If that's the case it's already like that. In my comment above I interpreted what you said as moving the new tests into the pre-existing topics. |
Sorry for the late response. Unfortunately I don't have that much time working on this. Thank you very much for the fix and especially to write tests for them. Probably the issue you've faced was because one of the tests failed to clean after itself which I fixed recently in 1345a23 I am aware that the tests need some refactoring and I've already started that with a grunt integration which would include linting and running the tests. |
So for now, I'll merge this as it is since it fixes an outstanding and we'll need to refactor the tests anyways. |
Fix issue 62; duplicate delete for _rmdirRecursiveSync
Thanks @raszi 👍. |
Fixes #62