-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Upgrading 5.10.4 to 5.10.5 cause test run to hang #9437
Comments
just by chance does your unit test runs any aggregation pipeline ? if so, then you hit the same issue I reported as #9431 a couple of days ago |
It may be related. Do you use async iterators in your tests @josephstgh ? Any code samples you can provide would be helpful. |
@rvillane I don't have any aggregation pipeline in my test @vkarpov15 I do have some Update back again shortly |
I'm trying to create an easily reproducible script but we got a similar problem, a piece of our code and tests started to hand at |
Ok, in our case it seems that using sinonjs' fake timers to simulate a different date and time is causing |
Ah yes, I'm also using |
Possibly related to #9417 |
I have verified, and I think it is indeed related to It does seem to work for some of the test but not all. For example, some test case continue to fail even with the workaround. Still trying to figure out why.. |
Glad to hear this doesn't have anything to do with our aggregation cursor changes. You are right that This issue is due to a fix in the MongoDB node driver that allows for better concurrency but relies on Can you please provide an example of a test that fails even with |
Apologies, haven't had the time to do so yet. Will try to get an example of that soon. Appreciate your help! |
Hi @vkarpov15, I am unable to provide an repo as of right now, because of the test setup. I'm still trying to break it down, but this is roughly it.. I am testing kind of a // perform a app login
await usernamePwLogin(); // jwt token will be stored in storage
const token1 = getTokenFromStorage();
// my logic is if it the token is used before some expiry and after certain timing, the token will sort of refreshed
const clock = sinon.useFakeTimers({ now: token1.oat * 1000, toFake: ['setTimeout', 'setInterval']});
clock.tick(someDelay);
// perform an login with existing token should return new set of token
await jwtLogin(token1);
const token2 = getTokenFromStorage();
assert.notStrictEqual(token2, token1); // this should not be the same so when using So I went to look at the API of If you are able to spot anything from this would be much much appreciated. Thanks! |
What does |
As I'm using feathersjs framework, it also comes with feathers-client to perform the authentication which eventually triggers this jwtLoginStrategy I believe triggers this code Sorry, I don't mean to dump the codes/library to you, but I'm not exactly sure what you looking out for. Do let me know if more info is required, or I'm missing your question/point |
@vkarpov15 I was going to fix my tests by making sure Sinon didn't overwrite setImmediate but it looks like faking only the
|
@paglias do you know exactly what code hangs? Is it a query, a |
@vkarpov15 so I was writing a test and noticed that I had messed up sinon's syntax. With the correct one nothing hangs as long as only |
@paglias can you please provide the code of the test you wrote? |
The below script works fine for me with Mongoose v5.10.9, please modify the below script to demonstrate your issue @paglias @josephstgh 👍 'use strict';
const mongoose = require('mongoose');
const sinon = require('sinon');
sinon.useFakeTimers({ toFake: ['Date'] });
mongoose.set('useFindAndModify', false);
const { Schema } = mongoose;
run().catch(err => console.log(err));
async function run() {
await mongoose.connect('mongodb://localhost:27017/test', {
useNewUrlParser: true,
useUnifiedTopology: true
});
await mongoose.connection.dropDatabase();
const Model = mongoose.model('Test', Schema({ name: String }));
await Model.create({ name: 'test' });
console.log('Done', await Model.findOne(), new Date());
} |
@vkarpov15 with my previous comment I meant that |
Hi, will be testing out again in next couple days. |
Hi @vkarpov15, setting Those that continues to fail, is not caused by the "hang" issue but my assertion based on I will try to see if I can pinpoint more clearly so I can try to do up a repo so that it can be more easily diagnose. However before I am able to, do you have any suggestion? Thank you! |
It seems very strange that adding 'setTimeout' to |
Hi @vkarpov15, I will try to replicate it with a new repo as soon as possible. Thanks for helping! |
Hi @vkarpov15, I managed to replicate it here Let me know if there's anything else I can provide with Thanks! |
@josephstgh the issue is that node-schedule uses |
So if I were to understand correctly, based on what failing test I have now, I need to understand what sort of So it would be one of these based on the docs |
@josephstgh that's correct. Which is why we strongly recommend not using |
In that case, may I know what's the correct way to test when I want to |
Stub node-scheduler's |
This would only assert that it's being called with the correct params but not able to verify the result of the job that is being scheduled isn't it, without ticking the time forward. Imagine I scheduled a job to run an hour later, and that it will call an update to a doc, or create new doc. Without ticking the time, I am not able verify if the item is updated / created, yes? I understand this is a little out of scope, but would appreciate if you could help me understand the right approach. Thank you very much. |
Do you want to request a feature or report a bug?
Might be a bug
What is the current behavior?
Update:
I think I managed to drill down a little but still not quite sure. I isolated to a few more specific test case suite. Will update here once I have more findings. Update: Sorry, wasn't able to find anything conclusive yet..
When using
5.10.4
, when I ran my test (ts-mocha), it run smoothly as usual without any issue but once I upgrade to5.10.5
, there seem to have some weird issue like "hanging" on the test case. I don't have any error, or anything. Based on the changelog, the only thing it seem to possibly affect is the upgrade ofmongodb driver
to 3.6.2 but I am not sure where to begin checking.I'm not sure if it has anything to do with #9203 ? Just a wild guess.
I am still able to run my application without issue, it seem to be affecting the test run now
All test case seem to hit the
timeout
limit of 10sI understand this is little to go with, but do let me know what I can do to provide more information
What is the expected behavior?
Test to run as per usual to what it does in 5.10.4 or before
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Working
node: v12.18.4
mongoose: 5.10.4
mongodb: 4.2.0
Not working
node: v12.18.4
mongoose: 5.10.5
mongodb: 4.2.0
The text was updated successfully, but these errors were encountered: