move integration test to minikube proj (#526)
* move integrate test to minikube proj * fix format
This commit is contained in:
@@ -12,6 +12,8 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="5.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="5.0.0" />
|
||||||
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.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" Version="2.4.1" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using k8s.Models;
|
using k8s.Models;
|
||||||
using Microsoft.AspNetCore.JsonPatch;
|
using Microsoft.AspNetCore.JsonPatch;
|
||||||
using Microsoft.Rest;
|
using Microsoft.Rest;
|
||||||
|
using Nito.AsyncEx;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace k8s.E2E
|
namespace k8s.E2E
|
||||||
@@ -155,6 +159,73 @@ namespace k8s.E2E
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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()
|
private static IKubernetes CreateClient()
|
||||||
|
|||||||
@@ -557,76 +557,7 @@ namespace k8s.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[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")]
|
[Fact(Skip = "https://github.com/kubernetes-client/csharp/issues/165")]
|
||||||
public async Task DirectWatchEventsWithTimeout()
|
public async Task DirectWatchEventsWithTimeout()
|
||||||
|
|||||||
Reference in New Issue
Block a user