Skip to content
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

Proposal: Remove unit test dependency from MySQL #456

Closed
codingllama opened this issue Mar 21, 2017 · 7 comments
Closed

Proposal: Remove unit test dependency from MySQL #456

codingllama opened this issue Mar 21, 2017 · 7 comments
Assignees
Labels
Milestone

Comments

@codingllama
Copy link
Contributor

Currently, unit tests require a local MySQL to be running and have a root user without a password. While the presence of MySQL is paramount for integration-like tests, unit tests shouldn't have such requirement. That precludes users from doing a simple go test ./... and forces a specific local configuration.

I've had a quick look at sqlite in memory as substitute for unit tests and it looks viable.

A course of action could be:

  1. Make tests rely on GetTestDB instead of opening connections directly
  2. Replace the DB with sqlite3/:memory:
  3. ?
  4. Profit

From what I've seen, there a few changes we'd have to make for it to work:

  • Remove '#' comments from storage.sql
  • Declare indexes separately from table definitions
  • Remove SET GLOBAL sql_mode
  • Find a way around enums

A simple solution would be to have separate-but-equivalent schemas. That's not entirely desirable due to duplication, but it does fix a whole category of issues. Another venue is to "reinterpret" the script at GetTestDB and remove / change the problematic lines.

There are a few other options, such as writing our own fake storage implementation, but that doesn't solve the issue of storage layer tests.

WDYT?

@codingllama codingllama self-assigned this Mar 21, 2017
@gdbelvin
Copy link
Contributor

I was just working on something like this, but abandoned it for the moment.

In addition to the issues you've identified, I also identified the following:

  • No support for SQL ENUMS
  • Unique Indexes need to be declared outside tables

This would make it much easier to test Trillian with other projects. +1

For what it's worth we could supply a command line flag so the travis tests could still run using proper MySQL to make sure we haven't missed anything.

@codingllama
Copy link
Contributor Author

Yep, I was expecting you to pitch along. :)
@pphaneuf may be interested as well, as we were talking about this earlier today.

I have an experimental branch with a bunch of similar changes to yours, although it's nowhere close to a complete solution.

I like the idea of a flag for Travis. We could run unit tests using both in-memory and MySQL to be extra safe. There's also less reason not to do this if we have that.

@Martin2112
Copy link
Contributor

I did have a fake storage implementation back at the start of the project but it was too much work to maintain with things in flux.

I'd like to defer this until we've settled the schema a bit more. Note that there are some more issues with parameter ordering that might not affect SQLite but do affect sql variants with positional parameters like Postgres.

@Martin2112
Copy link
Contributor

Oh and what's the proposal for unit testing the MySQL code without MySQL? :-)

@codingllama
Copy link
Contributor Author

Re storage fakes: yeah, it can get pretty onerous early on. I did it before and, while it's handy, it also brings significant maintenance costs.

Re testing MySQL: integration tests would still require MySQL; we're aiming for the go test experience to be free of external setup, not everything.

There's also the idea of setting a DB flag for tests: by default we go with an in-memory storage, but if the flag is set to mysql then we use it. The same mechanism can be used to make Travis do 2 go test passes: one with in-memory and one with MySQL. It could also be used to test with MySQL locally.

If it all works as above, then we can do it without losing any functionality on our workflow, which would be pretty sweet. :)

How does that sound to you?

@Martin2112
Copy link
Contributor

Martin2112 commented Mar 28, 2017 via email

@Martin2112
Copy link
Contributor

Provisionally putting this in M9 to be done when things have settled down with the schema etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants