Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 19 additions & 3 deletions .github/workflows/missing-services-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,32 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ClearML_AccessKey: ${{ secrets.ClearML_AccessKey }}
ClearML_SecretKey: ${{ secrets.ClearML_SecretKey }}
CLEARML_GPU_QUEUE: autoscaler
CLEARML_CPU_QUEUE: autoscaler.cpu_only
SERVAL_HOST_URL: http://localhost
SERVAL_AUTH_URL: https://sil-appbuilder.auth0.com

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5

# get version of machine.py - MACHINE_PY_IMAGE will force the docker compose to use the proper version of machine.py
- name: Install regctl
uses: iarekylew00t/regctl-installer@v1

- name: Set proper version of Machine.py
run: |
export MACHINE_PY_IMAGE=ghcr.io/sillsdev/machine.py:$(regctl image config ghcr.io/sillsdev/machine.py | jq -r ".config.Labels[\"org.opencontainers.image.version\"]") && \
echo "MACHINE_PY_IMAGE=$MACHINE_PY_IMAGE" >> $GITHUB_ENV && \
echo "MACHINE_PY_CPU_IMAGE=$MACHINE_PY_IMAGE.cpu_only" >> $GITHUB_ENV

- name: Confirm proper version of Machine.py
run: |
echo $MACHINE_PY_IMAGE $MACHINE_PY_CPU_IMAGE

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v5
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x

- name: Get Machine
run: cd .. && git clone https://github.com/sillsdev/machine.git && cd machine && dotnet build && cd ../serval && dotnet build
Expand Down
6 changes: 2 additions & 4 deletions samples/ApiExample/ApiExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Duende.AccessTokenManagement" Version="3.2.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Duende.AccessTokenManagement" Version="4.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.10" />
<PackageReference Include="Serval.Client" Version="1.12.0" />
</ItemGroup>

Expand Down
10 changes: 6 additions & 4 deletions samples/ApiExample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO.Compression;
using ApiExample;
using Duende.AccessTokenManagement;
using Duende.IdentityModel.Client;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -47,15 +48,15 @@ static ServiceProvider SetupServices()
TokenClientName,
client =>
{
client.TokenEndpoint = servalOptions.TokenUrl;
client.ClientId = servalOptions.ClientId;
client.ClientSecret = servalOptions.ClientSecret;
client.TokenEndpoint = new Uri(servalOptions.TokenUrl, UriKind.Absolute);
client.ClientId = ClientId.Parse(servalOptions.ClientId);
client.ClientSecret = ClientSecret.Parse(servalOptions.ClientSecret);
client.Parameters = new Parameters { { "audience", servalOptions.Audience } };
}
);
services.AddClientCredentialsHttpClient(
HttpClientName,
TokenClientName,
ClientCredentialsClientName.Parse(TokenClientName),
configureClient: client => client.BaseAddress = new Uri(servalOptions.ApiServer)
);
services.AddHttpClient(HttpClientName).SetHandlerLifetime(TimeSpan.FromMinutes(5));
Expand Down Expand Up @@ -188,6 +189,7 @@ async Task CreatePreTranslationEngineAsync(CancellationToken cancellationToken)
// The generated translation will be very, very inaccurate.
JObject options = [];
options.Add("max_steps", 20);
options.Add("tags", "api-example");

// We will train on one book, and translate two books
var translationBuildConfig = new TranslationBuildConfig
Expand Down
35 changes: 28 additions & 7 deletions src/Serval/test/Serval.E2ETests/MissingServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ namespace Serval.E2ETests;

