From 9315b0a2074aab02ca9d4ebe8bb2dc63c2790336 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 10 Jul 2024 09:29:54 +0100 Subject: [PATCH] Add Integration tests to CI (#19) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Instances base (#6) * Use Uri for checks in GetAccounts function (#8) * Add integration and perf tests to sln (#9) * Remove perf tests (#10) * remove perf tests * do all unit tests * Code coverage (#11) * code coverage * enable codecov for GA * Update README.md * Update coverage and dependencies (#12) * Update coverage and dependencies * fmt * add codecov config * merge DUI3/Alpha into sdk (#13) * merge DUI3/Alpha into sdk * formatting * Merge Objects dui3/alpha -> dev (#14) * merge DUI3/Alpha into sdk * formatting * Objects changes * Objects tests * Unit test project * add coverage exclusion * fix some tests and fix nullability errors * update codecov to be less intrusive (#15) * update codecov to be less intrusive * fix codecov yaml * add coverage exclusion * Merge sharp `dui3/alpha` -> sdk `main` (#16) * Merge * csharpier format * Fixed polysharp issues * Integration Tests * Fixes * add build for docker compose * add integration tests * remove extra services * update healthcheck for server --------- Co-authored-by: Oğuzhan Koral <45078678+oguzhankoral@users.noreply.github.com> Co-authored-by: Jedd Morgan <45512892+JR-Morgan@users.noreply.github.com> --- build/Program.cs | 23 ++++++++- docker-compose.yml | 114 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 docker-compose.yml diff --git a/build/Program.cs b/build/Program.cs index e276da07..bdb5f21f 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -1,4 +1,4 @@ -using GlobExpressions; +using GlobExpressions; using static Bullseye.Targets; using static SimpleExec.Command; @@ -9,6 +9,7 @@ const string RESTORE = "restore"; const string BUILD = "build"; const string TEST = "test"; +const string INTEGRATION = "integration"; const string PACK = "pack"; Target( @@ -58,8 +59,26 @@ await RunAsync( } ); +Target( + INTEGRATION, + DependsOn(BUILD), + async () => + { + await RunAsync("docker", "compose -f docker-compose.yml up --wait"); + foreach (var test in Glob.Files(".", "**/*.Tests.Integration.csproj").Concat(Glob.Files(".", "**/*.Tests.csproj"))) + { + await RunAsync( + "dotnet", + $"test {test} -c Release --no-build --no-restore --verbosity=normal /p:AltCover=true /p:AltCoverAttributeFilter=ExcludeFromCodeCoverage" + ); + } + + await RunAsync("docker", "compose down"); + } +); + Target(PACK, DependsOn(TEST), () => RunAsync("dotnet", "pack Speckle.Sdk.sln -c Release -o output --no-build")); -Target("default", DependsOn(FORMAT, TEST), () => Console.WriteLine("Done!")); +Target("default", DependsOn(FORMAT, TEST, INTEGRATION), () => Console.WriteLine("Done!")); await RunTargetsAndExitAsync(args).ConfigureAwait(true); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..7c2ce420 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,114 @@ +version: "3.9" +name: "speckle-server" + +services: + #### + # Speckle Server dependencies + ####### + postgres: + image: "postgres:14.5-alpine" + restart: always + environment: + POSTGRES_DB: speckle + POSTGRES_USER: speckle + POSTGRES_PASSWORD: speckle + volumes: + - postgres-data:/var/lib/postgresql/data/ + healthcheck: + # the -U user has to match the POSTGRES_USER value + test: ["CMD-SHELL", "pg_isready -U speckle"] + interval: 5s + timeout: 5s + retries: 30 + + redis: + image: "redis:6.0-alpine" + restart: always + volumes: + - redis-data:/data + healthcheck: + test: ["CMD", "redis-cli", "--raw", "incr", "ping"] + interval: 5s + timeout: 5s + retries: 30 + + minio: + image: "minio/minio:RELEASE.2023-10-25T06-33-25Z" + command: server /data --console-address ":9001" + restart: always + volumes: + - minio-data:/data + healthcheck: + test: + [ + "CMD-SHELL", + "curl -s -o /dev/null http://127.0.0.1:9000/minio/index.html", + ] + interval: 5s + timeout: 30s + retries: 30 + start_period: 10s + + #### + # Speckle Server + ####### + + speckle-server: + image: speckle/speckle-server:latest + restart: always + healthcheck: + test: + - CMD + - node + - -e + - "try { require('node:http').request({headers: {'Content-Type': 'application/json'}, port:3000, hostname:'127.0.0.1', path:'/liveness', method: 'GET', timeout: 2000 }, (res) => { body = ''; res.on('data', (chunk) => {body += chunk;}); res.on('end', () => {process.exit(res.statusCode != 200 || body.toLowerCase().includes('error'));}); }).end(); } catch { process.exit(1); }" + interval: 10s + timeout: 10s + retries: 3 + start_period: 90s + ports: + - "0.0.0.0:3000:3000" + depends_on: + postgres: + condition: service_healthy + redis: + condition: service_healthy + minio: + condition: service_healthy + environment: + # TODO: Change this to the URL of the speckle server, as accessed from the network + CANONICAL_URL: "http://127.0.0.1:8080" + SPECKLE_AUTOMATE_URL: "http://127.0.0.1:3030" + + # TODO: Change thvolumes: + REDIS_URL: "redis://redis" + + S3_ENDPOINT: "http://minio:9000" + S3_ACCESS_KEY: "minioadmin" + S3_SECRET_KEY: "minioadmin" + S3_BUCKET: "speckle-server" + S3_CREATE_BUCKET: "true" + + FILE_SIZE_LIMIT_MB: 100 + MAX_PROJECT_MODELS_PER_PAGE: 500 + + # TODO: Change this to a unique secret for this server + SESSION_SECRET: "TODO:ReplaceWithLongString" + + STRATEGY_LOCAL: "true" + DEBUG: "speckle:*" + + POSTGRES_URL: "postgres" + POSTGRES_USER: "speckle" + POSTGRES_PASSWORD: "speckle" + POSTGRES_DB: "speckle" + ENABLE_MP: "false" + +networks: + default: + name: speckle-server + +volumes: + postgres-data: + redis-data: + minio-data: