Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facade job creation tests #10

Merged
merged 52 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
c96e4f4
Sample AI task
pwalski Nov 15, 2023
9b47bdb
Build of sample AI app
pwalski Nov 15, 2023
a3f01c2
Test console logging. Current job test WIP.
pwalski Nov 16, 2023
e90e311
Merge branch 'master' into facade-job-creation-tests
pwalski Nov 16, 2023
b0f52e1
JobTests WIP
pwalski Nov 18, 2023
785016f
Job tests. Relay and requestor startup/shutdown. WIP
pwalski Nov 20, 2023
cecfdf6
JobTests. Yagna data dir. WIP
pwalski Nov 20, 2023
b9c6f88
JobTests. Yagna account/payment init. WIP
pwalski Nov 20, 2023
45a3ae3
JobTests. Yagna account/payment init. WIP
pwalski Nov 20, 2023
9cdc042
JobTests currentJob check WIP
pwalski Nov 20, 2023
b3c61b4
JobTests WIP
pwalski Nov 21, 2023
fea6e58
Merge remote-tracking branch 'origin/master' into facade-job-creation…
pwalski Nov 21, 2023
f08a51d
JobTests patching runtime descriptor
pwalski Nov 21, 2023
a371ef3
Avoid re-downloading sample app dependencies
pwalski Nov 22, 2023
7a1a477
JobsTest paths with correct separator
pwalski Nov 22, 2023
a011fd0
Avoid re-downloading sample app dependencies. csproj cleanup
pwalski Nov 22, 2023
ae04fbf
Child test process shutdown hook
pwalski Nov 22, 2023
cac6444
EXE_UNIT_PATH pattern update
pwalski Nov 22, 2023
36087ac
Runtime version update. Runtime renamed to 'ai'. Reusing old relay di…
pwalski Nov 22, 2023
76ea965
Merge branch 'master' into facade-job-creation-tests
pwalski Nov 22, 2023
5d75f3a
Better display commands stdout and stderr
nieznanysprawiciel Nov 22, 2023
7021fb1
Default YA_NET_RELAY_HOST disabled. Fmt.
pwalski Nov 23, 2023
bc01ffa
GUI ya-provider run cmd process startup bugfix
pwalski Nov 23, 2023
56d337c
Sample app startup bugfix
pwalski Nov 23, 2023
0f157f6
ya-relay-server version update
pwalski Nov 23, 2023
9201a66
JobTests waiting for status/job change using channels.
pwalski Nov 24, 2023
7703d5e
JobTests closing sample app using sigint
pwalski Nov 24, 2023
4880438
JobTests closing relay using sigkill
pwalski Nov 24, 2023
69ac0ce
JobTests test processes started using MedallionShell
pwalski Nov 24, 2023
3d06516
Artifacts downloaded to temp dir.
pwalski Nov 25, 2023
f6e89cf
JobTests facade file logging
pwalski Nov 25, 2023
49ea4fc
JobTests test logging through diagnostic messages
pwalski Nov 26, 2023
56c271e
Requestor graceful shutdown
pwalski Nov 26, 2023
41d8241
PropertyChangedHandler supporting of nullables
pwalski Nov 26, 2023
278ab1a
JobTests closing relay using sigint
pwalski Nov 26, 2023
580ca1b
Reusing requestor data dir (to not upset faucet)
pwalski Nov 26, 2023
551d6a5
Linux test bugfix
pwalski Nov 26, 2023
27db3f7
Test expanding archive bugfix
pwalski Nov 27, 2023
59a9673
CI test diag verbosity
pwalski Nov 27, 2023
439238c
JobTest assert requestor id and job status
pwalski Nov 27, 2023
9d65a51
JobTest payment fund error handling bugfix. Unified string formatting.
pwalski Nov 27, 2023
2a44952
JobTest printing test utils logs through logger
pwalski Nov 27, 2023
9211616
JobTest file logger disabled
pwalski Nov 27, 2023
d9d3801
JobTests yagna, ya-provider, and yapapi logs
pwalski Nov 27, 2023
3f2fd8b
JobTests yagna, ya-provider, and yapapi logs. Always uploading.
pwalski Nov 27, 2023
f02d3af
JobTests release allocations when reusing requestor data dir
pwalski Nov 27, 2023
180857f
JobTests yagna, ya-provider, and yapapi logs. OS specific archives.
pwalski Nov 27, 2023
544c2aa
JobTests sample app allocation of 1 glm.
pwalski Nov 27, 2023
ce7c6cf
JobTests gftp on sample app PATH
pwalski Nov 27, 2023
44bbfbe
Warnings cleanup
pwalski Nov 27, 2023
1e838a5
Warnings cleanup bugfix
pwalski Nov 27, 2023
41533c5
Revert "Warnings cleanup"
pwalski Nov 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,19 @@ jobs:
- name: Build
run: dotnet build
- name: Test with the dotnet CLI
run: dotnet test
run: dotnet test -v diag
- name: Archive JobTests artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: JobTests_${{ matrix.os }}
path: |
Golem.Tests/tests/JobTests/modules/golem-data/yagna/*.log
Golem.Tests/tests/JobTests/modules/golem-data/provider/*.log
- name: Archive JobTests requestor artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: JobTests_requestor_${{ matrix.os }}
path: |
Golem.Tests/tests/JobTests_requestor/modules/golem-data/yagna/*.log
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Mock/obj/
/Golem.Tests/bin/
/Golem.Tests/obj/
/Golem.Tests/tests/
/Golem.Tests/TestResults
/Golem.Tests/Tools/App/.venv
/Golem.Tests/Tools/App/build
/Golem.Tests/Tools/App/dist
/Golem.Tests/Tools/App/app.spec
/MockGUI/bin/
/MockGUI/obj/
/modules/
27 changes: 25 additions & 2 deletions Golem.Tests/Golem.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="MedallionShell" Version="1.6.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand All @@ -23,11 +25,32 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="XunitContext" Version="3.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GolemLib\GolemLib.csproj" />
<ProjectReference Include="..\Golem\Golem.csproj" />
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<Target Name="AfterClean">
<RemoveDir Directories="$(ProjectDir)\bin\$(Configuration)\net7.0\app\" ContinueOnError="true" />
<RemoveDir Directories="$(ProjectDir)\Tools\App\dist" ContinueOnError="true" />
<RemoveDir Directories="$(ProjectDir)\Tools\App\build" ContinueOnError="true" />
</Target>

<Target Name="BuildApp" BeforeTargets="Test" AfterTargets="AfterBuild">
<Exec Command="python -m venv .venv" WorkingDirectory="$(ProjectDir)\Tools\App" ConsoleToMsBuild="true" />
<Exec Command=".\.venv\Scripts\activate | pip install -r requirements.txt" Condition="'$(OS)' == 'WINDOWS_NT'" WorkingDirectory="$(ProjectDir)\Tools\App" ConsoleToMsBuild="true" />
<Exec Command=".\.venv\Scripts\activate | pyinstaller --onefile app.py -y" Condition="'$(OS)' == 'WINDOWS_NT'" WorkingDirectory="$(ProjectDir)\Tools\App" ConsoleToMsBuild="true" />
<Exec Command=". .venv/bin/activate; pip install -r requirements.txt" Condition="'$(OS)' != 'WINDOWS_NT'" WorkingDirectory="$(ProjectDir)\Tools\App" ConsoleToMsBuild="true" />
<Exec Command=". .venv/bin/activate; pyinstaller --onefile app.py -y" Condition="'$(OS)' != 'WINDOWS_NT'" WorkingDirectory="$(ProjectDir)\Tools\App" ConsoleToMsBuild="true" />
<RemoveDir Directories="$(ProjectDir)\bin\$(Configuration)\net7.0\app" ContinueOnError="true" />
<ItemGroup>
<AppBinary Include="$(ProjectDir)Tools\App\dist\*.*" />
</ItemGroup>
<Copy SourceFiles="@(AppBinary)" DestinationFolder="$(ProjectDir)bin\$(Configuration)\net7.0\app\" />
</Target>

</Project>
28 changes: 22 additions & 6 deletions Golem.Tests/GolemTests.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
using App;

using Golem;
using Golem.IntegrationTests.Tools;
using Golem.Yagna.Types;

using GolemLib;
using GolemLib.Types;

using Microsoft.Extensions.Logging;

namespace Golem.Tests
{
[Collection("Sequential")]
public class GolemTests
public class GolemTests : IDisposable
{
readonly ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
builder.AddSimpleConsole(options => options.SingleLine = true)
private readonly ILoggerFactory _loggerFactory;

public GolemTests(ITestOutputHelper outputHelper)
{
XunitContext.Register(outputHelper);
_loggerFactory = LoggerFactory.Create(builder =>
builder.AddSimpleConsole(options => options.SingleLine = true)
);
}

[Fact]
public async Task StartStop_VerifyStatusAsync()
{
string golemPath = await PackageBuilder.BuildTestDirectory("StartStop_VerifyStatusAsync");
Console.WriteLine("Path: " + golemPath);

var golem = new Golem(PackageBuilder.BinariesDir(golemPath), PackageBuilder.DataDir(golemPath), loggerFactory);
var golem = new Golem(PackageBuilder.BinariesDir(golemPath), PackageBuilder.DataDir(golemPath), _loggerFactory);
GolemStatus status = GolemStatus.Off;

Action<GolemStatus> updateStatus = (v) =>
Expand Down Expand Up @@ -54,7 +65,7 @@ public async Task Start_ChangeWallet_VerifyStatusAsync()
string golemPath = await PackageBuilder.BuildTestDirectory("Start_ChangeWallet_VerifyStatusAsync");
Console.WriteLine("Path: " + golemPath);

var golem = new Golem(PackageBuilder.BinariesDir(golemPath), PackageBuilder.DataDir(golemPath), loggerFactory);
var golem = new Golem(PackageBuilder.BinariesDir(golemPath), PackageBuilder.DataDir(golemPath), _loggerFactory);
GolemStatus status = GolemStatus.Off;

Action<GolemStatus> updateStatus = (v) =>
Expand All @@ -79,7 +90,7 @@ public async Task Start_ChangePrices_VerifyPriceAsync()
string golemPath = await PackageBuilder.BuildTestDirectory("Start_ChangePrices_VerifyPriceAsync");
Console.WriteLine("Path: " + golemPath);

var golem = new Golem(PackageBuilder.BinariesDir(golemPath), PackageBuilder.DataDir(golemPath), loggerFactory);
var golem = new Golem(PackageBuilder.BinariesDir(golemPath), PackageBuilder.DataDir(golemPath), _loggerFactory);

decimal price = 0;

Expand Down Expand Up @@ -110,5 +121,10 @@ public async Task Start_ChangePrices_VerifyPriceAsync()
Assert.Equal(0.007m, golem.Price.EnvPerHour);
Assert.Equal(0.008m, golem.Price.NumRequests);
}

public void Dispose()
{
XunitContext.Flush();
}
}
}
159 changes: 159 additions & 0 deletions Golem.Tests/JobTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using System.Threading.Channels;

using App;

using Golem;
using Golem.IntegrationTests.Tools;
using Golem.Yagna;
using Golem.Yagna.Types;

using GolemLib;
using GolemLib.Types;

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Configuration;

using Xunit.Abstractions;
using Xunit.Sdk;

namespace Golem.Tests
{

public class GolemFixture : IDisposable
{
public GolemFixture(IMessageSink sink)
{
Sink = sink;
}

public IMessageSink Sink { get; }

public void Dispose()
{
}
}

[Collection("Sequential")]
public class JobTests : IDisposable, IAsyncLifetime, IClassFixture<GolemFixture>
{
private readonly ILoggerFactory _loggerFactory;
private readonly ILogger _logger;
private GolemRelay? _relay;
private GolemRequestor? _requestor;

public JobTests(ITestOutputHelper outputHelper, GolemFixture golemFixture)
{
XunitContext.Register(outputHelper);
// var logfile = Path.Combine(PackageBuilder.TestDir(nameof(JobTests)), "gh_facade-{Date}.log");
var loggerProvider = new TestLoggerProvider(golemFixture.Sink);
_logger = loggerProvider.CreateLogger(nameof(JobTests));
_loggerFactory = LoggerFactory.Create(builder => builder
.AddSimpleConsole(options => options.SingleLine = true)
// .AddFile(logfile)
.AddProvider(loggerProvider)
);
}

public async Task InitializeAsync()
{
_relay = await GolemRelay.Build(nameof(JobTests), _loggerFactory.CreateLogger("Relay"));
Assert.True(_relay.Start());
System.Environment.SetEnvironmentVariable("YA_NET_RELAY_HOST", "127.0.0.1:17464");
System.Environment.SetEnvironmentVariable("RUST_LOG", "debug");

_requestor = await GolemRequestor.Build(nameof(JobTests), _loggerFactory.CreateLogger("Requestor"), false);
Assert.True(_requestor.Start());
_requestor.InitAccount();
}

[Fact]
public async Task StartStop_Job()
{
string golemPath = await PackageBuilder.BuildTestDirectory(nameof(JobTests));
_logger.LogInformation($"Path: {golemPath}");
var golem = new Golem(PackageBuilder.BinariesDir(golemPath), PackageBuilder.DataDir(golemPath), _loggerFactory);

var statusChannel = Channel.CreateUnbounded<GolemStatus>();
Action<GolemStatus> golemStatus = async (v) =>
{
_logger.LogInformation($"Golem status update. {v}");
await statusChannel.Writer.WriteAsync(v);
};
golem.PropertyChanged += new PropertyChangedHandler<Golem, GolemStatus>(nameof(IGolem.Status), golemStatus).Subscribe();

var jobChannel = Channel.CreateUnbounded<IJob?>();
Action<IJob?> currentJobHook = async (v) =>
{
_logger.LogInformation($"Current Job update. {v}");
await jobChannel.Writer.WriteAsync(v);
};
golem.PropertyChanged += new PropertyChangedHandler<Golem, IJob?>(nameof(IGolem.CurrentJob), currentJobHook).Subscribe();

_logger.LogInformation("Starting Golem");
await golem.Start();
Assert.Equal(GolemStatus.Starting, await statusChannel.Reader.ReadAsync());
GolemStatus? status = GolemStatus.Starting;
while ((status = await statusChannel.Reader.ReadAsync()) == GolemStatus.Starting)
{
_logger.LogInformation("Still starting");
}
Assert.Equal(status, GolemStatus.Ready);

Assert.Null(golem.CurrentJob);

_logger.LogInformation("Starting App");
var app = _requestor?.CreateSampleApp() ?? throw new Exception("Requestor not started yet");
Assert.True(app.Start());

var jobStartCounter = 0;
IJob? job = null;
while ((job = await jobChannel.Reader.ReadAsync()) == null && jobStartCounter++ < 100)
{
_logger.LogInformation("Still no job");
}
_logger.LogInformation($"Got a job. Status {golem.CurrentJob?.Status}, Id: {golem.CurrentJob?.Id}, RequestorId: {golem.CurrentJob?.RequestorId}");

Assert.NotNull(golem.CurrentJob);
Assert.Equal(golem.CurrentJob.RequestorId, _requestor?.AppKey?.Id);
Assert.Equal(golem.CurrentJob?.Status, JobStatus.Idle);

_logger.LogInformation("Stopping App");
await app.Stop(StopMethod.SigInt);

var jobStopCounter = 0;
while ((job = await jobChannel.Reader.ReadAsync()) != null && jobStopCounter++ < 100)
{
_logger.LogInformation($"Still has a job. Status: {job.Status}, Id: {job.Id}, RequestorId: {job.RequestorId}");
}
_logger.LogInformation("No more jobs");
Assert.Null(golem.CurrentJob);

_logger.LogInformation("Stopping Golem");
await golem.Stop();

var golemStopCounter = 0;
while ((status = await statusChannel.Reader.ReadAsync()) == GolemStatus.Ready && golemStopCounter++ < 100)
{
_logger.LogInformation("Still stopping");
}
Assert.Equal(status, GolemStatus.Off);
}

public async Task DisposeAsync()
{
if (_requestor != null)
{
await _requestor.Stop(StopMethod.SigInt);
}
if (_relay != null)
{
await _relay.Stop(StopMethod.SigInt);
}
}

public void Dispose()
{
XunitContext.Flush();
}
}
}
Empty file.
Loading
Loading