Skip to content

Enable use of docker in travis and run tedious + stress tests in CI#614

Closed
elhigu wants to merge 12 commits into
tediousjs:masterfrom
elhigu:run-ci-tests-against-mssql-server
Closed

Enable use of docker in travis and run tedious + stress tests in CI#614
elhigu wants to merge 12 commits into
tediousjs:masterfrom
elhigu:run-ci-tests-against-mssql-server

Conversation

@elhigu

@elhigu elhigu commented Feb 26, 2018

Copy link
Copy Markdown

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.

@elhigu elhigu force-pushed the run-ci-tests-against-mssql-server branch 14 times, most recently from f4c52fc to 840f585 Compare February 26, 2018 14:16
@elhigu

elhigu commented Feb 26, 2018

Copy link
Copy Markdown
Author

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 😅

@elhigu elhigu force-pushed the run-ci-tests-against-mssql-server branch 4 times, most recently from ddca31b to 3efd83e Compare March 4, 2018 20:53
@elhigu

elhigu commented Mar 4, 2018

Copy link
Copy Markdown
Author

Now that implementation is using end event and npm run mssql-server:up is actually waiting until mssql server is ready all seems to run correctly.

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.

Comment thread lib/tedious.js Outdated
reject(err)
}
}

@elhigu elhigu Mar 4, 2018

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below this line is the actual fix, that we are rejecting also if end is emitted, even that connectnever triggered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe explaining what is happening and why in a comment in the code would make sense?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, better to add some information to comments too 👍

})
}

function cloneDeep (val) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is reused, maybe makes sense to extract to test util file? or import lodash as devdependency and use _.cloneDeep?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the config belong inside the test itself?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peding -> pending

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack!


if (hangRounds === 3) {
console.log('Driver did hang exit with error')
process.exit(1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is a test, does it make sense to exit process and not just fail an assertion?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe all the proxy code would make more sense in a separate helper file to reduce the clutter?..

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@elhigu

elhigu commented Apr 6, 2018

Copy link
Copy Markdown
Author

@kibertoad Thanks for the review, I'll be updating this as soon as I have some spare time.

@willmorgan

Copy link
Copy Markdown
Collaborator

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.

@elhigu

elhigu commented Oct 18, 2018

Copy link
Copy Markdown
Author

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.

@dhensby dhensby force-pushed the run-ci-tests-against-mssql-server branch from 3efd83e to 00b2dbc Compare October 18, 2018 21:25
Comment thread test/mssql-config.js Outdated
try {
config = require(`./.mssql.json`)
} catch (e) {
config = require(`./.mssql-docker.json`)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would be the expected error here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file doesn't exist?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we just include the correct file depending on the context? 😱

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂️

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not bothered, the only thing I may have changed is to call it .mssql,dist.json

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 👍

Comment thread test/tedious/tedious.js Outdated

const config = function () {
let cfg = JSON.parse(require('fs').readFileSync(`${__dirname}/../.mssql.json`))
let cfg = clone(require('../mssql-config'))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PRS WELCOME

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, that would be more readable

@dhensby dhensby left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a few of these commits can be squashed too, to neated it up

Comment thread package.json Outdated
"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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be docker-compose down -v?

Comment thread lib/tedious.js Outdated
debug('pool(%d): connection #%d created', IDS.get(this), IDS.get(tedious))
debug('connection(%d): establishing', IDS.get(tedious))

tedious.on('debug', msg => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... probably this is not needed, but something else was.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

@dhensby Closing this PR should be fairly high priority as it's blocking this old chestnut from getting removed:

https://github.com/tgriesser/knex/blob/232fe9f1517dba927f6a3a1fb1b8842d7c0a4007/src/dialects/mssql/index.js#L52-L70

cc: @elhigu

@dhensby

dhensby commented Oct 19, 2018

Copy link
Copy Markdown
Collaborator

@willmorgan this PR is not blocking that. This is: tediousjs/tedious#809

See knex/knex#2861

@dhensby

dhensby commented Oct 19, 2018

Copy link
Copy Markdown
Collaborator

Feedback addressed

@dhensby dhensby force-pushed the run-ci-tests-against-mssql-server branch from a505ec0 to 69869af Compare October 19, 2018 09:11
@willmorgan

Copy link
Copy Markdown
Collaborator

@willmorgan this PR is not blocking that.

I think it actually is - see the comment in the highlighting code that refers back to this very PR.

@dhensby

dhensby commented Oct 19, 2018

Copy link
Copy Markdown
Collaborator

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 error event is correctly emitted on aborted connections now.

@dhensby

dhensby commented Oct 20, 2018

Copy link
Copy Markdown
Collaborator

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....

@dhensby

dhensby commented Oct 20, 2018

Copy link
Copy Markdown
Collaborator

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.

@dhensby

dhensby commented Nov 19, 2018

Copy link
Copy Markdown
Collaborator

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

@dhensby dhensby closed this Nov 19, 2018
@kibertoad

Copy link
Copy Markdown
Contributor

@dhensby Wait, aren't stress tests passing because this PR also includes fixes, as mentioned by @elhigu in pr description?

@dhensby

dhensby commented Nov 19, 2018

Copy link
Copy Markdown
Collaborator

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants