Skip to content

Commit ba83963

Browse files
authored
Enable Npgsql.Specification.Tests in the build pipeline (#6504)
1 parent 67685cc commit ba83963

5 files changed

Lines changed: 107 additions & 22 deletions

File tree

.github/workflows/build.yml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
# The NPGSQL_TEST_POSTGIS environment variable ensures that if PostGIS isn't installed,
7171
# the PostGIS tests fail and therefore fail the build.
7272
env:
73-
NPGSQL_TEST_POSTGIS: ${{ !startsWith(matrix.os, 'windows') && !startsWith(matrix.os, 'macos') }}
73+
NPGSQL_TEST_POSTGIS: ${{ !startsWith(matrix.os, 'windows') && !startsWith(matrix.os, 'macos') && matrix.pg_prerelease == '' }}
7474

7575
steps:
7676
- name: Checkout
@@ -108,16 +108,19 @@ jobs:
108108
sudo chmod 600 $PGDATA/{server.crt,server.key,ca.crt}
109109
sudo chown postgres $PGDATA/{server.crt,server.key,ca.crt}
110110
111+
# Create the npgsql_tests database
112+
sudo -u postgres psql -c "CREATE DATABASE npgsql_tests"
113+
111114
# Create npgsql_tests user with md5 password 'npgsql_tests'
112115
sudo -u postgres psql -c "CREATE USER npgsql_tests SUPERUSER PASSWORD 'md5adf74603a5772843f53e812f03dacb02'"
113116
114117
sudo -u postgres psql -c "CREATE USER npgsql_tests_ssl SUPERUSER PASSWORD 'npgsql_tests_ssl'"
115118
sudo -u postgres psql -c "CREATE USER npgsql_tests_nossl SUPERUSER PASSWORD 'npgsql_tests_nossl'"
116119
117-
# To disable PostGIS for prereleases (because it usually isn't available until late), surround with the following:
118-
#if [ -z "${{ matrix.pg_prerelease }}" ]; then
120+
# Install PostGIS if required
121+
if [[ $NPGSQL_TEST_POSTGIS == 'true' ]]; then
119122
sudo apt-get install -qq postgresql-${{ matrix.pg_major }}-postgis-${{ env.postgis_version }}
120-
#fi
123+
fi
121124
122125
if [ ${{ matrix.pg_major }} -ge 14 ]; then
123126
sudo sed -i "s|unix_socket_directories = '/var/run/postgresql'|unix_socket_directories = '/var/run/postgresql, @/npgsql_unix'|" $PGDATA/postgresql.conf
@@ -192,6 +195,9 @@ jobs:
192195
sed -i "s|#max_prepared_transactions = 0|max_prepared_transactions = 100|" pgsql/PGDATA/postgresql.conf
193196
pgsql/bin/pg_ctl -D pgsql/PGDATA -l logfile -o '-c ssl=true -c ssl_cert_file=../server.crt -c ssl_key_file=../server.key -c ssl_ca_file=../ca.crt' start
194197
198+
# Create npgsql_tests database
199+
pgsql/bin/psql -U postgres -c "CREATE DATABASE npgsql_tests"
200+
195201
# Create npgsql_tests user with md5 password 'npgsql_tests'
196202
pgsql/bin/psql -U postgres -c "CREATE ROLE npgsql_tests SUPERUSER LOGIN PASSWORD 'md5adf74603a5772843f53e812f03dacb02'"
197203
@@ -256,6 +262,9 @@ jobs:
256262
sleep 5
257263
done
258264
265+
# Create the npgsql_tests database
266+
psql -c "CREATE DATABASE npgsql_tests" postgres
267+
259268
# Create npgsql_tests user with md5 password 'npgsql_tests'
260269
psql -c "CREATE USER npgsql_tests SUPERUSER PASSWORD 'md5adf74603a5772843f53e812f03dacb02'" postgres
261270
@@ -298,11 +307,8 @@ jobs:
298307
done
299308
psql -c "CREATE USER npgsql_tests_scram SUPERUSER PASSWORD 'npgsql_tests_scram'" postgres
300309
301-
# TODO: Once test/Npgsql.Specification.Tests work, switch to just testing on the solution
302310
- name: Test
303-
run: |
304-
dotnet test -c ${{ matrix.config }} -f ${{ matrix.test_tfm }} test/Npgsql.Tests --logger "GitHubActions;report-warnings=false" --blame-crash --blame-hang-timeout 30s
305-
dotnet test -c ${{ matrix.config }} -f ${{ matrix.test_tfm }} test/Npgsql.DependencyInjection.Tests --logger "GitHubActions;report-warnings=false"
311+
run: dotnet test -c ${{ matrix.config }} -f ${{ matrix.test_tfm }} --logger "GitHubActions;report-warnings=false" --blame-crash --blame-hang-timeout 30s
306312
shell: bash
307313

308314
- name: Upload Test Hang Dumps
@@ -314,13 +320,6 @@ jobs:
314320
**/*.dmp
315321
**/*_Sequence.xml
316322
317-
- name: Test Plugins
318-
run: |
319-
if [ -z "${{ matrix.pg_prerelease }}" ]; then
320-
dotnet test -c ${{ matrix.config }} -f ${{ matrix.test_tfm }} test/Npgsql.PluginTests --logger "GitHubActions;report-warnings=false"
321-
fi
322-
shell: bash
323-
324323
- id: analyze_tag
325324
name: Analyze tag
326325
shell: bash

test/Npgsql.Specification.Tests/Npgsql.Specification.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@
1010
<PackageReference Include="xunit" />
1111
<PackageReference Include="xunit.runner.visualstudio" />
1212
</ItemGroup>
13+
14+
<PropertyGroup>
15+
<NoWarn>$(NoWarn);xUnit1004</NoWarn>
16+
</PropertyGroup>
1317
</Project>
Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
using AdoNet.Specification.Tests;
2+
using Xunit;
3+
using Xunit.Sdk;
24

35
namespace Npgsql.Specification.Tests;
46

57
public sealed class NpgsqlCommandTests(NpgsqlDbFactoryFixture fixture) : CommandTestBase<NpgsqlDbFactoryFixture>(fixture)
68
{
7-
// PostgreSQL only supports a single transaction on a given connection at a given time. As a result,
8-
// Npgsql completely ignores DbCommand.Transaction.
9-
public override void ExecuteReader_throws_when_transaction_required() {}
10-
public override void ExecuteReader_throws_when_transaction_mismatched() {}
11-
}
9+
public override void ExecuteReader_throws_when_transaction_required()
10+
{
11+
// PostgreSQL only supports a single transaction on a given connection at a given time. As a result,
12+
// Npgsql completely ignores DbCommand.Transaction.
13+
var ex = Assert.Throws<ThrowsException>(() => base.ExecuteReader_throws_when_transaction_required());
14+
Assert.Contains("No exception was thrown", ex.Message);
15+
}
16+
17+
public override void ExecuteReader_throws_when_transaction_mismatched()
18+
{
19+
// PostgreSQL only supports a single transaction on a given connection at a given time. As a result,
20+
// Npgsql completely ignores DbCommand.Transaction.
21+
var ex = Assert.Throws<ThrowsException>(() => base.ExecuteReader_throws_when_transaction_mismatched());
22+
Assert.Contains("No exception was thrown", ex.Message);
23+
}
24+
25+
// Skipped tests mark places where Npgsql currently diverges from AdoNet.Specification.Tests expectations.
26+
// Some divergences may be by design; others may indicate compatibility gaps worth investigating.
27+
28+
[Fact(Skip = "NpgsqlCommand.ExecuteReader() throws NpgsqlOperationInProgressException instead of InvalidOperationException when another reader is already open")]
29+
public override void ExecuteReader_throws_when_reader_open() {}
30+
31+
[Fact(Skip = "NpgsqlCommand.Execute() throws InvalidCastException instead of NotSupportedException for unknown ParameterValue types")]
32+
public override void Execute_throws_for_unknown_ParameterValue_type() {}
33+
}
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
using System.Threading.Tasks;
12
using AdoNet.Specification.Tests;
3+
using Xunit;
24

