Skip to content

Commit

Permalink
Added test execution at the end of build process (#244)
Browse files Browse the repository at this point in the history
* Added first test execution at the end of build process

* Added and commente tests on MacOS due to services not available
  • Loading branch information
masesdevelopers authored Jun 24, 2024
1 parent 6e4e5a3 commit 9312fea
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 26 deletions.
85 changes: 81 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,90 @@ jobs:
fetch-depth: '1'
submodules: 'true'

- name: Precompile tests
run: dotnet build --no-incremental --configuration Release /p:Platform="Any CPU" test\KEFCore.Test.sln

- name: Recompile to create nuget packages
run: dotnet build --no-incremental --configuration Release /p:Platform="Any CPU" src\net\KEFCore.sln

- uses: actions/upload-artifact@v4
with:
name: KEFCore
path: .\bin\*nupkg
path: .\bin\*nupkg

- name: Compile tests
run: dotnet build --no-incremental --configuration Release /p:Platform="Any CPU" test\KEFCore.Test.sln

- name: Save KEFCore bin in cache
uses: actions/cache/save@v4
with:
enableCrossOsArchive: true
path: ./bin/
key: KEFCore_bin_${{ github.sha }}

execute_tests:
needs: build_windows
services:
kafka:
# Private registry image
image: ghcr.io/masesgroup/knet:master # to be changed with official version when willbe available
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
ports:
- 9092:9092
env:
KNET_RUNNING_MODE: server
JCOBRIDGE_LicensePath: ${{ secrets.JCOBRIDGE_ONLINE }}

strategy:
fail-fast: false
matrix:
os: [ 'ubuntu-latest' ] #, 'macos-latest', 'macos-13' , 'windows-latest' ]
framework: [ 'net462', 'net6.0', 'net8.0' ]
jdk_vendor: [ 'temurin', 'zulu', 'microsoft', 'corretto', 'oracle']
jdk_version: [ '11', '17', '21' ] # only LTS versions
exclude:
- os: ubuntu-latest
framework: net462
- os: macos-latest
framework: net462
- os: macos-latest
framework: net6.0
- os: macos-13
framework: net462
- os: macos-13
framework: net6.0
- jdk_vendor: oracle
jdk_version: 11

runs-on: ${{ matrix.os }}
steps:
- name: Restore KEFCore bin from cache
uses: actions/cache/restore@v4
with:
fail-on-cache-miss: true
enableCrossOsArchive: true
path: ./bin/
key: KEFCore_bin_${{ github.sha }}

- name: Set up JDK distribution
uses: actions/setup-java@v4
with: # running setup-java again overwrites the settings.xml
distribution: ${{ matrix.jdk_vendor }}
java-version: ${{ matrix.jdk_version }}

- name: Executing MASES.EntityFrameworkCore.KNet.Test.Benchmark on Ubuntu with ${{ matrix.jdk_vendor }} ${{ matrix.jdk_version }}
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' || matrix.os == 'macos-13' }}
run: dotnet ./bin/${{ matrix.framework }}/MASES.EntityFrameworkCore.KNet.Test.Benchmark.dll ./bin/${{ matrix.framework }}/Benchmark.KNetStreams.json localhost:9092
env:
JCOBRIDGE_LicensePath: ${{ secrets.JCOBRIDGE_ONLINE }}

- name: Executing MASES.EntityFrameworkCore.KNet.Test.Benchmark on Windows with ${{ matrix.jdk_vendor }} ${{ matrix.jdk_version }}
if: ${{ matrix.os == 'windows-latest' && matrix.framework != 'net462' }}
run: dotnet .\bin\${{ matrix.framework }}\MASES.EntityFrameworkCore.KNet.Test.Benchmark.dll .\bin\${{ matrix.framework }}\Benchmark.KNetStreams.json localhost:9092
env:
JCOBRIDGE_LicensePath: ${{ secrets.JCOBRIDGE_ONLINE }}

- name: Executing MASES.EntityFrameworkCore.KNet.Test.Benchmark on Windows with ${{ matrix.jdk_vendor }} ${{ matrix.jdk_version }}
if: ${{ matrix.os == 'windows-latest' && matrix.framework == 'net462' }}
run: .\bin\${{ matrix.framework }}\MASES.EntityFrameworkCore.KNet.Test.Benchmark.exe .\bin\${{ matrix.framework }}\Benchmark.KNetStreams.json localhost:9092
env:
JCOBRIDGE_LicensePath: ${{ secrets.JCOBRIDGE_ONLINE }}
6 changes: 6 additions & 0 deletions test/Common/ProgramConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ public static void LoadConfig(string[] args)
Config = JsonSerializer.Deserialize<ProgramConfig>(File.ReadAllText(args[0]));
}
else Config = new();

