Skip to content

Commit

Permalink
Merge pull request #8 from microsoft/updating-integration-test
Browse files Browse the repository at this point in the history
Updating integration test to ensure Pod gets to Running status
  • Loading branch information
bradarm authored Jul 22, 2024
2 parents 9fbcf33 + c816f65 commit e1743df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"app_name": "platform-deployment",
"app_type": "sdk-service",
"addl_debug_shim_suffixes": "client",
"debug_shim_post_yaml_file": "/workspace/platform-deployment/.vscode/debugShim-svcAcct-clusterAdmin.yaml",
"smb_enabled_in_cluster": "true"
"debug_shim_post_yaml_file": "/workspace/platform-deployment/.vscode/debugShim-svcAcct-clusterAdmin.yaml"
}
},
"customizations": {
Expand Down
2 changes: 1 addition & 1 deletion test/integrationTests/TestSharedContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TestSharedContext : IDisposable {
internal static k8s.Kubernetes K8S_CLIENT = null!;
internal static Core.Client SPACEFX_CLIENT = null!;
internal static bool HOST_SVC_ONLINE = false;
internal static TimeSpan MAX_TIMESPAN_TO_WAIT_FOR_MSG = TimeSpan.FromSeconds(90);
internal static TimeSpan MAX_TIMESPAN_TO_WAIT_FOR_MSG = TimeSpan.FromSeconds(300);

/// <summary>
/// Setup the SpaceFx Core to be shared across tests
Expand Down
32 changes: 17 additions & 15 deletions test/integrationTests/Tests/DeploymentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public DeploymentTests(TestSharedContext context) {
[Fact]
public async Task DeployAnApp() {
const string testName = nameof(DeployAnApp);
bool podFound = false;
k8s.Models.V1Pod? integrationPod = null;
DateTime maxTimeToWait = DateTime.Now.Add(TestSharedContext.MAX_TIMESPAN_TO_WAIT_FOR_MSG);
MessageFormats.HostServices.Link.LinkResponse? jsonFileResponse = null;
MessageFormats.HostServices.Link.LinkResponse? yamlFileResponse = null;
Expand All @@ -27,8 +27,8 @@ public async Task DeployAnApp() {

var result = await TestSharedContext.K8S_CLIENT.CoreV1.ListPodForAllNamespacesWithHttpMessagesAsync(allowWatchBookmarks: false, watch: false, pretty: true);
podList = result.Body as k8s.Models.V1PodList ?? throw new Exception("Failed to get Pod List");
podFound = podList.Items.Any(pod => pod.Name().Contains("integration-test", StringComparison.CurrentCultureIgnoreCase));
Assert.False(podFound);
integrationPod = podList.Items.FirstOrDefault(pod => pod.Name().Contains("integration-test", StringComparison.CurrentCultureIgnoreCase));
Assert.Null(integrationPod);

Console.WriteLine("Integration Test Pod not found. Continuing with test");

Expand Down Expand Up @@ -131,16 +131,18 @@ void LinkResponseEventHandler(object? _, MessageFormats.HostServices.Link.LinkRe
DateTime maxTimeToWaitForDeployment = DateTime.Now.Add(TestSharedContext.MAX_TIMESPAN_TO_WAIT_FOR_MSG);
Console.WriteLine("Starting polling to wait for deployment...");

while (!podFound && DateTime.Now <= maxTimeToWaitForDeployment) {
while (integrationPod == null && DateTime.Now <= maxTimeToWaitForDeployment) {
result = await TestSharedContext.K8S_CLIENT.CoreV1.ListPodForAllNamespacesWithHttpMessagesAsync(allowWatchBookmarks: false, watch: false, pretty: true);
podList = result.Body as k8s.Models.V1PodList ?? throw new Exception("Failed to get Pod List");
podFound = podList.Items.Any(pod => pod.Name().Contains("integration-test", StringComparison.CurrentCultureIgnoreCase));
Console.WriteLine($"...pod found: {podFound}");
if (!podFound) await Task.Delay(5000);
integrationPod = podList.Items.FirstOrDefault(pod => pod.Name().Contains("integration-test", StringComparison.CurrentCultureIgnoreCase) && pod.Status.Phase == "Running");
Console.WriteLine($"...pod found: {integrationPod == null}");
if (integrationPod == null)
await Task.Delay(5000);
}

if (podFound == false) throw new TimeoutException($"Failed to find deployment after {TestSharedContext.MAX_TIMESPAN_TO_WAIT_FOR_MSG}. Please check that {TestSharedContext.TARGET_SVC_APP_ID} is deployed");
Assert.True(podFound);
if (integrationPod == null || integrationPod?.Status.Phase == "Pending") throw new TimeoutException($"Failed to find deployment after {TestSharedContext.MAX_TIMESPAN_TO_WAIT_FOR_MSG}. Please check that {TestSharedContext.TARGET_SVC_APP_ID} is deployed");
Assert.NotNull(integrationPod);
Assert.Equal("Running", integrationPod.Status.Phase);

string recdFile = Path.Combine((await TestSharedContext.SPACEFX_CLIENT.GetXFerDirectories()).inbox_directory, "astronaut.jpg");

Expand All @@ -158,20 +160,20 @@ void LinkResponseEventHandler(object? _, MessageFormats.HostServices.Link.LinkRe
Console.WriteLine("Integration Test Pod Found. Waiting for deletion (max 3 mins)");
maxTimeToWaitForDeployment = DateTime.Now.Add(TimeSpan.FromMinutes(3));

while (podFound && DateTime.Now <= maxTimeToWaitForDeployment) {
while (integrationPod != null && DateTime.Now <= maxTimeToWaitForDeployment) {
result = await TestSharedContext.K8S_CLIENT.CoreV1.ListPodForAllNamespacesWithHttpMessagesAsync(allowWatchBookmarks: false, watch: false, pretty: true);
podList = result.Body as k8s.Models.V1PodList ?? throw new Exception("Failed to get Pod List");
podFound = podList.Items.Any(pod => pod.Name().Contains("integration-test", StringComparison.CurrentCultureIgnoreCase));
Console.WriteLine($"...pod found: {podFound}");
if (podFound) await Task.Delay(5000);
integrationPod = podList.Items.FirstOrDefault(pod => pod.Name().Contains("integration-test", StringComparison.CurrentCultureIgnoreCase));
Console.WriteLine($"...pod found: {integrationPod != null}");
if (integrationPod != null) await Task.Delay(5000);
}

if (podFound == true) throw new TimeoutException($"Failed to remove deployment after {TimeSpan.FromMinutes(3)}. Please check that {TestSharedContext.TARGET_SVC_APP_ID} is deployed");
if (integrationPod != null) throw new TimeoutException($"Failed to remove deployment after {TimeSpan.FromMinutes(3)}. Please check that {TestSharedContext.TARGET_SVC_APP_ID} is deployed");




Console.WriteLine("Integration Test Pod successfully removed.");
Assert.False(podFound);
Assert.Null(integrationPod);
}
}

0 comments on commit e1743df

Please sign in to comment.