Enable use of docker in travis and run tedious + stress tests in CI#614
Enable use of docker in travis and run tedious + stress tests in CI#614elhigu wants to merge 12 commits into
Conversation
f4c52fc to
840f585
Compare
|
I'm having some failure problems with these tests... stay tuned, I already did put so much time to this that I can't stop now 😅 |
ddca31b to
3efd83e
Compare
|
Now that implementation is using Commit history is a bit ugly though so squash merge would be probably good choice to use if this is chosen to be merged in. Meanwhile I see if I'm able to write workaround for this to knex. |
| reject(err) | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Below this line is the actual fix, that we are rejecting also if end is emitted, even that connectnever triggered.
There was a problem hiding this comment.
Maybe explaining what is happening and why in a comment in the code would make sense?
There was a problem hiding this comment.
Yeah, better to add some information to comments too 👍
| }) | ||
| } | ||
|
|
||
| function cloneDeep (val) { |
There was a problem hiding this comment.
since this is reused, maybe makes sense to extract to test util file? or import lodash as devdependency and use _.cloneDeep?
There was a problem hiding this comment.
I didn't want to add even extra dev dependency for simple one liner, I'll refactor this and delay functions to test utils.
| debug('========== Reconnecting mssql') | ||
|
|
||
| // this test needs toxiproxy to run so docker mssql is also required | ||
| mssqlCon = new mssql.ConnectionPool({ |
There was a problem hiding this comment.
does the config belong inside the test itself?
There was a problem hiding this comment.
Yes, this time configuration should be hardcoded, because it must match the docker-compose setup which is hardcoded as well (but in yaml language instead of js / json).
| console.log('------------------------ REQUESTS SINCE LAST PRINT ------------------------') | ||
| if (mssqlCon.pool) { | ||
| console.dir({ | ||
| peding: mssqlCon.pool.pending, |
|
|
||
| if (hangRounds === 3) { | ||
| console.log('Driver did hang exit with error') | ||
| process.exit(1) |
There was a problem hiding this comment.
since this is a test, does it make sense to exit process and not just fail an assertion?
There was a problem hiding this comment.
Probably throwing exception and leaking it out kill the process would work too, but I think that calling exit(1) reflects more explicitly about that it is really intended to close this this process if hang is detected.
| }) | ||
| } catch (err) {} | ||
|
|
||
| const proxy = await toxicli.createProxy({ |
There was a problem hiding this comment.
maybe all the proxy code would make more sense in a separate helper file to reduce the clutter?..
There was a problem hiding this comment.
It is already in helper called recreateProxy, I find it better to have that code easily accessible than refactored prematurely.
Also the kind of proxy setup one needs to create depends on code that is being tested (I already wrote this kind of code for multiple DB drivers), so general helper doesn't make sense yet (unless there will be more tests like this using the same proxycreation).
|
@kibertoad Thanks for the review, I'll be updating this as soon as I have some spare time. |
|
I think in the short term while we're still figuring out what to do with AppVeyor (assuming stress tests are run there), then it'll give us something controlled to test on. |
Also included default config, which will use mssql running in docker for testing
|
Adding that stresstest sounds fine if its added as a separate travis instance doesnt sound like a bad thing if it works on travis fine. Also I think that this PR doesn’t contain all the canges I made to knex side so some cross referencing from there could be done. Also some of the stuff in this PR might have already been fixed in current master. |
3efd83e to
00b2dbc
Compare
| try { | ||
| config = require(`./.mssql.json`) | ||
| } catch (e) { | ||
| config = require(`./.mssql-docker.json`) |
There was a problem hiding this comment.
what would be the expected error here?
There was a problem hiding this comment.
shouldn't we just include the correct file depending on the context? 😱
There was a problem hiding this comment.
.mssql-docker.json docker file is included in repo with correct settings for dockerized mssql and if someone likes to use he's own mssql installation he can just add that .mssql.json which is not added to repo to override usage of docker... I don't have much of preference how it is signaled which configuration needs to be used. This was the easiest choice to implement and maintain that I came up :) Arguable maybe not the most elegant, but I like promoting functional design over elegancy.
There was a problem hiding this comment.
I'm really not bothered, the only thing I may have changed is to call it .mssql,dist.json
There was a problem hiding this comment.
The configuration file is tightly coupled with the configuration in docker file, that is why I choose the name also to refer to docker. Though .dist.json suffix could be good in either way 👍
|
|
||
| const config = function () { | ||
| let cfg = JSON.parse(require('fs').readFileSync(`${__dirname}/../.mssql.json`)) | ||
| let cfg = clone(require('../mssql-config')) |
There was a problem hiding this comment.
I'd be in favour of assigning the mssql-config require once at the top (eslint global-require style) and then cloning that assignment like so:
const configOptions = require('../mssql-config');
// later...
function config() {
return Object.assign({ driver: 'tedious' }, configOptions);
}There was a problem hiding this comment.
yup, that would be more readable
dhensby
left a comment
There was a problem hiding this comment.
Quite a few of these commits can be squashed too, to neated it up
| "test-cli": "node_modules/.bin/mocha test/common/cli.js" | ||
| "test-cli": "node_modules/.bin/mocha test/common/cli.js", | ||
| "mssql-server:up": "docker-compose up --no-start && docker-compose start", | ||
| "mssql-server:down": "docker-compose down" |
There was a problem hiding this comment.
should this be docker-compose down -v?
| debug('pool(%d): connection #%d created', IDS.get(this), IDS.get(tedious)) | ||
| debug('connection(%d): establishing', IDS.get(tedious)) | ||
|
|
||
| tedious.on('debug', msg => { |
There was a problem hiding this comment.
It was, because some disconnect events were not coming through, but I think this is one thing that in knex side was implemented in a different way in the patch I made there.
There was a problem hiding this comment.
So... probably this is not needed, but something else was.
There was a problem hiding this comment.
Yeah, to fix the pool depletion bug you needed the safeReject and safeResolve methods and to attach to the end event as well as the error because end was being fired by tedious (instead of error) if there was a socket timeout during connections.
That's not the case anymore so I've completely removed that patch, so this can go as well, I think.
|
@willmorgan this PR is not blocking that. This is: tediousjs/tedious#809 See knex/knex#2861 |
|
Feedback addressed |
a505ec0 to
69869af
Compare
I think it actually is - see the comment in the highlighting code that refers back to this very PR. |
I'm literally working on all 3 aspects, this PR is not blocking anything. This PR has gone from fixing the pool depletion bug to simply providing a resilient test suite. The fix for pool depletion has been removed from this PR and as the |
|
Right; I'm a little concerned that the stress test is not failing (because it should be due to the issue fixed with tediousjs/tedious#809 (not yet merged / released).. The stress tests in the knex library do fail without the current fix.... |
|
OK - so something that's not so clear to me and @elhigu I'd like your thoughts on this: I'd expect that this stress test would fail the same way the knex one would. If I check out this branch of knex (to allow running non-4.1.0 versions of mssql) https://github.com/dhensby/knex/tree/fix/mssql-support and then install this PR's branch of mssql and run the stress test there, I get the error noted here tediousjs/tedious#809. But if I run the stress test in this PR I get no error (even when I allow the test to run indefinitely). Therefore there must be some material difference to how this stress test is implemented. |
|
I'm going to have to close this due to lack of feedback and the fact it's not actually replicating the problems that other stress tests do. I'll happily re-open once we've got an update |
|
@kibertoad nope, I pulled the fixes out into their own PR: #719 which wasn't merged in the end because the bug was fixed in the upstream library instead. But when I run the stress test that comes with knex I then got an error (which was fixed with tediousjs/tedious#809) but that error does not happen with this stress test, so there must be some difference |
This should also include fixes to current test problems in test-tedious when using .mssql-docker.yml configuration.
Written on top of PR that fixes pool create issue in rare connection failure cases.
This also includes fix for the problem #612 and added test to CI that connecting doesn't hang anymore.