-
Notifications
You must be signed in to change notification settings - Fork 127
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
test(Model): reworked model.js test #329
Conversation
I forgot to mention: these tests are basically the same as in model.js, however I've reduced a lot of copy-pasta, cleaned it up a bit, etc. I wanted to keep it in a separate file so we could discuss any potential issues (as there were a few last time). My goal is to come to some conclusions regarding converting the rest of test suite over to some sort of consistent style/format. I would also absolutely love if we could come to an agreement on a .jshintrc that could be added to the project |
82e3785
to
42d943b
Compare
* cleaned up test code to be as asynchronous as possible * used chai/chai-as-expected to make tests more readable * introduced test-fixture to properly track/clean/drop tables throughout all test runs * made sure to wait for all table creation before operating on those tables
42d943b
to
8e75492
Compare
I think we should probably still have some tests (maybe all?) that don't wait for |
@marshall007 yeah, I agree, and that's possible with passing in The tests where I added the Finally, considering these are the model tests there is probably just going to be more of this type of behavior, rather than the query tests for instance where we might set up a bunch of sample data and just query away without needing to setup/teardown tables. |
@mbroadst agreed concerning the "fire-and-forget" stuff, it's nice to have the tests encapsulated the way you've done with |
@marshall007 well to be honest, adding the By all means fork this PR and improve upon it, I'm very open to discussion. |
I don't have much time today (and probably this week), so I just gave the pull request a quick look but I'm not sure to understand what this PR is suppose to bring. A few quick/random thoughts:
I'm aware that tests are messy, that we could refactor some code (like test-fixtures), but this PR doesn't seem to simplify things or make developing easier. |
To answer those points in order:
As for the comment "doesn't seem to simplify things or make developing easier", can you please expand upon that? Because I strongly disagree. |
}); | ||
|
||
return model.ready() | ||
.then(function() { expect(model).to.exist; }); |
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.
model
is immediately defined. There's no need to wait for the promise returned by ready
describe('ensureIndex', function() { | ||
afterEach(function() { return test.dropTables(); }); | ||
|
||
it('should add and ensure an index', function() { |
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.
done?
I don't have much time tonight, but still did a full pass (I think) on the test file. Thanks @mbroadst, I appreciate the effort but there are a few issues with the tests. They are not strictly equivalent (or at least testing the same set of things). The prototype chain in thinky is really special, and the tests were actually meaningful. The comments about equality, I'm still the one who has to run the tests the most (since I'm still the main one writing code for thinky), and honestly I don't want to have to google how chai works everytime or write a script to be sure that it will test what I want. The extra time it needs to run the tests may not be an issue for most of the people, but as the one who always run the tests before releasing and often while adding features, this would be a huge pain/downside for my interest to work on thinky. |
Arg you guys already replied to my comments. I have to run now. I'll try to catch up tonight (if it's not too late) or tomorrow. |
afaict the issues you brought up are quite easily solved. your discomfort with chai can be overcome (I'll just revert to assert, even though I think it's stretching it a bit far to say that nobody reading chai would have any idea what it's doing.. "1,006,653 downloads in the last month" on npmjs just completely disagrees with you here). As far as the time it takes to run the tests, well that's just how long it has to take until the guys at rethink optimize the tableCreate process I think. IMHO an ORM/ODM has to be incredibly precise in its testing, specifically involving making sure that tests run from a clean slate and in a reproducible manner. I'm adding roughly 1min (in fact I think its more like ~40s) to your test run here, but you make it seem like we're talking about 10min extra here (and tbh if it was 10min I'd still be for it). |
@mbroadst if the database/table cleanup is adding additional overhead perhaps we could add a command line argument to disable this? That way the CI server can run in "no-cleanup" mode for performance and/or @neumino's sanity :) |
@marshall007 we certainly could, though I believe it would be non-trivial. Again I point to Sequelize. They release regularly with only two official maintainers, and a test suite on travis that runs 25 variations for a grand total of 52 min 23 sec of testing. It is confusing to me that we are discussing how Not to mention, when |
Here's a list of actionable items for this PR:
Then it should be good I think. I don't really like having a |
you clearly saw that as needless here. Sure in cases like 742 I shouldn't presently return the validation function (though I believe in the future validations should be a promise chain, but more on this later), but I don't agree that bar-none all tests should use
I've already agreed to do this, but I'm glad we finally dragged the "I just don't like it" out of you 😄. In response to the added point there about deep equality, that's another matter of opinion but frankly the I believe chai's take on that to be the "correct" way. When you do this in your tests, you are saying that a plain object
You are indeed mistaken. There is only one set of tests that does this currently (the "Models" described section), and while you could certainly rewrite all tests to be that way, it wasn't on my list of things to do. It's a non-trivial amount of work to convert these tests to all run that way, and frankly its generally much easier for a developer to fully create the model in the test they are working on and "just not think about it" (rather than setting
This "behind the scenes" work is incomplete. The original reason I peppered the code with calls to Anyway, in conclusion you:
additionally, you don't really want the reduction in duplicate code by using for loops but you can live with it. That basically denies all the points this PR was created to address. I'm fine with that, you're the maintainer, but I can't help but feel that with a slightly more open mind you could dramatically reduce your work load here. Cheers |
throughout all test runs
those tables
You'll notice these tests take far longer to run. That's because previously thinky's tests did not actually wait for table creation (and frankly did not do any cleanup after test runs). This issue should track the progress of table creation speed (the bottleneck): rethinkdb/rethinkdb#4746