35
namespace Npgsql.Specification.Tests;
46

5-
public sealed class NpgsqlConnectionTests(NpgsqlDbFactoryFixture fixture) : ConnectionTestBase<NpgsqlDbFactoryFixture>(fixture);
7+
public sealed class NpgsqlConnectionTests(NpgsqlDbFactoryFixture fixture) : ConnectionTestBase<NpgsqlDbFactoryFixture>(fixture)
8+
{
9+
// Skipped tests mark places where Npgsql currently diverges from AdoNet.Specification.Tests expectations.
10+
// Some divergences may be by design; others may indicate compatibility gaps worth investigating.
11+
12+
[Fact(Skip = "NpgsqlConnection does not support the Disposed event")]
13+
public override void Dispose_raises_Disposed() {}
14+
15+
[Fact(Skip = "NpgsqlConnection does not support the Disposed event")]
16+
public override Task DisposeAsync_raises_Disposed() => Task.CompletedTask;
17+
18+
[Fact(Skip = "NpgsqlConnection.OpenAsync() does not throw OperationCanceledException when a canceled token is passed")]
19+
public override Task OpenAsync_is_canceled() => Task.CompletedTask;
20+
}
Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,50 @@
1+
using System.Threading.Tasks;
12
using AdoNet.Specification.Tests;
3+
using Xunit;
24

