Skip to content

Commit

Permalink
Support backward compatibility
Browse files Browse the repository at this point in the history
- Skip tests for features not available in previous PGMQ versions.
- Updated readme to specify which features are available.
- Added badges to readme and added link to nuget package.
- Updated build to test against more version
brianpursley committed Dec 18, 2024
1 parent e98aaa2 commit 56545c4
Showing 4 changed files with 32 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -45,6 +45,15 @@ jobs:
- name: Test (latest pgmq version)
run: Npgmq.Test/scripts/run-tests.sh

- name: Test (pgmq 1.4.5)
run: Npgmq.Test/scripts/run-tests.sh 1.4.5

- name: Test (pgmq 1.3.3)
run: Npgmq.Test/scripts/run-tests.sh 1.3.3

- name: Test (pgmq 1.2.1)
run: Npgmq.Test/scripts/run-tests.sh 1.2.1

- name: Test (pgmq 1.1.1)
run: Npgmq.Test/scripts/run-tests.sh 1.1.1

1 change: 1 addition & 0 deletions Npgmq.Test/Npgmq.Test.csproj
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Xunit.SkippableFact" Version="1.5.23" />
</ItemGroup>

<ItemGroup>
14 changes: 12 additions & 2 deletions Npgmq.Test/NpgmqClientTest.cs
Original file line number Diff line number Diff line change
@@ -50,6 +50,12 @@ private async Task ResetTestQueueAsync()
await _sut.CreateQueueAsync(TestQueueName);
}

private async Task<bool> IsMinPgmqVersion(string minVersion)
{
var version = await _connection.ExecuteScalarAsync<string>("select extversion from pg_extension where extname = 'pgmq';");
return version is not null && new Version(version) >= new Version(minVersion);
}

[Fact]
public async Task ArchiveAsync_should_archive_a_single_message()
{
@@ -687,9 +693,11 @@ public async Task SendAsync_with_int_delay_should_add_message_with_future_vt()
Assert.Equal(msgId, await _connection.ExecuteScalarAsync<long>($"SELECT msg_id FROM pgmq.q_{TestQueueName} LIMIT 1;"));
}

[Fact]
[SkippableFact]
public async Task SendAsync_with_timestamp_delay_should_add_message_with_a_specified_vt()
{
Skip.IfNot(await IsMinPgmqVersion("1.5.0"), "This test requires pgmq 1.5.0 or later");

// Arrange
await ResetTestQueueAsync();
var delay = DateTimeOffset.UtcNow.AddHours(1);
@@ -747,9 +755,11 @@ public async Task SendBatchAsync_with_int_delay_should_add_multiple_messages_wit
Assert.Equal(msgIds.OrderBy(x => x), (await _connection.QueryAsync<long>($"SELECT msg_id FROM pgmq.q_{TestQueueName} ORDER BY msg_id;")).ToList());
}

[Fact]
[SkippableFact]
public async Task SendBatchAsync_with_timestamp_delay_should_add_multiple_messages_with_a_specified_vt()
{
Skip.IfNot(await IsMinPgmqVersion("1.5.0"), "This test requires pgmq 1.5.0 or later");

// Arrange
await ResetTestQueueAsync();
var delay = DateTimeOffset.UtcNow.AddHours(1);
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,14 +2,21 @@

A .NET client for [Postgres Message Queue](https://github.com/tembo-io/pgmq) (PGMQ).

[![Build](https://github.com/brianpursley/Npgmq/actions/workflows/build.yml/badge.svg)](https://github.com/brianpursley/Npgmq/actions/workflows/build.yml)
[![Nuget](https://img.shields.io/nuget/v/Npgmq)](https://www.nuget.org/packages/Npgmq/)
![License](https://img.shields.io/github/license/brianpursley/Npgmq)

## Compatibility

* pgmq >= 0.31.0
| PGMQ Version | Compatibility |
|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1.5.0+ | Fully supported |
| 0.31.0 - 1.4.5 | The following method overloads are *not* supported, since they were introduced in PGMQ 1.5.0:<br/> - `SendAsync(string, T, DateTimeOffset)`<br/>- `SendBatchAsync(string, IEnumerable<T>, DateTimeOffset)` |

## Installation
To install the package via Nuget, run the following command:
To install the package via [Nuget](https://www.nuget.org/packages/Npgmq/), run the following command:

```bash
```shell
dotnet add package Npgmq
```

0 comments on commit 56545c4

Please sign in to comment.