[TestFixture]
[Category("E2EMissingServices")]
[Explicit("These are only run from the missing services E2E tests")]
public class MissingServicesTests
{
private ServalClientHelper _helperClient;

[OneTimeSetUp]
public async Task OneTimeSetup()
{
_helperClient = new ServalClientHelper("https://serval-api.org/", ignoreSSLErrors: true);
await _helperClient.InitAsync();
_helperClient = new ServalClientHelper("https://serval-api.org/", ignoreSslErrors: true);
try
{
await _helperClient.InitAsync();
}
catch (ServalApiException)
{
// An error will be thrown when the services are missing
}
}

[SetUp]
Expand All @@ -37,7 +45,8 @@ public void UseEngineServerAsync()
{
string engineId = await _helperClient.CreateNewEngineAsync("SmtTransfer", "es", "en", "SMT3");
string[] books = ["1JN.txt", "2JN.txt", "3JN.txt"];
await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "en", false);
ParallelCorpusConfig corpus = await _helperClient.MakeParallelTextCorpus(books, "es", "en", false);
await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, corpus, false);
await _helperClient.BuildEngineAsync(engineId);
});
}
Expand Down Expand Up @@ -75,8 +84,12 @@ public async Task UseMissingAWSAsync()
{
string engineId = await _helperClient.CreateNewEngineAsync("Nmt", "es", "en", "NMT1");
string[] books = ["MAT.txt", "1JN.txt", "2JN.txt"];
await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "en", false);
await _helperClient.AddTextCorpusToEngineAsync(engineId, ["3JN.txt"], "es", "en", true);
ParallelCorpusConfig trainCorpus = await _helperClient.MakeParallelTextCorpus(books, "es", "es", true);
await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, trainCorpus, false);
books = ["3JN.txt"];
ParallelCorpusConfig pretranslateCorpus = await _helperClient.MakeParallelTextCorpus(books, "es", "es", true);
await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, pretranslateCorpus, true);

await _helperClient.BuildEngineAsync(engineId);
IList<TranslationBuild> builds = await _helperClient.TranslationEnginesClient.GetAllBuildsAsync(engineId);
Assert.That(builds.First().State, Is.EqualTo(JobState.Faulted));
Expand All @@ -102,7 +115,8 @@ public void UseMissingEngineServerAsync()
{
string engineId = await _helperClient.CreateNewEngineAsync("SmtTransfer", "es", "en", "SMT3");
string[] books = ["1JN.txt", "2JN.txt", "3JN.txt"];
await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "en", false);
ParallelCorpusConfig corpus = await _helperClient.MakeParallelTextCorpus(books, "es", "en", false);
await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, corpus, false);
await _helperClient.BuildEngineAsync(engineId);
});
Assert.That(ex, Is.Not.Null);
Expand All @@ -112,7 +126,14 @@ public void UseMissingEngineServerAsync()
[TearDown]
public async Task TearDown()
{
await _helperClient.TearDown();
try
{
await _helperClient.TearDown();
}
catch (ServalApiException)
{
// An error will be thrown when the services are missing
}
}

[OneTimeTearDown]
Expand Down
19 changes: 16 additions & 3 deletions src/Serval/test/Serval.E2ETests/ServalApiSlowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ namespace Serval.E2ETests;
[TestFixture]
[Category("E2E")]
[Category("slow")]
[Explicit("These are only manually run occasionally due to their speed")]
public class ServalApiSlowTests
{
private ServalClientHelper _helperClient;

[OneTimeSetUp]
public async Task OneTimeSetup()
{
_helperClient = new ServalClientHelper("https://serval-api.org/", ignoreSSLErrors: true);
_helperClient = new ServalClientHelper("https://serval-api.org/", ignoreSslErrors: true);
await _helperClient.InitAsync();
}

Expand All @@ -21,10 +22,22 @@ public void Setup()
}

[Test]
public async Task GetSmtWholeBible()
[Obsolete("Legacy corpora are deprecated")]
public async Task GetSmtWholeBible_LegacyCorpus()
{
string engineId = await _helperClient.CreateNewEngineAsync("SmtTransfer", "es", "en", "SMT2");
await _helperClient.AddTextCorpusToEngineAsync(engineId, ["bible.txt"], "es", "en", false);
await _helperClient.AddLegacyCorpusToEngineAsync(engineId, ["bible.txt"], "es", "en", false);
await _helperClient.BuildEngineAsync(engineId);
TranslationResult tResult = await _helperClient.TranslationEnginesClient.TranslateAsync(engineId, "Espíritu");
Assert.That(tResult.Translation, Is.EqualTo("Spirit"));
}

[Test]
public async Task GetSmtWholeBible_ParallelCorpus()
{
string engineId = await _helperClient.CreateNewEngineAsync("SmtTransfer", "es", "en", "SMT2");
ParallelCorpusConfig trainCorpus = await _helperClient.MakeParallelTextCorpus(["bible.txt"], "es", "en", false);
await _helperClient.AddParallelTextCorpusToEngineAsync(engineId, trainCorpus, false);
await _helperClient.BuildEngineAsync(engineId);
TranslationResult tResult = await _helperClient.TranslationEnginesClient.TranslateAsync(engineId, "Espíritu");
Assert.That(tResult.Translation, Is.EqualTo("Spirit"));
Expand Down
Loading
Loading