Skip to content

move integration test to minikube proj #526

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

Merged
merged 2 commits into from
Nov 25, 2020
Merged
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
2 changes: 2 additions & 0 deletions tests/E2E.Tests/E2E.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="5.0.0" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />

<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
71 changes: 71 additions & 0 deletions tests/E2E.Tests/MnikubeTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using k8s.Models;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.Rest;
using Nito.AsyncEx;
using Xunit;

namespace k8s.E2E
Expand Down Expand Up @@ -155,6 +159,73 @@ void Cleanup()
}
}

[MinikubeFact]
public async Task WatcherIntegrationTest()
{
var kubernetes = CreateClient();

var job = await kubernetes.CreateNamespacedJobAsync(
new V1Job()
{
ApiVersion = "batch/v1",
Kind = V1Job.KubeKind,
Metadata = new V1ObjectMeta() { Name = nameof(WatcherIntegrationTest).ToLowerInvariant() },
Spec = new V1JobSpec()
{
Template = new V1PodTemplateSpec()
{
Spec = new V1PodSpec()
{
Containers = new List<V1Container>()
{
new V1Container()
{
Image = "ubuntu",
Name = "runner",
Command = new List<string>() { "/bin/bash", "-c", "--" },
Args = new List<string>()
{
"trap : TERM INT; sleep infinity & wait",
},
},
},
RestartPolicy = "Never",
},
},
},
},
"default").ConfigureAwait(false);

var events = new Collection<Tuple<WatchEventType, V1Job>>();

var started = new AsyncManualResetEvent();
var connectionClosed = new AsyncManualResetEvent();

var watcher = await kubernetes.WatchNamespacedJobAsync(
job.Metadata.Name,
job.Metadata.NamespaceProperty,
resourceVersion: job.Metadata.ResourceVersion,
timeoutSeconds: 30,
onEvent:
(type, source) =>
{
Debug.WriteLine($"Watcher 1: {type}, {source}");
events.Add(new Tuple<WatchEventType, V1Job>(type, source));
job = source;
started.Set();
},
onClosed: connectionClosed.Set).ConfigureAwait(false);

await started.WaitAsync().ConfigureAwait(false);

await Task.WhenAny(connectionClosed.WaitAsync(), Task.Delay(TimeSpan.FromMinutes(3))).ConfigureAwait(false);
Assert.True(connectionClosed.IsSet);

await kubernetes.DeleteNamespacedJobAsync(
job.Metadata.Name,
job.Metadata.NamespaceProperty,
new V1DeleteOptions() { PropagationPolicy = "Foreground" }).ConfigureAwait(false);
}


private static IKubernetes CreateClient()
Expand Down
69 changes: 0 additions & 69 deletions tests/KubernetesClient.Tests/WatchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,76 +557,7 @@ public async Task DirectWatchAllEvents()
}
}

[Fact(Skip = "Integration Test")]
public async Task WatcherIntegrationTest()
{
var kubernetesConfig =
KubernetesClientConfiguration.BuildConfigFromConfigFile(
@"C:\Users\frede\Source\Repos\cloud\minikube.config");
var kubernetes = new Kubernetes(kubernetesConfig);

var job = await kubernetes.CreateNamespacedJobAsync(
new V1Job()
{
ApiVersion = "batch/v1",
Kind = V1Job.KubeKind,
Metadata = new V1ObjectMeta() { Name = nameof(WatcherIntegrationTest).ToLowerInvariant() },
Spec = new V1JobSpec()
{
Template = new V1PodTemplateSpec()
{
Spec = new V1PodSpec()
{
Containers = new List<V1Container>()
{
new V1Container()
{
Image = "ubuntu/xenial",
Name = "runner",
Command = new List<string>() { "/bin/bash", "-c", "--" },
Args = new List<string>()
{
"trap : TERM INT; sleep infinity & wait",
},
},
},
RestartPolicy = "Never",
},
},
},
},
"default").ConfigureAwait(false);

var events = new Collection<Tuple<WatchEventType, V1Job>>();

var started = new AsyncManualResetEvent();
var connectionClosed = new AsyncManualResetEvent();

var watcher = await kubernetes.WatchNamespacedJobAsync(
job.Metadata.Name,
job.Metadata.NamespaceProperty,
resourceVersion: job.Metadata.ResourceVersion,
timeoutSeconds: 30,
onEvent:
(type, source) =>
{
Debug.WriteLine($"Watcher 1: {type}, {source}");
events.Add(new Tuple<WatchEventType, V1Job>(type, source));
job = source;
started.Set();
},
onClosed: connectionClosed.Set).ConfigureAwait(false);

await started.WaitAsync().ConfigureAwait(false);

await Task.WhenAny(connectionClosed.WaitAsync(), Task.Delay(TimeSpan.FromMinutes(3))).ConfigureAwait(false);
Assert.True(connectionClosed.IsSet);

await kubernetes.DeleteNamespacedJobAsync(
job.Metadata.Name,
job.Metadata.NamespaceProperty,
new V1DeleteOptions()).ConfigureAwait(false);
}

[Fact(Skip = "https://github.com/kubernetes-client/csharp/issues/165")]
public async Task DirectWatchEventsWithTimeout()
Expand Down