35
namespace Npgsql.Specification.Tests;
46

5-
public sealed class NpgsqlDataReaderTests(NpgsqlSelectValueFixture fixture) : DataReaderTestBase<NpgsqlSelectValueFixture>(fixture);
7+
public sealed class NpgsqlDataReaderTests(NpgsqlSelectValueFixture fixture) : DataReaderTestBase<NpgsqlSelectValueFixture>(fixture)
8+
{
9+
// Skipped tests mark places where Npgsql currently diverges from AdoNet.Specification.Tests expectations.
10+
// Some divergences may be by design; others may indicate compatibility gaps worth investigating.
11+
12+
[Fact(Skip = "NpgsqlDataReader.FieldCount throws ObjectDisposedException instead of InvalidOperationException")]
13+
public override void FieldCount_throws_when_closed() {}
14+
15+
[Fact(Skip = "NpgsqlDataReader.GetBytes() throws ArgumentOutOfRangeException instead of returning 0 when dataOffset is too large")]
16+
public override void GetBytes_reads_nothing_when_dataOffset_is_too_large() {}
17+
18+
[Fact(Skip = "NpgsqlDataReader.GetChars() throws EndOfStreamException instead of returning 0 when dataOffset is too large")]
19+
public override void GetChars_reads_nothing_when_dataOffset_is_too_large() {}
20+
21+
[Fact(Skip = "NpgsqlDataReader.GetDataTypeName() throws ObjectDisposedException instead of InvalidOperationException when reader is disposed")]
22+
public override void GetDataTypeName_throws_when_closed() {}
23+
24+
[Fact(Skip = "NpgsqlDataReader.GetFieldType() throws ObjectDisposedException instead of InvalidOperationException when reader is disposed")]
25+
public override void GetFieldType_throws_when_closed() {}
26+
27+
[Fact(Skip = "NpgsqlDataReader.GetFieldValueAsync() does not throw an OperationCanceledException when a canceled token is passed")]
28+
public override Task GetFieldValueAsync_is_canceled() => Task.CompletedTask;
29+
30+
[Fact(Skip = "NpgsqlDataReader.GetName() throws ObjectDisposedException instead of InvalidOperationException when reader is disposed")]
31+
public override void GetName_throws_when_closed() {}
32+
33+
[Fact(Skip = "NpgsqlDataReader.GetTextReader() throws InvalidCastException when command text is null")]
34+
public override void GetTextReader_returns_empty_for_null_String() {}
35+
36+
[Fact(Skip = "NpgsqlDataReader.GetValue() throws ObjectDisposedException instead of InvalidOperationException when reader is disposed")]
37+
public override void GetValue_throws_when_closed() {}
38+
39+
[Fact(Skip = "NpgsqlDataReader.IsDBNull() throws ObjectDisposedException instead of InvalidOperationException when reader is disposed")]
40+
public override void IsDBNull_throws_when_closed() {}
41+
42+
[Fact(Skip = "NpgsqlDataReader.IsDBNullAsync() does not throw OperationCanceledException when a canceled token is passed")]
43+
public override Task IsDBNullAsync_is_canceled() => Task.CompletedTask;
44+
45+
[Fact(Skip = "NpgsqlDataReader.NextResult() throws ObjectDisposedException instead of InvalidOperationException when reader is disposed")]
46+
public override void NextResult_throws_when_closed() {}
47+
48+
[Fact(Skip = "NpgsqlDataReader.Read() throws ObjectDisposedException instead of InvalidOperationException when reader is disposed")]
49+
public override void Read_throws_when_closed() {}
50+
}

0 commit comments

Comments
 (0)