Skip to content

Commit

Permalink
Made requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mudiagaobrikisil committed Oct 21, 2024
1 parent 937c563 commit edf45ea
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 53 deletions.
6 changes: 0 additions & 6 deletions src/Serval/src/Serval.ApiServer/ServalSettings.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/Serval/src/Serval.ApiServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ public void ConfigureServices(IServiceCollection services)
.AddOpenTelemetry()
.WithMetrics(opts => opts.AddAspNetCoreInstrumentation().AddPrometheusExporter());
}
services.Configure<Serval.Shared.Configuration.ServalSettings>(Configuration.GetSection("ServalSettings"));
services.Configure<Bugsnag.Configuration>(Configuration.GetSection("Bugsnag"));
services.AddBugsnag();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Serval/src/Serval.Client/Client.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9816,8 +9816,8 @@ public partial class TranslationBuild
[Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public object? Options { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("servalReleaseVersion", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? ServalReleaseVersion { get; set; } = default!;
[Newtonsoft.Json.JsonProperty("servalVersion", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? ServalVersion { get; set; } = default!;

}

Expand Down
1 change: 1 addition & 0 deletions src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public class ApiOptions

public TimeSpan DefaultHttpRequestTimeout { get; set; } = TimeSpan.FromSeconds(58); // must be less than 60 seconds Cloudflare timeout
public TimeSpan LongPollTimeout { get; set; } = TimeSpan.FromSeconds(40); // must be less than DefaultHttpRequestTimeout
public string ServalVersion { get; set; } = "1.0.0"; // Default value
}
6 changes: 0 additions & 6 deletions src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public record TranslationBuildDto
/// }
/// </example>
public object? Options { get; init; }
public string? ServalReleaseVersion { get; init; }
public string? ServalVersion { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class TranslationEnginesController(
IPretranslationService pretranslationService,
IOptionsMonitor<ApiOptions> apiOptions,
IUrlService urlService,
ILogger<TranslationEnginesController> logger,
IOptions<ServalSettings> servalSettingsOptions
ILogger<TranslationEnginesController> logger
) : ServalControllerBase(authService)
{
private static readonly JsonSerializerOptions ObjectJsonSerializerOptions =
Expand All @@ -23,7 +22,8 @@ IOptions<ServalSettings> servalSettingsOptions
private readonly IOptionsMonitor<ApiOptions> _apiOptions = apiOptions;
private readonly IUrlService _urlService = urlService;
private readonly ILogger<TranslationEnginesController> _logger = logger;
private readonly ServalSettings _servalSettings = servalSettingsOptions.Value;

// private readonly ServalSettings _servalSettings = apiOptions.Value;

/// <summary>
/// Get all translation engines
Expand Down Expand Up @@ -1508,7 +1508,7 @@ private TranslationBuildDto Map(Build source)
State = source.State,
DateFinished = source.DateFinished,
Options = source.Options,
ServalReleaseVersion = _servalSettings.ReleaseVersion
ServalVersion = _apiOptions.CurrentValue.ServalVersion
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/Serval/src/Serval.Translation/Models/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public record Build : IEntity
public JobState State { get; init; } = JobState.Pending;
public DateTime? DateFinished { get; init; }
public IReadOnlyDictionary<string, object>? Options { get; init; }
public string? ServalReleaseVersion { get; set; }
public string? ServalVersion { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Serval.ApiServer;

[TestFixture]
[Category("Integration")]
public class TranslationEngineTests
public class TranslationEngineTests(IOptionsMonitor<ApiOptions> apiOptions, TranslationEngineTests.TestEnvironment env)
{
private static readonly TranslationCorpusConfig TestCorpusConfig =
new()
Expand Down Expand Up @@ -74,8 +74,9 @@ public class TranslationEngineTests
private const string TARGET_CORPUS_ID = "cc0000000000000000000002";
private const string DOES_NOT_EXIST_ENGINE_ID = "e00000000000000000000004";
private const string DOES_NOT_EXIST_CORPUS_ID = "c00000000000000000000001";
private readonly IOptionsMonitor<ApiOptions> _apiOptions = apiOptions;

private TestEnvironment _env;
private TestEnvironment _env = env;

[SetUp]
public async Task SetUp()
Expand Down Expand Up @@ -1391,6 +1392,12 @@ public async Task StartBuildForEngineByIdAsync(IEnumerable<string> scope, int ex

build = await client.GetCurrentBuildAsync(engineId);
Assert.That(build, Is.Not.Null);

// Fetch and assert ServalVersion from ApiOptions
// ApiOptions apiOptions = _env.GetRequiredService<IOptionsMonitor<ApiOptions>>().CurrentValue;
Assert.That(_apiOptions.CurrentValue.ServalVersion, Is.Not.Null);
// Assert.That(apiOptions.ServalVersion, Is.EqualTo("expected_version")); // Replace with the actual expected version

break;
case 400:
case 403:
Expand Down Expand Up @@ -1891,7 +1898,7 @@ public void TearDown()
_env.Dispose();
}

private class TestEnvironment : DisposableBase
public class TestEnvironment : DisposableBase
{
private readonly IServiceScope _scope;
private readonly MongoClient _mongoClient;
Expand Down
29 changes: 0 additions & 29 deletions src/Serval/test/Serval.E2ETests/ServalApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,6 @@ public async Task GetEchoPretranslate()
Assert.That(pretranslations, Has.Count.GreaterThan(1));
}

[Test]
public async Task GetServalReleaseVersion()
{
string engineId = await _helperClient.CreateNewEngineAsync("Echo", "es", "es", "Echo2");
string[] books = ["1JN.txt", "2JN.txt"];
await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "es", false);
books = ["3JN.txt"];
string corpusId = await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "es", true);
await _helperClient.BuildEngineAsync(engineId);
IList<Pretranslation> pretranslations = await _helperClient.TranslationEnginesClient.GetAllPretranslationsAsync(
engineId,
corpusId
);
Assert.That(pretranslations, Has.Count.GreaterThan(1));
TranslationBuild build = await _helperClient.TranslationEnginesClient.GetCurrentBuildAsync(engineId);
Assert.That(
build.ServalReleaseVersion,
Is.Not.Null.And.Not.Empty,
"Serval release version should not be null or empty."
);

var hasServalReleaseVersionProperty = typeof(TranslationBuild).GetProperty("ServalReleaseVersion") != null;
Assert.That(
hasServalReleaseVersionProperty,
Is.True,
"ServalReleaseVersion property should exist in the build."
);
}

[Test]
public async Task GetSmtTranslation()
{
Expand Down

0 comments on commit edf45ea

Please sign in to comment.