-
Notifications
You must be signed in to change notification settings - Fork 52
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
Promise support #7
Comments
The only pitfall I currently see is that you might need to run the promises sequentially in order to get clean heap snapshots. (There is only one heap, so running multiple stuff concurrently would make it impossible to get useful heap diffs, I guess) |
@andywer yeah that's the plan |
@andywer I just realize I need to modify the api because if we want to support promise, we need to add a new function for Promise only Several solutions:
const iterate = require('leakage')
iterate(100, () => {}) // returns Promise
iterate.sync(100, () => {}) // will throws if leaking
I prefer number 2 as will work for both sync and async code, and if user really want only sync they can use it //cc @btmills |
@mastilver I don't think so. The only problem is that you cannot do How about Alternatively we might use data.task. Should basically work like a Promise, but it doesn't start on creation. |
I don't see how you want to make it work, when the input function return a Promise, it needs to return a Promise as well, so we can wait for the result. With solution 2: this would totally work iterate(100, async () => {
await someAsyncStuff()
})
.then(() => {
// everything went well
})
.catch(err => {}) as well as iterate(100, () => {
someSyncStuff()
})
.then(() => {
// everything went well
})
.catch(err => {}) |
Ok, my But I would try to avoid having two different methods. I think the way Mocha or Jest do it (the function returns a promise or not), for example, is quite nice. We cannot go the exact same way if we want to run the tests strictly sequentially, but maybe can come up with something quite similar :) Another easy solution might be |
😆
I don't particularly agree with that, the most majority of packages have a async fn by default and a
Yes, but they are the consumer, so they can do whatever they want (if they receive a Promise => wait until it resolve, if they receive a callback => same they wait, if it's synchronous => they just run it So if we give Promises to |
Hmm, But your point is valid. And there is another issue: I am not sure if we can really ensure that test runners run (start) async tests strictly sequentially: http://stackoverflow.com/a/12983519 Maybe we should even consider dropping official support for all test runner that we know we cannot guarantee sequential execution under all circumstances. What do you think? Poking @btmills as well. |
👍
Damn... It makes senses but I didn't think about that... 😞 |
Don't worry, that's still a normal part of the process. Let's take a step back, have a good night's sleep and come up with an elegant concept. Then we start thinking how to implement it :) |
When designing an API, I like to write code as if I'm using my ideal API, and then figure out how to implement it. So here's some sketching:
I believe all of these forms could be differentiated inside a single Thoughts?
I think that makes sense. Make it the user's responsibility (and note this in the docs) to ensure that there's nothing else happening concurrently inside the same process while a leak test is being run. |
Yeah, 1 + 4 would also be my favorite. Combining it with a narrow set of supported test runners to ensure sequential testing should do the trick :) Btw: I was already thinking about implementing a small check in |
Have been playing around with a solution for Promise support, so that Here are my experiences so far:
So promises may be nice for the public API, but internally |
Any news here? I'd love to see promise support added. May even give it a shot if the API has been agreed upon and you're too busy. |
@stephenmathieson Yeah, sorry that it takes rather long and sure, knock yourself out if you want 😉, but the reason why it takes rather long is quite simple: Writing code for the Another thing is that I am currently also working on the next release of webpack-blocks. I will work on it as well, of course, but it might take one or two weeks. |
PS: Sorry for the long monolog, but I know it's a critical feature and it's good that you asked, so I know people care 😉 |
any updates on this? |
Not yet, sorry. I experimented, but got no usable outcome yet. I am rather busy preparing webpack-block's biggest release right now... 😕 |
Can I see what you tried? |
@mjhea0 Sure! I pushed it to branch async-support-2. When you run |
Update: I tried another way of implementing async support in branch async-support. The problem is: It failed on the first run and then started to work without any changes. So now all tests (including async ones) are green locally on my machine, but the travis build is mostly red (run tests on 3 node versions, 2 failed). Not sure why... |
Strange. Yeah, it passed on Node 7. Node probably just rejects them now. http://stackoverflow.com/questions/20068467/do-never-resolved-promises-cause-memory-leak |
It really seems to be node 7 vs. node < 7. I can reproduce it locally by switching between node versions. But the only difference in node 7 promise handling I can find is that unhandled promise rejections show a warning. I don't think it's about never resolving promises, since in the failing test case I wouldn't know where there is a single unresolved promise... |
Good news, though. Tried it in a real world scenario using node 7 and worked just fine 🎉 Here is a small test setup testing the |
Nice! Breaks on my end as well! |
@mjhea0 It breaks on your machine... using node <= 6? |
Sorry, I meant it is not breaking. |
Just released version 0.3.0-beta with promise support. Please try it out if you can :) It's really simple to use! |
Known issues: You need node >= 7.0 and for some reason the tests fail on travis right now :-/ (Tests are run twice, first on 'prepublish' which is invoked by |
Whats the status here? :D |
Status is: There is a solution for async testing in the release branch, but it randomly fails to do its job here and there and I can only guess why, but have no exact idea what's the problem 🙈💩 |
Well, at least there is progress. And btw -> awesome package overall. Node needs something like this badly :D |
Closing it in favor of #22. The next release supporting async testing is straight ahead! |
I can use your module for a database related module
Do you see any drawback adding support for Promises, let me know what you think!
I'm already working on it, it should be ready by the end of the day
The text was updated successfully, but these errors were encountered: