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

Improve scaling of Kubernetes end-to-end integration test #504

Merged
merged 3 commits into from
Dec 21, 2020
Merged
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
20 changes: 14 additions & 6 deletions test/MLOps.NET.SQLite.IntegrationTests/KubernetesEndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using MLOps.NET.SQLite.IntegrationTests.Schema;
using MLOps.NET.Tests.Common.Configuration;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
Expand Down Expand Up @@ -45,7 +46,10 @@ public async Task DeployModel_GivenACompleteRun_ShouldDeployModelToContainer()
//Arrange and Act
var mlContext = new MLContext(seed: 2);

var run = await sut.LifeCycle.CreateRunAsync("titanic");
var seed = new Random().Next(0, 1000);
var experimentName = $"titanic-{seed}";

var run = await sut.LifeCycle.CreateRunAsync(experimentName);

var data = mlContext.Data.LoadFromTextFile<ModelInput>("Data/titanic.csv", hasHeader: true, separatorChar: ',');
var testTrainTest = mlContext.Data.TrainTestSplit(data);
Expand Down Expand Up @@ -78,7 +82,7 @@ public async Task DeployModel_GivenACompleteRun_ShouldDeployModelToContainer()
var response = await CallDeployedApi(deployment);
response.IsSuccessStatusCode.Should().BeTrue();

await CleanUpKubernetesResourcesAsync();
await CleanUpKubernetesResourcesAsync(experimentName);
}

[TestMethod]
Expand All @@ -87,7 +91,11 @@ public async Task DeployModel_GivenACompleteRunWithRegisteredSchema_ShouldDeploy
//Arrange and Act
var mlContext = new MLContext(seed: 2);

var run = await sut.LifeCycle.CreateRunAsync("titanic");
var seed = new Random().Next(0, 1000);
var experimentName = $"titanic-{seed}";

var run = await sut.LifeCycle.CreateRunAsync(experimentName);

await sut.LifeCycle.RegisterModelSchema<ModelInput, ModelOutput>(run.RunId);

var data = mlContext.Data.LoadFromTextFile<ModelInput>("Data/titanic.csv", hasHeader: true, separatorChar: ',');
Expand Down Expand Up @@ -121,7 +129,7 @@ public async Task DeployModel_GivenACompleteRunWithRegisteredSchema_ShouldDeploy
var response = await CallDeployedApi(deployment);
response.IsSuccessStatusCode.Should().BeTrue();

await CleanUpKubernetesResourcesAsync();
await CleanUpKubernetesResourcesAsync(experimentName);
}

[ExpectedException(typeof(ModelSchemaNotRegisteredException))]
Expand Down Expand Up @@ -178,11 +186,11 @@ private async Task<HttpResponseMessage> CallDeployedApi(Deployment deployment)
return await client.PostAsync(deployment.DeploymentUri, requestMessage);
}

private async Task CleanUpKubernetesResourcesAsync()
private async Task CleanUpKubernetesResourcesAsync(string experimentName)
{
var path = SetKubeConfig(ConfigurationFactory.GetConfiguration()[ConfigurationKeys.KubeConfig]);

await Cli.Wrap("kubectl").WithArguments($"delete ns titanic-test --kubeconfig {path}").ExecuteBufferedAsync();
await Cli.Wrap("kubectl").WithArguments($"delete ns {experimentName}-test --kubeconfig {path}").ExecuteBufferedAsync();
}

private static string SetKubeConfig(string kubeconfigPathOrContent)
Expand Down