if (args.Length > 1)
{
Config.BootstrapServers = args[1];
}

ReportString(JsonSerializer.Serialize<ProgramConfig>(Config, new JsonSerializerOptions() { WriteIndented = true }));

if (!KafkaDbContext.EnableKEFCoreTracing) KafkaDbContext.EnableKEFCoreTracing = Config.EnableKEFCoreTracing;
Expand Down
48 changes: 26 additions & 22 deletions test/KEFCore.Benchmark.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,34 +191,38 @@ join pg in context.Posts on op.BlogId equals pg.BlogId
}
finally
{
testWatcher.Stop();
globalWatcher.Stop();
context?.Dispose();
ProgramConfig.ReportString(string.Empty);
ProgramConfig.ReportString($"Full test completed in {globalWatcher.Elapsed}, only tests completed in {testWatcher.Elapsed}");

TimeSpan[] max = new TimeSpan[maxTests];
for (int i = 0; i < max.Length; i++) { max[i] = TimeSpan.Zero; }
TimeSpan[] min = new TimeSpan[maxTests];
for (int i = 0; i < min.Length; i++) { min[i] = TimeSpan.MaxValue; }
TimeSpan[] total = new TimeSpan[maxTests];
for (int i = 0; i < total.Length; i++) { total[i] = TimeSpan.Zero; }
for (int i = 0; i < ProgramConfig.Config.NumberOfExecutions; i++)
try
{
var item = _tests[i].QueryTimes;
testWatcher.Stop();
globalWatcher.Stop();
context?.Dispose();
ProgramConfig.ReportString(string.Empty);
ProgramConfig.ReportString($"Full test completed in {globalWatcher.Elapsed}, only tests completed in {testWatcher.Elapsed}");

TimeSpan[] max = new TimeSpan[maxTests];
for (int i = 0; i < max.Length; i++) { max[i] = TimeSpan.Zero; }
TimeSpan[] min = new TimeSpan[maxTests];
for (int i = 0; i < min.Length; i++) { min[i] = TimeSpan.MaxValue; }
TimeSpan[] total = new TimeSpan[maxTests];
for (int i = 0; i < total.Length; i++) { total[i] = TimeSpan.Zero; }
for (int i = 0; i < ProgramConfig.Config.NumberOfExecutions; i++)
{
var item = _tests[i].QueryTimes;

for (int testId = 0; testId < maxTests; testId++)
{
max[testId] = item[testId] > max[testId] ? item[testId] : max[testId];
min[testId] = item[testId] < min[testId] ? item[testId] : min[testId];
total[testId] += item[testId];
}
}

for (int testId = 0; testId < maxTests; testId++)
{
max[testId] = item[testId] > max[testId] ? item[testId] : max[testId];
min[testId] = item[testId] < min[testId] ? item[testId] : min[testId];
total[testId] += item[testId];
ProgramConfig.ReportString($"Test {testId} -> Max {max[testId]} Min {min[testId]} Mean {total[testId] / ProgramConfig.Config.NumberOfExecutions}");
}
}

for (int testId = 0; testId < maxTests; testId++)
{
ProgramConfig.ReportString($"Test {testId} -> Max {max[testId]} Min {min[testId]} Mean {total[testId] / ProgramConfig.Config.NumberOfExecutions}");
}
catch { ProgramConfig.ReportString($"Failed to report test execution"); }
}
}
}
Expand Down

0 comments on commit 9312fea

Please sign in to comment.