Use sqlite3 as the default driver for unit tests#886
Use sqlite3 as the default driver for unit tests#886codingllama merged 11 commits intogoogle:masterfrom
Conversation
|
Fixes #456. |
a320cff to
2e39e81
Compare
Codecov Report
@@ Coverage Diff @@
## master #886 +/- ##
==========================================
- Coverage 64.45% 64.43% -0.03%
==========================================
Files 91 91
Lines 7577 7581 +4
==========================================
+ Hits 4884 4885 +1
- Misses 2237 2242 +5
+ Partials 456 454 -2
Continue to review full report at Codecov.
|
.travis.yml
Outdated
| - cd $HOME/gopath/src/github.com/google/trillian | ||
| - HAMMER_OPTS="--operations=50" ./integration/maphammer.sh 3 | ||
| - | | ||
| if [[ -n "${TRILLIAN_SQL_DRIVER}" && "${TRILLIAN_SQL_DRIVER}" != sqlite3 ]]; then |
There was a problem hiding this comment.
or, just to capture an IRL chat, flip this to check for mysql since that what the scripts contained in the block are expecting?
There was a problem hiding this comment.
Flipped and quoted.
| ) | ||
|
|
||
| func TestMapIntegration(t *testing.T) { | ||
| if provider := testdb.Default(); !provider.IsMySQL() { |
There was a problem hiding this comment.
Would this be a useful test helper func to share with the other tests?
There was a problem hiding this comment.
I think this is OK, it's not that verbose and both the Skip and the message are clearly visible in the test.
storage/mysql/log_storage_test.go
Outdated
| j, logID := j, logID | ||
| func() { | ||
| tx := beginLogTx(s, logID, t) | ||
| defer tx.Close() |
There was a problem hiding this comment.
Did you do this func(){}() to force the defer to run or was there another subtle reason?
If it's the former, maybe it's better to just explicitly do the tx.Close() below, 'cos the function is a bit confusing (it looks like it might go async or something).
There was a problem hiding this comment.
One suggestion might be something like a func runWithTX(s, logID, f func(tx) err) err and you'd do here:
for ... {
err := runWithTX(s, logID, func f(tx ...) err {
numToAdd ..
...
if bad {
return errors.New(...)
}
...
return nil
})
if err != nil {
t.Error...
}
}and runWithTX does the
tx := beginLog...
defer tx.Close()
return f(tx)There was a problem hiding this comment.
Yes, the funcs were because of the defer-close. I went with your first suggestion and explicitly closed the tx.
I have been meaning to add runInTX methods for a while now, but in a slightly different form. I'll save those to another PR.
storage/mysql/log_storage_test.go
Outdated
| if diff := pretty.Compare(expectedCount, got); diff != "" { | ||
| t.Errorf("GetUnsequencedCounts() = diff -want +got:\n%s", diff) | ||
| } | ||
| func() { |
| FOREIGN KEY(TreeId) REFERENCES Trees(TreeId) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| CREATE UNIQUE INDEX TreeHeadRevisionIdx |
There was a problem hiding this comment.
(curiosity) is there a material difference between this and how it was declared before?
There was a problem hiding this comment.
Apart from having an explicit name, I think it's the same.
storage/testdb/testdb.go
Outdated
|
|
||
| // Provider is an object capable of creating new test databases. | ||
| type Provider struct { | ||
| Driver string |
| continue // skip empty lines and comments | ||
| } | ||
| if p.Driver == sqliteDriver { | ||
| line = enumRegex.ReplaceAllString(line, "VARCHAR(50)") |
There was a problem hiding this comment.
I'll assume those are happy tears. ;)
|
@AlCutter: all comments addressed, PTAL. |
The testdb package creates new databases using either mysql and sqlite, allowing us to switch between drivers transparently. The default driver for tests can be overriden via the TRILLIAN_SQL_DRIVER environment variable.
|
Thanks! Rebased on master, that should fix Travis errors. |
This partly-reverts commit 4023e5a ("Use sqlite3 as the default driver for unit tests (google#886)"), removing SQLite as a storage option. In practice, having a default DB that doesn't support much of the Trillian functionality (e.g. none of the map tests, none of the integration tests) has inconvenienced core developers. However, to allow the core `git clone <repo> ; go test ./...` scenario to still work without setup dependencies, all DB-using tests explicitly check for MySQL availability and are skipped if MySQL is not present.
This partly-reverts commit 4023e5a ("Use sqlite3 as the default driver for unit tests (google#886)"), removing SQLite as a storage option. In practice, having a default DB that doesn't support much of the Trillian functionality (e.g. none of the map tests, none of the integration tests) has inconvenienced core developers. However, to allow the core `git clone <repo> ; go test ./...` scenario to still work without setup dependencies, all DB-using tests explicitly check for MySQL availability and are skipped if MySQL is not present.
This partly-reverts commit 4023e5a ("Use sqlite3 as the default driver for unit tests (#886)"), removing SQLite as a storage option. In practice, having a default DB that doesn't support much of the Trillian functionality (e.g. none of the map tests, none of the integration tests) has inconvenienced core developers. However, to allow the core `git clone <repo> ; go test ./...` scenario to still work without setup dependencies, all DB-using tests explicitly check for MySQL availability and are skipped if MySQL is not present. A single deliberate test failure is emitted in this situation as a reminder that many tests are being skipped.
The testdb package adds utilities to create test databases for different
drivers. Currently, it supports sqlite3 (default) and mysql. The default driver
can be specified by the TRILLIAN_SQL_DRIVER environment variable, allowing tests
to transparently execute against different databases/drivers.
Adjustments done to existing code:
(functionally equivalent, but more portable)
false, otherwise SQLite interprets the constant as a column name)
(SQLite writes []byte{} as NULL). (This is a positive change in many ways, as
an empty Any proto is not valid due to having no type_url.)
A few test loops that defer-close resources had their scope reduced (using
anonymous functions), as doing so greatly reduces test duration on SQLite.
Finally, integration.GetTestDB has been completely replaced by
testdb.NewTrillianDB.