diff --git a/.github/workflows/healthchecks_solr_ci.yml b/.github/workflows/healthchecks_solr_ci.yml index a4c4f80056..acbb68ab90 100644 --- a/.github/workflows/healthchecks_solr_ci.yml +++ b/.github/workflows/healthchecks_solr_ci.yml @@ -29,58 +29,8 @@ on: jobs: build: - runs-on: ubuntu-latest - # container: mcr.microsoft.com/dotnet/sdk:6.0 - # services: - # solr: - # image: solr:8.4.1 - # ports: - # - 8983:8983 - # volumes: - # - ${{ github.workspace }}/build/docker-services/solrcore:/var/solr/data/solrcore - # - ${{ github.workspace }}/build/docker-services/solrcoredown:/var/solr/data/solrcoredown - steps: - # - name: Provide permission for deleting volume files - # run: sudo chown -R $USER:$USER /home/runner/work/${{ github.event.repository.name }} - - - uses: actions/checkout@v3 - - name: Initialize Solr - run: | - docker run -d -p8983:8983 -v${{ github.workspace }}/build/docker-services/solrcore:/var/solr/data/solrcore -v${{ github.workspace }}/build/docker-services/solrcoredown:/var/solr/data/solrcoredown solr:8.4.1 - - name: Test Solr - run: | - wget http://localhost:8983/solr/# - curl http://localhost:8983/solr/# -v - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: | - 8.0.x - 9.0.x - - name: Restore - run: | - dotnet restore ./src/HealthChecks.Solr/HealthChecks.Solr.csproj && - dotnet restore ./test/HealthChecks.Solr.Tests/HealthChecks.Solr.Tests.csproj - - name: Check formatting - run: | - dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.Solr/HealthChecks.Solr.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) && - dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.Solr.Tests/HealthChecks.Solr.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) - - name: Build - run: | - dotnet build --no-restore ./src/HealthChecks.Solr/HealthChecks.Solr.csproj && - dotnet build --no-restore ./test/HealthChecks.Solr.Tests/HealthChecks.Solr.Tests.csproj - #- name: Test - # run: > - # dotnet test - # ./test/HealthChecks.Solr.Tests/HealthChecks.Solr.Tests.csproj - # --no-restore - # --no-build - # --collect "XPlat Code Coverage" - # --results-directory .coverage - # -- - # DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover - #- name: Upload Coverage - # uses: codecov/codecov-action@v3 - # with: - # flags: Solr - # directory: .coverage + uses: ./.github/workflows/reusable_ci_workflow.yml + with: + PROJECT_PATH: ./src/HealthChecks.Solr/HealthChecks.Solr.csproj + TEST_PROJECT_PATH: ./test/HealthChecks.Solr.Tests/HealthChecks.Solr.Tests.csproj + CODECOV_FLAGS: Solr diff --git a/test/HealthChecks.Solr.Tests/Functional/SolrHealthCheckTests.cs b/test/HealthChecks.Solr.Tests/Functional/SolrHealthCheckTests.cs index d9697dce1d..9043743f16 100644 --- a/test/HealthChecks.Solr.Tests/Functional/SolrHealthCheckTests.cs +++ b/test/HealthChecks.Solr.Tests/Functional/SolrHealthCheckTests.cs @@ -3,7 +3,7 @@ namespace HealthChecks.Solr.Tests.Functional; -public class solr_healthcheck_should +public class solr_healthcheck_should(SolrContainerFixture solrFixture) : IClassFixture { [Fact] public async Task be_healthy_if_solr_is_available() @@ -12,7 +12,7 @@ public async Task be_healthy_if_solr_is_available() .ConfigureServices(services => { services.AddHealthChecks() - .AddSolr("http://localhost:8983/solr", "solrcore", tags: ["solr"]); + .AddSolr(solrFixture.GetConnectionString(), "solrcore", tags: ["solr"]); }) .Configure(app => { @@ -35,7 +35,7 @@ public async Task be_unhealthy_if_solr_ping_is_disabled() .ConfigureServices(services => { services.AddHealthChecks() - .AddSolr("http://localhost:8893/solr", "solrcoredown", tags: ["solr"]); + .AddSolr(solrFixture.GetConnectionString(), "solrcoredown", tags: ["solr"]); }) .Configure(app => { diff --git a/test/HealthChecks.Solr.Tests/HealthChecks.Solr.Tests.csproj b/test/HealthChecks.Solr.Tests/HealthChecks.Solr.Tests.csproj index 90f4daa6d7..a00f1ab7a6 100644 --- a/test/HealthChecks.Solr.Tests/HealthChecks.Solr.Tests.csproj +++ b/test/HealthChecks.Solr.Tests/HealthChecks.Solr.Tests.csproj @@ -4,4 +4,14 @@ + + + + + + + PreserveNewest + + + diff --git a/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcore/conf/managed-schema b/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcore/conf/managed-schema new file mode 100644 index 0000000000..3a27e08ba6 --- /dev/null +++ b/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcore/conf/managed-schema @@ -0,0 +1,296 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcore/conf/solrconfig.xml b/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcore/conf/solrconfig.xml new file mode 100644 index 0000000000..1cf9fbae71 --- /dev/null +++ b/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcore/conf/solrconfig.xml @@ -0,0 +1,1230 @@ + + + + + + + + + 8.4.1 + + + + + + + + + + + ${solr.data.dir:} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${solr.lock.type:native} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${solr.ulog.dir:} + ${solr.ulog.numVersionBuckets:65536} + + + + + ${solr.autoCommit.maxTime:15000} + false + + + + + + ${solr.autoSoftCommit.maxTime:-1} + + + + + + + + + + + + + + ${solr.max.booleanClauses:1024} + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + 20 + + + 200 + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + server-enabled.txt + + *:* + + + + + + explicit + 10 + + + + + + + + + + + + + + + + explicit + json + true + + + + + + _text_ + + + + + + + + + text_general + + + + + + default + _text_ + solr.DirectSolrSpellChecker + + internal + + 0.5 + + 2 + + 1 + + 5 + + 4 + + 0.01 + + + + + + + + + + + + default + on + true + 10 + 5 + 5 + true + true + 10 + 5 + + + spellcheck + + + + + + + + + + true + false + + + terms + + + + + + + + + + + 100 + + + + + + + + 70 + + 0.5 + + [-\w ,/\n\"']{20,200} + + + + + + + ]]> + ]]> + + + + + + + + + + + + + + + + + + + + + + + + ,, + ,, + ,, + ,, + ,]]> + ]]> + + + + + + 10 + .,!? + + + + + + + WORD + + + en + US + + + + + + + + + + + + [^\w-\.] + _ + + + + + + + yyyy-MM-dd['T'[HH:mm[:ss[.SSS]][z + yyyy-MM-dd['T'[HH:mm[:ss[,SSS]][z + yyyy-MM-dd HH:mm[:ss[.SSS]][z + yyyy-MM-dd HH:mm[:ss[,SSS]][z + [EEE, ]dd MMM yyyy HH:mm[:ss] z + EEEE, dd-MMM-yy HH:mm:ss z + EEE MMM ppd HH:mm:ss [z ]yyyy + + + + + java.lang.String + text_general + + *_str + 256 + + + true + + + java.lang.Boolean + booleans + + + java.util.Date + pdates + + + java.lang.Long + java.lang.Integer + plongs + + + java.lang.Number + pdoubles + + + + + + + + + + + + + + + + + + + + text/plain; charset=UTF-8 + + + + + + + + + + + + + + diff --git a/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcore/data/server-enabled.txt b/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcore/data/server-enabled.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcoredown/conf/managed-schema b/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcoredown/conf/managed-schema new file mode 100644 index 0000000000..3a27e08ba6 --- /dev/null +++ b/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcoredown/conf/managed-schema @@ -0,0 +1,296 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcoredown/conf/solrconfig.xml b/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcoredown/conf/solrconfig.xml new file mode 100644 index 0000000000..1cf9fbae71 --- /dev/null +++ b/test/HealthChecks.Solr.Tests/Resources/solr/configsets/solrcoredown/conf/solrconfig.xml @@ -0,0 +1,1230 @@ + + + + + + + + + 8.4.1 + + + + + + + + + + + ${solr.data.dir:} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${solr.lock.type:native} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${solr.ulog.dir:} + ${solr.ulog.numVersionBuckets:65536} + + + + + ${solr.autoCommit.maxTime:15000} + false + + + + + + ${solr.autoSoftCommit.maxTime:-1} + + + + + + + + + + + + + + ${solr.max.booleanClauses:1024} + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + 20 + + + 200 + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + server-enabled.txt + + *:* + + + + + + explicit + 10 + + + + + + + + + + + + + + + + explicit + json + true + + + + + + _text_ + + + + + + + + + text_general + + + + + + default + _text_ + solr.DirectSolrSpellChecker + + internal + + 0.5 + + 2 + + 1 + + 5 + + 4 + + 0.01 + + + + + + + + + + + + default + on + true + 10 + 5 + 5 + true + true + 10 + 5 + + + spellcheck + + + + + + + + + + true + false + + + terms + + + + + + + + + + + 100 + + + + + + + + 70 + + 0.5 + + [-\w ,/\n\"']{20,200} + + + + + + + ]]> + ]]> + + + + + + + + + + + + + + + + + + + + + + + + ,, + ,, + ,, + ,, + ,]]> + ]]> + + + + + + 10 + .,!? + + + + + + + WORD + + + en + US + + + + + + + + + + + + [^\w-\.] + _ + + + + + + + yyyy-MM-dd['T'[HH:mm[:ss[.SSS]][z + yyyy-MM-dd['T'[HH:mm[:ss[,SSS]][z + yyyy-MM-dd HH:mm[:ss[.SSS]][z + yyyy-MM-dd HH:mm[:ss[,SSS]][z + [EEE, ]dd MMM yyyy HH:mm[:ss] z + EEEE, dd-MMM-yy HH:mm:ss z + EEE MMM ppd HH:mm:ss [z ]yyyy + + + + + java.lang.String + text_general + + *_str + 256 + + + true + + + java.lang.Boolean + booleans + + + java.util.Date + pdates + + + java.lang.Long + java.lang.Integer + plongs + + + java.lang.Number + pdoubles + + + + + + + + + + + + + + + + + + + + text/plain; charset=UTF-8 + + + + + + + + + + + + + + diff --git a/test/HealthChecks.Solr.Tests/SolrContainerFixture.cs b/test/HealthChecks.Solr.Tests/SolrContainerFixture.cs new file mode 100644 index 0000000000..393c1a65c1 --- /dev/null +++ b/test/HealthChecks.Solr.Tests/SolrContainerFixture.cs @@ -0,0 +1,67 @@ +using DotNet.Testcontainers.Builders; +using DotNet.Testcontainers.Containers; + +namespace HealthChecks.Solr.Tests; + +public class SolrContainerFixture : IAsyncLifetime +{ + private const string Registry = "docker.io"; + + private const string Image = "library/solr"; + + private const string Tag = "9.9.0-slim"; + + private const int Port = 8983; + + public IContainer? Container { get; private set; } + + public string GetConnectionString() + { + if (Container is null) + { + throw new InvalidOperationException("The test container was not initialized."); + } + + var endpoint = new UriBuilder(Uri.UriSchemeHttp, Container.Hostname, Container.GetMappedPublicPort(Port)) + { + Path = "/solr" + }; + + return endpoint.ToString(); + } + + public async Task InitializeAsync() => Container = await CreateContainerAsync(); + + public Task DisposeAsync() => Container?.DisposeAsync().AsTask() ?? Task.CompletedTask; + + private static async Task CreateContainerAsync() + { + var waitStrategy = Wait + .ForUnixContainer() + .UntilHttpRequestIsSucceeded(x => x.ForPath("/solr/solrcore/admin/ping").ForPort(Port)); + + string hostConfigSetsPath = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "solr", "configsets"); + + const string configSetsPath = "/opt/solr/server/solr/configsets"; + + var container = new ContainerBuilder() + .WithImage($"{Registry}/{Image}:{Tag}") + .WithResourceMapping( + new DirectoryInfo(Path.Combine(hostConfigSetsPath, "solrcore")), + $"{configSetsPath}/solrcore") + .WithResourceMapping( + new DirectoryInfo(Path.Combine(hostConfigSetsPath, "solrcoredown")), + $"{configSetsPath}/solrcoredown") + .WithCommand( + "sh", + "-c", + $"precreate-core solrcore {configSetsPath}/solrcore && precreate-core solrcoredown {configSetsPath}/solrcoredown && solr-foreground") + .WithPortBinding(Port, true) + .WithWaitStrategy(waitStrategy) + .Build(); + + await container.StartAsync(); + + return container; + } +}