Create abstract test suite
Closed this issue · 10 comments
See https://github.com/dotnet/corefx/issues/7810#issuecomment-346144759 where @roji wrote:
there will need to be a generic abstract nuget that specific ADO.NET drivers can consume, extending the abstract test suite. Some tests may be overridden (so everything needs to be virtual), some would be ignored/skipped (not relevant for that provider), etc. etc.
A previous comment mentions "EFCore.Specification.Tests"; the latest code path is https://github.com/aspnet/EntityFrameworkCore/tree/dev/src/EFCore.Specification.Tests.
Probably the patterns developed in that test suite would be appropriate to use here.
It looks like it takes a dependency on Xunit. If we wanted to keep the colour-coded matrix, maybe it could be created by parsing Xunit output from running the tests with a particular connector.
Established the basic pattern that test classes should follow, and implemented it for MySqlConnector.
Using Xunit brings nice benefits, such as being able to run/debug individual tests in an IDE. Creating the same table from its XML output may be challenging, though.
All tests have been ported to the new framework (but a NuGet package has not been published yet).
Once this is published as a nuget I'll also set up a project in the Npgsql solution and see how it goes...
FWIW, here are the current Npgsql test "failures". I don't yet have a good way to denote "let's agree to disagree"; maybe overriding the method with a Skip
reason? (Of course, when integrated into your own test suite you're free to do whatever you want.)
DbCommand
- Setting
CommandText
orConnection
when there is an active reader; expected to throwInvalidOperationException
; Npgsql does not.- Only System.Data.SQLite, pre-release Microsoft.Data.Sqlite, and latest MySqlConnector do this.
- Calling
ExecuteQuery
,ExecuteScalar
, etc. whenCommandText
hasn't been set; expected to throwInvalidOperationException
; Npgsql does not.- Every connector except Npgsql and System.Data.SQLite does this
- Calling
ExecuteReader
when there is an open reader; Npgsql throwsNpgsqlOperationInProgressException
notInvalidOperationException
- ... which is an
InvalidOperationException
, so I need to fix the test
- ... which is an
- Set
DbCommand.Transaction
to a transaction from a different connection should throwInvalidOperationException
- Calling
ExecuteReader
when theConnection
has an active transaction but theCommand.Transaction
property isn't set; Npgsql doesn't throw anInvalidOperationException
fromExecuteReader
but does throwNpgsqlOperationInProgressException
fromDbTransaction.Dispose
.
Command
- Npgsql throws
NotSupportedException
instead ofInvalidOperationException when
BeginTransaction` is called nested on the same connection. - Open throws
ArgumentException
notInvalidOperationException
whenConnectionString
isn't set.- Connectors are pretty inconsistent about this
@bgrainger thanks for those! I'll take a look at them for Npgsql 3.3.
Regarding the suite itself... I think Npgsql's test suite should live in the Npgsql solution (extending your abstract test suite nuget of course) - this is the approach used in the EF Core functional tests, and as you say it would allow me to skip certain tests, modify others, etc. For the purposes of generating the comparative graphics, rather than the current method maybe you could simply include Npgsql's suite via git submodules or similar - this would avoid duplicating the suite in your project for the sole purpose of generating the comparison.
I'll try to find some time to integrate this into Npgsql soon!
Package is on NuGet: https://www.nuget.org/packages/AdoNet.Specification.Tests/
Basic instructions in the README: https://github.com/mysql-net/AdoNetApiTest/blob/master/README.md
Have created a test project in the Npgsql solution which extends this, was quite easy to do. Have also started looking at some quick fixes, work is ongoing in https://github.com/roji/Npgsql/tree/spec-tests.
One point: it doesn't seem right for AdoNet.Specification.Tests to contain concrete database types (e.g. PostgresDatabaseBase
... The whole point of the specific provider projects is for them to provide their own subclass of DatabaseBase
. Note that in the Npgsql project I have my own subclass (MyPostgresDatabase
) to override the default connection string, to make it match with what my other test suites use as a default.
Will try to report on progress...
PS Will probably submit a PR to run the latest Npgsql CI package in your comparison run - and not just the latest stable release - so we can track progress.
it doesn't seem right for AdoNet.Specification.Tests to contain concrete database types
I felt a little dirty about this, but decided that (for pragmatic reasons) it could be useful for multiple providers to be able to reuse common logic for, e.g., creating SQL for a particular server.
The ConnectionString
is a hack, and almost certainly not reusable by any provider, so you're right: it should be removed.
(I didn't discuss this in the README, but a provider is of course free to implement IDbFactoryFixture
from scratch, and not take a dependency on those other types.)