Squashed commit of the following: (#492)
commit dc93612024202e651a9cbe4194c1495c823bff12
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 16:24:33 2020 -0700
fix SA1505
commit dc9fdbc4a4fbce7f4362a24e1ff98be4d27e16a8
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 16:24:02 2020 -0700
add ()
commit 16fb7357fcd7e288a4b8fb201fda2b0aae92e5bc
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 16:21:37 2020 -0700
disable SA1117
commit 544a7e5891e853e2e222f855e5446f3fd79ce2ba
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 16:21:16 2020 -0700
fix SA1508
commit 4e998adf440dda4f13512d1e10f8cb5d5fbc6bd9
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 16:08:28 2020 -0700
allow sa1623
commit baf787255c657a00a6074598c6875e0ab4c9d065
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 16:07:23 2020 -0700
fix SA1413
commit 5ef2ca65de62e6c3cbe513902e3954d78f6dc315
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 16:05:45 2020 -0700
fix SA1413
commit 6cb71f08060b8252a18b01a5788eb2ddcee67c3e
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 06:44:55 2020 -0700
fix throw stack
commit e6ada0b1cb3aa72df5fcaa0b4690aadcbd4bda5a
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 06:44:35 2020 -0700
allow CA2225
commit 2e79edec5843c20b7e8f8e9ec5b61cf95284466a
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 06:35:50 2020 -0700
allow SA1507
commit 108f5a6361f4faa211a8e01f783803295fac0453
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 06:35:31 2020 -0700
force SA1413
commit 20f33b64972bfafeada513ae1a46a030934673fd
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 06:30:58 2020 -0700
force SA1413
commit 6b0de102d68a116e149868731e155bc374f56cc8
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 06:28:33 2020 -0700
fix encoding
commit 4bd8892c2f0e0fa3666e59b0b77f5b23a2e4ca50
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 06:26:00 2020 -0700
fix xunit order
commit e28556b37ecd782df2d740321e782622ecd277ca
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 06:10:20 2020 -0700
fix spacing SA1012 SA1004
commit e8cf4b1e0be951babe04cc3674e17718319b8476
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 06:04:44 2020 -0700
fix SA1211
commit b4164446f7f9d82fb872243e59e3f5c46fbb1f3c
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 06:02:34 2020 -0700
fix attribute related warning
commit 2f17ef45947f6ade36593ede6ba4d27bd1991508
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 05:56:53 2020 -0700
allow ca1801 ca1052 ca1054
commit 49b857f3f1b4a44a809c9186108caab0412c101e
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 05:50:07 2020 -0700
fix SA1001
commit 3389662a32cfc481a3fdf50b6fd651e23aadd9dd
Author: Boshi LIAN <bolian@microsoft.com>
Date: Fri Oct 9 06:24:32 2020 -0700
fix dotnet format
commit f9d55fc925e8a7d2f2b403bd3ae35673068134da
Merge: 8e81532 0d68823
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 05:44:30 2020 -0700
Merge branch 'master' into style_fix0
commit 8e815324040837714efb323580cc5dcd79e58310
Author: Boshi Lian <farmer1992@gmail.com>
Date: Fri Oct 9 05:33:02 2020 -0700
fix remaing build err
commit ecf0152f9e989c4c68274b488d4b3ed6ee88daf9
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 05:24:00 2020 -0700
fix SA1707
commit 462d94794848ebfcd102b56a4344ffc33b50f591
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 05:19:38 2020 -0700
fix underscore naming
commit 5271b113603e469021348523f19555e6be22aebc
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 05:19:12 2020 -0700
allow CA1822
commit 602713ce631026e88d8ff7e8803bb12c2addc3c2
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 04:37:16 2020 -0700
fix CA1822
commit bd4fee4d31c1054eadf6d03aa10f443eee9654c0
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 04:36:36 2020 -0700
fix CA1822
commit 257d461f21ef7df65fbc787d5c42c59a89d0eced
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 04:34:25 2020 -0700
introduce dispose pattern
commit 1d668c7926f877ea196edb67acbfe9bfeddb9e15
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 04:23:09 2020 -0700
allow CA2008
commit e4fa6acaf36b84298c8c2ab125ff8aa9efc097b7
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 04:20:28 2020 -0700
allow CA1827
commit dd931d99fa3a95f936ed566320fffa85efb22838
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 04:14:35 2020 -0700
allow SA1314 CA1825
commit 13b6cf11df439be8020e17bc5d30addc62f90c39
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 04:13:51 2020 -0700
Revert "fix CA1825"
This reverts commit 17e03bcd4e0f129a64e57d54fbe72acb7d1d226b.
commit 368664139c75d61ab5a0c432a7fbbdad956c54cf
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 04:09:52 2020 -0700
move class to single files
commit 0015631805d6bc31e4695881989058bb3955766f
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 04:09:27 2020 -0700
disable CA2000 / TODO
commit 0a1241e84ba1247c8ab4ab8d32bd5d800114420b
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 04:07:23 2020 -0700
allow SA1715
commit 17e03bcd4e0f129a64e57d54fbe72acb7d1d226b
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 04:06:57 2020 -0700
fix CA1825
commit 7baf350ca93cb45e2587d86fb6ab6e4cf665b6da
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 03:42:04 2020 -0700
fix SA1312 SA1306
commit 44ad5934182adfc871215637e9612295bc26e6f2
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 03:30:35 2020 -0700
fix CA2007
commit 325fa2c2d16d541db6e21b791c5170f39f832d43
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 03:25:11 2020 -0700
fix SA1131
commit 8f1f46b065dd7e9b316491676bb0b93ef91d0595
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 03:17:08 2020 -0700
allow SA1119
commit 57c0fe7cc26932cc30b4d7cc75a809746d74d5aa
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 03:14:14 2020 -0700
fix SA1400
commit 0afcbbc09d5ef66fbbd4b291d14e7804a8e5a1d3
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 03:12:18 2020 -0700
fix SA1513
commit 45f2424531d35a2a106e10e788aff1a18d745078
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 03:09:17 2020 -0700
allow ca1720 ca1716 sa1405
commit 3403814130a1bf730c4e275f74e9cf5d03bedb41
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 02:16:37 2020 -0700
fix model oper not contains generated header
commit 11377d916cf8cd3ad9109388aff6cf989ff4b7b0
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 02:14:05 2020 -0700
fix SA1649
commit 92b00051a8c80542a63e1dddbb6eed4e98ad26f9
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 02:11:16 2020 -0700
fix SA1124
commit 901a9dd2426fa316bcc5a3c2fc411e583f0e07df
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 02:09:27 2020 -0700
save 1122
commit a8f17b6bac1f1c115b7ed9ebb70d16697a3e81b7
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 02:09:07 2020 -0700
1507 followup
commit a143184921abb38a09e28a7ef07379003fb19563
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 02:07:38 2020 -0700
fix sa1507
commit 54b56026265cbbbfa6e5b8b4dcfab281ffbfa272
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 02:06:44 2020 -0700
fix sa1513
commit 53a009205c88a1d63d8daf32599bbc6428619638
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 02:05:36 2020 -0700
fix SA1649
commit 26d3e78f61ffc381887baaf5c8b56d92aa0ec563
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 02:01:01 2020 -0700
fix ca1816
commit 1ce5a04ce7a32d901cbece3e18d59e3c068cfd27
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed Oct 7 01:56:43 2020 -0700
readable ruleset
commit dafc55f1c2cdc8466919276291333ba46176161a
Author: Boshi Lian <farmer1992@gmail.com>
Date: Wed May 27 19:13:56 2020 -0700
sync none from guideline
This commit is contained in:
@@ -321,6 +321,7 @@ namespace k8s.Tests
|
||||
Assert.True(listTask.Response.IsSuccessStatusCode);
|
||||
Assert.Equal(1, listTask.Body.Items.Count);
|
||||
}
|
||||
|
||||
{
|
||||
var clientCertificateText = File.ReadAllText("assets/client.crt").Replace("\n", "\\n");
|
||||
var clientCertificateKeyText = File.ReadAllText("assets/client.key").Replace("\n", "\\n");
|
||||
@@ -357,7 +358,6 @@ namespace k8s.Tests
|
||||
}))
|
||||
{
|
||||
{
|
||||
|
||||
var responseJson = $"{{\"apiVersion\":\"testingversion\",\"status\":{{\"token\":\"{token}\"}}}}";
|
||||
var kubernetesConfig = GetK8SConfiguration(server.Uri.ToString(), responseJson, name);
|
||||
var clientConfig = KubernetesClientConfiguration.BuildConfigFromConfigObject(kubernetesConfig, name);
|
||||
@@ -366,6 +366,7 @@ namespace k8s.Tests
|
||||
Assert.True(listTask.Response.IsSuccessStatusCode);
|
||||
Assert.Equal(1, listTask.Body.Items.Count);
|
||||
}
|
||||
|
||||
{
|
||||
var responseJson = "{\"apiVersion\":\"testingversion\",\"status\":{\"token\":\"wrong_token\"}}";
|
||||
var kubernetesConfig = GetK8SConfiguration(server.Uri.ToString(), responseJson, name);
|
||||
@@ -421,7 +422,6 @@ namespace k8s.Tests
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, listTask.Response.StatusCode);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
var client = new Kubernetes(new KubernetesClientConfiguration
|
||||
{
|
||||
@@ -472,16 +472,15 @@ namespace k8s.Tests
|
||||
|
||||
var contexts = new List<Context>
|
||||
{
|
||||
new Context {Name = name, ContextDetails = new ContextDetails {Cluster = name, User = username } },
|
||||
new Context { Name = name, ContextDetails = new ContextDetails { Cluster = name, User = username } },
|
||||
};
|
||||
|
||||
{
|
||||
var clusters = new List<Cluster>
|
||||
{
|
||||
new Cluster
|
||||
{
|
||||
Name = name,
|
||||
ClusterEndpoint = new ClusterEndpoint {SkipTlsVerify = true, Server = serverUri }
|
||||
ClusterEndpoint = new ClusterEndpoint { SkipTlsVerify = true, Server = serverUri },
|
||||
},
|
||||
};
|
||||
|
||||
@@ -518,9 +517,9 @@ namespace k8s.Tests
|
||||
{
|
||||
ApiVersion = "testingversion",
|
||||
Command = command,
|
||||
Arguments = arguments.ToList()
|
||||
}
|
||||
}
|
||||
Arguments = arguments.ToList(),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
var kubernetesConfig = new K8SConfiguration { Clusters = clusters, Users = users, Contexts = contexts };
|
||||
|
||||
@@ -256,7 +256,7 @@ namespace k8s.Tests
|
||||
|
||||
// Kick off a read operation
|
||||
var readTask = Task.Run(() => read = buffer.Read(readData, 0, readData.Length));
|
||||
await Task.Delay(250);
|
||||
await Task.Delay(250).ConfigureAwait(false);
|
||||
Assert.False(readTask.IsCompleted, "Read task completed before data was available.");
|
||||
|
||||
// Write data to the buffer
|
||||
@@ -264,7 +264,7 @@ namespace k8s.Tests
|
||||
|
||||
await TaskAssert.Completed(readTask,
|
||||
timeout: TimeSpan.FromMilliseconds(1000),
|
||||
message: "Timed out waiting for read task to complete.");
|
||||
message: "Timed out waiting for read task to complete.").ConfigureAwait(false);
|
||||
|
||||
Assert.Equal(3, read);
|
||||
Assert.Equal(0xF0, readData[0]);
|
||||
@@ -411,10 +411,10 @@ namespace k8s.Tests
|
||||
byte[] output = new byte[buffer.Size + 1];
|
||||
|
||||
var readTask = Task.Run(() => buffer.Read(output, 0, output.Length));
|
||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
|
||||
|
||||
buffer.Write(data, 0, data.Length);
|
||||
await readTask;
|
||||
await readTask.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_0
|
||||
@@ -437,12 +437,12 @@ namespace k8s.Tests
|
||||
var consumerTask
|
||||
= Task.Run(() => this.Consume(buffer, SHA256.Create()));
|
||||
|
||||
await Task.WhenAll(generatorTask, consumerTask);
|
||||
await Task.WhenAll(generatorTask, consumerTask).ConfigureAwait(false);
|
||||
|
||||
var generatorHash
|
||||
= await generatorTask;
|
||||
= await generatorTask.ConfigureAwait(false);
|
||||
var consumerHash
|
||||
= await consumerTask;
|
||||
= await consumerTask.ConfigureAwait(false);
|
||||
|
||||
Assert.Equal(generatorHash, consumerHash);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace k8s.Tests
|
||||
Command = "command",
|
||||
Arguments = new List<string> { "arg1", "arg2" },
|
||||
EnvironmentVariables = new List<Dictionary<string, string>>
|
||||
{ new Dictionary<string, string> { { "name", "testkey" }, { "value", "testvalue" } } }
|
||||
{ new Dictionary<string, string> { { "name", "testkey" }, { "value", "testvalue" } } },
|
||||
});
|
||||
|
||||
var actualExecInfo = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(actual.StartInfo.EnvironmentVariables["KUBERNETES_EXEC_INFO"]);
|
||||
|
||||
@@ -19,8 +19,9 @@ namespace k8s.Tests
|
||||
{
|
||||
System.Diagnostics.Process.Start("chmod", $"+x {cmd}").WaitForExit();
|
||||
}
|
||||
|
||||
var sut = new GcpTokenProvider(cmd);
|
||||
var result = await sut.GetAuthenticationHeaderAsync(CancellationToken.None);
|
||||
var result = await sut.GetAuthenticationHeaderAsync(CancellationToken.None).ConfigureAwait(false);
|
||||
result.Scheme.Should().Be("Bearer");
|
||||
result.Parameter.Should().Be("ACCESS-TOKEN");
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>..\..\src\KubernetesClient\kubernetes-client.snk</AssemblyOriginatorKeyFile>
|
||||
<RootNamespace>k8s.Tests</RootNamespace>
|
||||
<TargetFrameworks>netcoreapp2.1;netcoreapp2.0</TargetFrameworks>
|
||||
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -20,12 +20,12 @@
|
||||
<PackageReference Include="Nito.AsyncEx" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
|
||||
<!-- <ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
|
||||
<Compile Remove="Kubernetes.Exec.Tests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
|
||||
<Compile Remove="Kubernetes.WebSockets.Tests.cs" />
|
||||
</ItemGroup>
|
||||
</ItemGroup> -->
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
|
||||
@@ -434,7 +434,7 @@ namespace k8s.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadKubeConfigFromEnvironmentVariable_MultipleConfigs()
|
||||
public void LoadKubeConfigFromEnvironmentVariableMultipleConfigs()
|
||||
{
|
||||
// This test makes sure that a list of environment variables works (no exceptions),
|
||||
// doesn't check validity of configuration, which is done in other tests.
|
||||
@@ -564,7 +564,7 @@ namespace k8s.Tests
|
||||
}
|
||||
}
|
||||
|
||||
private void AssertContextEqual(Context expected, Context actual)
|
||||
private static void AssertContextEqual(Context expected, Context actual)
|
||||
{
|
||||
Assert.Equal(expected.Name, actual.Name);
|
||||
Assert.Equal(expected.ContextDetails.Cluster, actual.ContextDetails.Cluster);
|
||||
@@ -572,7 +572,7 @@ namespace k8s.Tests
|
||||
Assert.Equal(expected.ContextDetails.Namespace, actual.ContextDetails.Namespace);
|
||||
}
|
||||
|
||||
private void AssertClusterEqual(Cluster expected, Cluster actual)
|
||||
private static void AssertClusterEqual(Cluster expected, Cluster actual)
|
||||
{
|
||||
Assert.Equal(expected.Name, actual.Name);
|
||||
Assert.Equal(expected.ClusterEndpoint.CertificateAuthority, actual.ClusterEndpoint.CertificateAuthority);
|
||||
@@ -582,7 +582,7 @@ namespace k8s.Tests
|
||||
Assert.Equal(expected.ClusterEndpoint.SkipTlsVerify, actual.ClusterEndpoint.SkipTlsVerify);
|
||||
}
|
||||
|
||||
private void AssertUserEqual(User expected, User actual)
|
||||
private static void AssertUserEqual(User expected, User actual)
|
||||
{
|
||||
Assert.Equal(expected.Name, actual.Name);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#if !NETCOREAPP2_1
|
||||
/*
|
||||
* These tests are only for the netstandard version of the client (there are separate tests for netcoreapp that connect to a local test-hosted server).
|
||||
*/
|
||||
@@ -153,3 +154,4 @@ namespace k8s.Tests
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -8,7 +8,7 @@ namespace k8s.Tests.Logging
|
||||
/// <summary>
|
||||
/// An implementation of <see cref="ILogger"/> that writes to the output of the current Xunit test.
|
||||
/// </summary>
|
||||
sealed class TestOutputLogger
|
||||
internal sealed class TestOutputLogger
|
||||
: ILogger
|
||||
{
|
||||
/// <summary>
|
||||
@@ -30,7 +30,7 @@ namespace k8s.Tests.Logging
|
||||
throw new ArgumentNullException(nameof(testOutput));
|
||||
}
|
||||
|
||||
if (String.IsNullOrWhiteSpace(loggerCategory))
|
||||
if (string.IsNullOrWhiteSpace(loggerCategory))
|
||||
{
|
||||
throw new ArgumentException(
|
||||
"Argument cannot be null, empty, or entirely composed of whitespace: 'loggerCategory'.",
|
||||
@@ -83,7 +83,7 @@ namespace k8s.Tests.Logging
|
||||
throw new ArgumentNullException(nameof(formatter));
|
||||
}
|
||||
|
||||
TestOutput.WriteLine(String.Format("[{0}] {1}: {2}",
|
||||
TestOutput.WriteLine(string.Format("[{0}] {1}: {2}",
|
||||
level,
|
||||
LoggerCategory,
|
||||
formatter(state, exception)));
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace k8s.Tests.Logging
|
||||
/// <summary>
|
||||
/// Logger provider for logging to Xunit test output.
|
||||
/// </summary>
|
||||
sealed class TestOutputLoggerProvider
|
||||
internal sealed class TestOutputLoggerProvider
|
||||
: ILoggerProvider
|
||||
{
|
||||
/// <summary>
|
||||
@@ -40,7 +40,7 @@ namespace k8s.Tests.Logging
|
||||
/// <summary>
|
||||
/// The output for the current test.
|
||||
/// </summary>
|
||||
ITestOutputHelper TestOutput { get; }
|
||||
private ITestOutputHelper TestOutput { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The logger's minimum log level.
|
||||
|
||||
@@ -32,9 +32,9 @@ namespace k8s.Tests.Mock
|
||||
_webHost = WebHost.CreateDefaultBuilder()
|
||||
.Configure(app => app.Run(async httpContext =>
|
||||
{
|
||||
if (await shouldNext(httpContext))
|
||||
if (await shouldNext(httpContext).ConfigureAwait(false))
|
||||
{
|
||||
await httpContext.Response.WriteAsync(resp);
|
||||
await httpContext.Response.WriteAsync(resp).ConfigureAwait(false);
|
||||
}
|
||||
}))
|
||||
.UseKestrel(options => { options.Listen(IPAddress.Loopback, 0, listenConfigure); })
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace k8s.Tests.Mock
|
||||
private string subProtocol;
|
||||
private ConcurrentQueue<MessageData> receiveBuffers = new ConcurrentQueue<MessageData>();
|
||||
private AsyncAutoResetEvent receiveEvent = new AsyncAutoResetEvent(false);
|
||||
private bool disposedValue;
|
||||
|
||||
public MockWebSocket(string subProtocol = null)
|
||||
{
|
||||
@@ -26,7 +27,7 @@ namespace k8s.Tests.Mock
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public EventHandler<MessageDataEventArgs> MessageSent;
|
||||
public EventHandler<MessageDataEventArgs> MessageSent { get; set; }
|
||||
|
||||
public Task InvokeReceiveAsync(ArraySegment<byte> buffer, WebSocketMessageType messageType, bool endOfMessage)
|
||||
{
|
||||
@@ -40,8 +41,6 @@ namespace k8s.Tests.Mock
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#region WebSocket overrides
|
||||
|
||||
public override WebSocketCloseStatus? CloseStatus => this.closeStatus;
|
||||
|
||||
public override string CloseStatusDescription => this.closeStatusDescription;
|
||||
@@ -76,12 +75,6 @@ namespace k8s.Tests.Mock
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
this.receiveBuffers.Clear();
|
||||
this.receiveEvent.Set();
|
||||
}
|
||||
|
||||
public override async Task<WebSocketReceiveResult> ReceiveAsync(ArraySegment<byte> buffer,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -127,14 +120,12 @@ namespace k8s.Tests.Mock
|
||||
{
|
||||
Buffer = buffer,
|
||||
MessageType = messageType,
|
||||
EndOfMessage = endOfMessage
|
||||
EndOfMessage = endOfMessage,
|
||||
},
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public class MessageData
|
||||
{
|
||||
public ArraySegment<byte> Buffer { get; set; }
|
||||
@@ -146,5 +137,33 @@ namespace k8s.Tests.Mock
|
||||
{
|
||||
public MessageData Data { get; set; }
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
this.receiveBuffers.Clear();
|
||||
this.receiveEvent.Set();
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
|
||||
// ~MockWebSocket()
|
||||
// {
|
||||
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace k8s.Tests.Mock.Server.Controllers
|
||||
/// <summary>
|
||||
/// The adapter used to capture sockets accepted by the test server and provide them to the calling test.
|
||||
/// </summary>
|
||||
WebSocketTestAdapter WebSocketTestAdapter { get; }
|
||||
private WebSocketTestAdapter WebSocketTestAdapter { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Mock Kubernetes API: exec-in-pod.
|
||||
@@ -52,11 +52,11 @@ namespace k8s.Tests.Mock.Server.Controllers
|
||||
}
|
||||
|
||||
WebSocket webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync(
|
||||
subProtocol: WebSocketProtocol.ChannelWebSocketProtocol);
|
||||
subProtocol: WebSocketProtocol.ChannelWebSocketProtocol).ConfigureAwait(false);
|
||||
|
||||
WebSocketTestAdapter.AcceptedPodExecV1Connection.AcceptServerSocket(webSocket);
|
||||
|
||||
await WebSocketTestAdapter.TestCompleted;
|
||||
await WebSocketTestAdapter.TestCompleted.ConfigureAwait(false);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace k8s.Tests.Mock.Server.Controllers
|
||||
/// <summary>
|
||||
/// The adapter used to capture sockets accepted by the test server and provide them to the calling test.
|
||||
/// </summary>
|
||||
WebSocketTestAdapter WebSocketTestAdapter { get; }
|
||||
private WebSocketTestAdapter WebSocketTestAdapter { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Mock Kubernetes API: port-forward for pod.
|
||||
@@ -56,11 +56,11 @@ namespace k8s.Tests.Mock.Server.Controllers
|
||||
}
|
||||
|
||||
WebSocket webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync(
|
||||
subProtocol: WebSocketProtocol.ChannelWebSocketProtocol);
|
||||
subProtocol: WebSocketProtocol.ChannelWebSocketProtocol).ConfigureAwait(false);
|
||||
|
||||
WebSocketTestAdapter.AcceptedPodPortForwardV1Connection.AcceptServerSocket(webSocket);
|
||||
|
||||
await WebSocketTestAdapter.TestCompleted;
|
||||
await WebSocketTestAdapter.TestCompleted.ConfigureAwait(false);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace k8s.Tests.Mock.Server
|
||||
/// <param name="services">
|
||||
/// The service collection to configure.
|
||||
/// </param>
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
public static void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
if (services == null)
|
||||
{
|
||||
@@ -43,7 +43,7 @@ namespace k8s.Tests.Mock.Server
|
||||
/// <param name="app">
|
||||
/// The application pipeline builder.
|
||||
/// </param>
|
||||
public void Configure(IApplicationBuilder app)
|
||||
public static void Configure(IApplicationBuilder app)
|
||||
{
|
||||
app.UseWebSockets(new WebSocketOptions
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace k8s.Tests.Mock.Server
|
||||
/// <summary>
|
||||
/// Completion source for the <see cref="TestCompleted"/> task.
|
||||
/// </summary>
|
||||
readonly TaskCompletionSource<object> _testCompletion = new TaskCompletionSource<object>();
|
||||
private readonly TaskCompletionSource<object> _testCompletion = new TaskCompletionSource<object>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="Task"/> that completes when the test is complete (providing <see cref="CompleteTest"/> is called).
|
||||
@@ -51,7 +51,7 @@ namespace k8s.Tests.Mock.Server
|
||||
/// <summary>
|
||||
/// Completion source for the <see cref="ServerSocketAccepted"/> task.
|
||||
/// </summary>
|
||||
readonly TaskCompletionSource<WebSocket> _completion = new TaskCompletionSource<WebSocket>();
|
||||
private readonly TaskCompletionSource<WebSocket> _completion = new TaskCompletionSource<WebSocket>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="Task"/> that completes when the server accepts a WebSocket connection (i.e. when <see cref="AcceptServerSocket"/> or <see cref="RejectServerSocket"/> is called).
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace k8s.Tests
|
||||
Name = "name",
|
||||
NamespaceProperty = "ns",
|
||||
ResourceVersion = "42",
|
||||
Uid = "id"
|
||||
Uid = "id",
|
||||
};
|
||||
Assert.Equal(ts, pod.CreationTimestamp().Value);
|
||||
Assert.Equal(ts2, pod.DeletionTimestamp().Value);
|
||||
|
||||
@@ -7,6 +7,6 @@ namespace k8s.Tests
|
||||
{
|
||||
Windows = 1,
|
||||
Linux = 2,
|
||||
OSX = 4
|
||||
OSX = 4,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace k8s.Tests
|
||||
/// Verify that the client can request execution of a command in a pod's default container, with only the STDOUT stream enabled.
|
||||
/// </summary>
|
||||
[Fact(DisplayName = "Can exec in pod's default container, STDOUT only")]
|
||||
public async Task Exec_DefaultContainer_StdOut()
|
||||
public async Task ExecDefaultContainerStdOut()
|
||||
{
|
||||
if (!Debugger.IsAttached)
|
||||
{
|
||||
@@ -51,7 +51,7 @@ namespace k8s.Tests
|
||||
TimeSpan.FromSeconds(5));
|
||||
}
|
||||
|
||||
await Host.StartAsync(TestCancellation);
|
||||
await Host.StartAsync(TestCancellation).ConfigureAwait(false);
|
||||
|
||||
using (Kubernetes client = CreateTestClient())
|
||||
{
|
||||
@@ -66,7 +66,7 @@ namespace k8s.Tests
|
||||
stdin: false,
|
||||
stdout: true,
|
||||
webSocketSubProtol: WebSocketProtocol.ChannelWebSocketProtocol,
|
||||
cancellationToken: TestCancellation);
|
||||
cancellationToken: TestCancellation).ConfigureAwait(false);
|
||||
Assert.Equal(WebSocketProtocol.ChannelWebSocketProtocol,
|
||||
clientSocket
|
||||
.SubProtocol); // For WebSockets, the Kubernetes API defaults to the binary channel (v1) protocol.
|
||||
@@ -81,10 +81,10 @@ namespace k8s.Tests
|
||||
const int STDOUT = 1;
|
||||
const string expectedOutput = "This is text send to STDOUT.";
|
||||
|
||||
int bytesSent = await SendMultiplexed(serverSocket, STDOUT, expectedOutput);
|
||||
int bytesSent = await SendMultiplexed(serverSocket, STDOUT, expectedOutput).ConfigureAwait(false);
|
||||
testOutput.WriteLine($"Sent {bytesSent} bytes to server socket; receiving from client socket...");
|
||||
|
||||
(string receivedText, byte streamIndex, int bytesReceived) = await ReceiveTextMultiplexed(clientSocket);
|
||||
(string receivedText, byte streamIndex, int bytesReceived) = await ReceiveTextMultiplexed(clientSocket).ConfigureAwait(false);
|
||||
testOutput.WriteLine(
|
||||
$"Received {bytesReceived} bytes from client socket ('{receivedText}', stream {streamIndex}).");
|
||||
|
||||
@@ -93,15 +93,14 @@ namespace k8s.Tests
|
||||
|
||||
await Disconnect(clientSocket, serverSocket,
|
||||
closeStatus: WebSocketCloseStatus.NormalClosure,
|
||||
closeStatusDescription: "Normal Closure");
|
||||
closeStatusDescription: "Normal Closure").ConfigureAwait(false);
|
||||
|
||||
WebSocketTestAdapter.CompleteTest();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void GetExitCodeOrThrow_Success()
|
||||
public void GetExitCodeOrThrowSuccess()
|
||||
{
|
||||
var status = new V1Status() { Metadata = null, Status = "Success", };
|
||||
|
||||
@@ -109,7 +108,7 @@ namespace k8s.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetExitCodeOrThrow_NonZeroExitCode()
|
||||
public void GetExitCodeOrThrowNonZeroExitCode()
|
||||
{
|
||||
var status = new V1Status()
|
||||
{
|
||||
@@ -121,8 +120,8 @@ namespace k8s.Tests
|
||||
{
|
||||
Causes = new List<V1StatusCause>()
|
||||
{
|
||||
new V1StatusCause() {Reason = "ExitCode", Message = "1" }
|
||||
}
|
||||
new V1StatusCause() { Reason = "ExitCode", Message = "1" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -130,7 +129,7 @@ namespace k8s.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetExitCodeOrThrow_InvalidExitCode()
|
||||
public void GetExitCodeOrThrowInvalidExitCode()
|
||||
{
|
||||
var status = new V1Status()
|
||||
{
|
||||
@@ -142,8 +141,8 @@ namespace k8s.Tests
|
||||
{
|
||||
Causes = new List<V1StatusCause>()
|
||||
{
|
||||
new V1StatusCause() {Reason = "ExitCode", Message = "abc" }
|
||||
}
|
||||
new V1StatusCause() { Reason = "ExitCode", Message = "abc" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -152,7 +151,7 @@ namespace k8s.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetExitCodeOrThrow_NoExitCode()
|
||||
public void GetExitCodeOrThrowNoExitCode()
|
||||
{
|
||||
var status = new V1Status()
|
||||
{
|
||||
@@ -168,7 +167,7 @@ namespace k8s.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetExitCodeOrThrow_OtherError()
|
||||
public void GetExitCodeOrThrowOtherError()
|
||||
{
|
||||
var status = new V1Status() { Metadata = null, Status = "Failure", Reason = "SomethingElse" };
|
||||
|
||||
@@ -177,7 +176,7 @@ namespace k8s.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NamespacedPodExecAsync_ActionNull()
|
||||
public async Task NamespacedPodExecAsyncActionNull()
|
||||
{
|
||||
using (MemoryStream stdIn = new MemoryStream())
|
||||
using (MemoryStream stdOut = new MemoryStream())
|
||||
@@ -209,7 +208,7 @@ namespace k8s.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NamespacedPodExecAsync_HttpException_WithStatus()
|
||||
public async Task NamespacedPodExecAsyncHttpExceptionWithStatus()
|
||||
{
|
||||
var kubernetesMock = new Moq.Mock<Kubernetes>(
|
||||
new object[] { Moq.Mock.Of<ServiceClientCredentials>(), new DelegatingHandler[] { } });
|
||||
@@ -232,7 +231,7 @@ namespace k8s.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NamespacedPodExecAsync_HttpException_NoStatus()
|
||||
public async Task NamespacedPodExecAsyncHttpExceptionNoStatus()
|
||||
{
|
||||
var kubernetesMock = new Moq.Mock<Kubernetes>(
|
||||
new object[] { Moq.Mock.Of<ServiceClientCredentials>(), new DelegatingHandler[] { } });
|
||||
@@ -255,7 +254,7 @@ namespace k8s.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NamespacedPodExecAsync_GenericException()
|
||||
public async Task NamespacedPodExecAsyncGenericException()
|
||||
{
|
||||
var kubernetesMock = new Moq.Mock<Kubernetes>(
|
||||
new object[] { Moq.Mock.Of<ServiceClientCredentials>(), new DelegatingHandler[] { } });
|
||||
@@ -278,7 +277,7 @@ namespace k8s.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NamespacedPodExecAsync_ExitCode_NonZero()
|
||||
public async Task NamespacedPodExecAsyncExitCodeNonZero()
|
||||
{
|
||||
var processStatus = new V1Status()
|
||||
{
|
||||
@@ -290,8 +289,8 @@ namespace k8s.Tests
|
||||
{
|
||||
Causes = new List<V1StatusCause>()
|
||||
{
|
||||
new V1StatusCause() {Reason = "ExitCode", Message = "1" }
|
||||
}
|
||||
new V1StatusCause() { Reason = "ExitCode", Message = "1" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace k8s.Tests
|
||||
stream.Write(b, 0, b.Length);
|
||||
|
||||
// Send 100 bytes, expect 1 (channel index) + 100 (payload) = 101 bytes
|
||||
Assert.True(await WaitForAsync(() => sentBuffer.Count == 101),
|
||||
Assert.True(await WaitForAsync(() => sentBuffer.Count == 101).ConfigureAwait(false),
|
||||
$"Demuxer error: expect to send 101 bytes, but actually send {sentBuffer.Count} bytes.");
|
||||
Assert.True(sentBuffer[0] == channelIndex, "The first sent byte is not channel index!");
|
||||
Assert.True(sentBuffer[1] == 0xEF, "Incorrect payload!");
|
||||
@@ -63,7 +63,7 @@ namespace k8s.Tests
|
||||
stream.Write(b, 0, b.Length);
|
||||
|
||||
// Send 300 bytes in 2 messages, expect 1 (channel index) * 2 + 300 (payload) = 302 bytes
|
||||
Assert.True(await WaitForAsync(() => sentBuffer.Count == 302),
|
||||
Assert.True(await WaitForAsync(() => sentBuffer.Count == 302).ConfigureAwait(false),
|
||||
$"Demuxer error: expect to send 302 bytes, but actually send {sentBuffer.Count} bytes.");
|
||||
Assert.True(sentBuffer[0] == channelIndex, "The first sent byte is not channel index!");
|
||||
Assert.True(sentBuffer[1] == 0xEF, "The first part of payload incorrect!");
|
||||
@@ -91,21 +91,21 @@ namespace k8s.Tests
|
||||
{
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(100, channelIndex, 0xAA, false)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(200, channelIndex, 0xAB, false)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(300, channelIndex, 0xAC, false)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
|
||||
await WaitForAsync(() => receivedBuffer.Count == expectedCount);
|
||||
await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "normal", CancellationToken.None);
|
||||
await WaitForAsync(() => receivedBuffer.Count == expectedCount).ConfigureAwait(false);
|
||||
await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "normal", CancellationToken.None).ConfigureAwait(false);
|
||||
});
|
||||
var buffer = new byte[50];
|
||||
while (true)
|
||||
{
|
||||
var cRead = await stream.ReadAsync(buffer, 0, buffer.Length);
|
||||
var cRead = await stream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
|
||||
if (cRead == 0)
|
||||
{
|
||||
break;
|
||||
@@ -117,7 +117,7 @@ namespace k8s.Tests
|
||||
}
|
||||
}
|
||||
|
||||
await t;
|
||||
await t.ConfigureAwait(false);
|
||||
|
||||
Assert.True(receivedBuffer.Count == expectedCount,
|
||||
$"Demuxer error: expect to receive {expectedCount} bytes, but actually got {receivedBuffer.Count} bytes.");
|
||||
@@ -150,21 +150,21 @@ namespace k8s.Tests
|
||||
{
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(100, channelIndex, 0xB1, true)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(200, channelIndex, 0xB2, false)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(300, channelIndex, 0xB3, false)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
|
||||
await WaitForAsync(() => receivedBuffer.Count == expectedCount);
|
||||
await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "normal", CancellationToken.None);
|
||||
await WaitForAsync(() => receivedBuffer.Count == expectedCount).ConfigureAwait(false);
|
||||
await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "normal", CancellationToken.None).ConfigureAwait(false);
|
||||
});
|
||||
var buffer = new byte[50];
|
||||
while (true)
|
||||
{
|
||||
var cRead = await stream.ReadAsync(buffer, 0, buffer.Length);
|
||||
var cRead = await stream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
|
||||
if (cRead == 0)
|
||||
{
|
||||
break;
|
||||
@@ -176,7 +176,7 @@ namespace k8s.Tests
|
||||
}
|
||||
}
|
||||
|
||||
await t;
|
||||
await t.ConfigureAwait(false);
|
||||
|
||||
Assert.True(receivedBuffer.Count == expectedCount,
|
||||
$"Demuxer error: expect to receive {expectedCount} bytes, but actually got {receivedBuffer.Count} bytes.");
|
||||
@@ -209,21 +209,21 @@ namespace k8s.Tests
|
||||
{
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(2, channelIndex, 0xC1, true)),
|
||||
WebSocketMessageType.Binary, false);
|
||||
WebSocketMessageType.Binary, false).ConfigureAwait(false);
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(100, channelIndex, 0xC2, false)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(300, channelIndex, 0xC3, false)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
|
||||
await WaitForAsync(() => receivedBuffer.Count == expectedCount);
|
||||
await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "normal", CancellationToken.None);
|
||||
await WaitForAsync(() => receivedBuffer.Count == expectedCount).ConfigureAwait(false);
|
||||
await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "normal", CancellationToken.None).ConfigureAwait(false);
|
||||
});
|
||||
var buffer = new byte[50];
|
||||
while (true)
|
||||
{
|
||||
var cRead = await stream.ReadAsync(buffer, 0, buffer.Length);
|
||||
var cRead = await stream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
|
||||
if (cRead == 0)
|
||||
{
|
||||
break;
|
||||
@@ -235,7 +235,7 @@ namespace k8s.Tests
|
||||
}
|
||||
}
|
||||
|
||||
await t;
|
||||
await t.ConfigureAwait(false);
|
||||
|
||||
Assert.True(receivedBuffer.Count == expectedCount,
|
||||
$"Demuxer error: expect to receive {expectedCount} bytes, but actually got {receivedBuffer.Count} bytes.");
|
||||
@@ -272,24 +272,24 @@ namespace k8s.Tests
|
||||
// Simulate WebSocket received remote data to multiple streams
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(100, channelIndex1, 0xD1, false)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(200, channelIndex2, 0xD2, false)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(300, channelIndex1, 0xD3, false)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
|
||||
await WaitForAsync(() => receivedBuffer1.Count == expectedCount1);
|
||||
await WaitForAsync(() => receivedBuffer2.Count == expectedCount2);
|
||||
await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "normal", CancellationToken.None);
|
||||
await WaitForAsync(() => receivedBuffer1.Count == expectedCount1).ConfigureAwait(false);
|
||||
await WaitForAsync(() => receivedBuffer2.Count == expectedCount2).ConfigureAwait(false);
|
||||
await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "normal", CancellationToken.None).ConfigureAwait(false);
|
||||
});
|
||||
var t2 = Task.Run(async () =>
|
||||
{
|
||||
var buffer = new byte[50];
|
||||
while (true)
|
||||
{
|
||||
var cRead = await stream1.ReadAsync(buffer, 0, buffer.Length);
|
||||
var cRead = await stream1.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
|
||||
if (cRead == 0)
|
||||
{
|
||||
break;
|
||||
@@ -306,7 +306,7 @@ namespace k8s.Tests
|
||||
var buffer = new byte[50];
|
||||
while (true)
|
||||
{
|
||||
var cRead = await stream2.ReadAsync(buffer, 0, buffer.Length);
|
||||
var cRead = await stream2.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
|
||||
if (cRead == 0)
|
||||
{
|
||||
break;
|
||||
@@ -318,7 +318,7 @@ namespace k8s.Tests
|
||||
}
|
||||
}
|
||||
});
|
||||
await Task.WhenAll(t1, t2, t3);
|
||||
await Task.WhenAll(t1, t2, t3).ConfigureAwait(false);
|
||||
|
||||
Assert.True(receivedBuffer1.Count == expectedCount1,
|
||||
$"Demuxer error: expect to receive {expectedCount1} bytes, but actually got {receivedBuffer1.Count} bytes.");
|
||||
@@ -361,24 +361,24 @@ namespace k8s.Tests
|
||||
// Simulate WebSocket received remote data to multiple streams
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(100, channelIndex1, 0xE1, true)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(200, channelIndex2, 0xE2, true)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
await ws.InvokeReceiveAsync(
|
||||
new ArraySegment<byte>(GenerateRandomBuffer(300, channelIndex1, 0xE3, false)),
|
||||
WebSocketMessageType.Binary, true);
|
||||
WebSocketMessageType.Binary, true).ConfigureAwait(false);
|
||||
|
||||
await WaitForAsync(() => receivedBuffer1.Count == expectedCount1);
|
||||
await WaitForAsync(() => receivedBuffer2.Count == expectedCount2);
|
||||
await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "normal", CancellationToken.None);
|
||||
await WaitForAsync(() => receivedBuffer1.Count == expectedCount1).ConfigureAwait(false);
|
||||
await WaitForAsync(() => receivedBuffer2.Count == expectedCount2).ConfigureAwait(false);
|
||||
await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "normal", CancellationToken.None).ConfigureAwait(false);
|
||||
});
|
||||
var t2 = Task.Run(async () =>
|
||||
{
|
||||
var buffer = new byte[50];
|
||||
while (true)
|
||||
{
|
||||
var cRead = await stream1.ReadAsync(buffer, 0, buffer.Length);
|
||||
var cRead = await stream1.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
|
||||
if (cRead == 0)
|
||||
{
|
||||
break;
|
||||
@@ -395,7 +395,7 @@ namespace k8s.Tests
|
||||
var buffer = new byte[50];
|
||||
while (true)
|
||||
{
|
||||
var cRead = await stream2.ReadAsync(buffer, 0, buffer.Length);
|
||||
var cRead = await stream2.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
|
||||
if (cRead == 0)
|
||||
{
|
||||
break;
|
||||
@@ -407,7 +407,7 @@ namespace k8s.Tests
|
||||
}
|
||||
}
|
||||
});
|
||||
await Task.WhenAll(t1, t2, t3);
|
||||
await Task.WhenAll(t1, t2, t3).ConfigureAwait(false);
|
||||
|
||||
Assert.True(receivedBuffer1.Count == expectedCount1,
|
||||
$"Demuxer error: expect to receive {expectedCount1} bytes, but actually got {receivedBuffer1.Count} bytes.");
|
||||
@@ -465,8 +465,9 @@ namespace k8s.Tests
|
||||
return true;
|
||||
}
|
||||
|
||||
await Task.Delay(10);
|
||||
} while (w.Elapsed.Duration().TotalSeconds < waitForSeconds);
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
}
|
||||
while (w.Elapsed.Duration().TotalSeconds < waitForSeconds);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using Xunit;
|
||||
|
||||
namespace k8s.Tests
|
||||
{
|
||||
static class TaskAssert
|
||||
internal static class TaskAssert
|
||||
{
|
||||
public static void NotCompleted(Task task, string message = "Task should not be completed")
|
||||
{
|
||||
@@ -17,25 +17,22 @@ namespace k8s.Tests
|
||||
var timeoutTask = Task.Delay(
|
||||
TimeSpan.FromMilliseconds(1000));
|
||||
|
||||
var completedTask = await Task.WhenAny(task, timeoutTask);
|
||||
var completedTask = await Task.WhenAny(task, timeoutTask).ConfigureAwait(false);
|
||||
Assert.True(ReferenceEquals(task, completedTask), message);
|
||||
|
||||
await completedTask;
|
||||
await completedTask.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static async Task<T> Completed<T>(Task<T> task, TimeSpan timeout, string message = "Task timed out")
|
||||
{
|
||||
var timeoutTask =
|
||||
Task.Delay(
|
||||
TimeSpan.FromMilliseconds(1000))
|
||||
.ContinueWith(
|
||||
completedTimeoutTask =>
|
||||
default(T)); // Value is never returned, but we need a task of the same result type in order to use Task.WhenAny.
|
||||
var timeoutTask = Task.Delay(TimeSpan.FromMilliseconds(1000)).ContinueWith(completedTimeoutTask => default(T));
|
||||
|
||||
var completedTask = await Task.WhenAny(task, timeoutTask);
|
||||
// Value is never returned, but we need a task of the same result type in order to use Task.WhenAny.
|
||||
|
||||
var completedTask = await Task.WhenAny(task, timeoutTask).ConfigureAwait(false);
|
||||
Assert.True(ReferenceEquals(task, completedTask), message);
|
||||
|
||||
return await completedTask;
|
||||
return await completedTask.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,20 +9,20 @@ namespace k8s.Tests
|
||||
{
|
||||
public class TokenFileAuthTests
|
||||
{
|
||||
public async Task Token()
|
||||
public async Task TestToken()
|
||||
{
|
||||
var auth = new TokenFileAuth("assets/token1");
|
||||
var result = await auth.GetAuthenticationHeaderAsync(CancellationToken.None);
|
||||
var result = await auth.GetAuthenticationHeaderAsync(CancellationToken.None).ConfigureAwait(false);
|
||||
result.Scheme.Should().Be("Bearer");
|
||||
result.Parameter.Should().Be("token1");
|
||||
|
||||
auth._token_file = "assets/token2";
|
||||
result = await auth.GetAuthenticationHeaderAsync(CancellationToken.None);
|
||||
auth.TokenFile = "assets/token2";
|
||||
result = await auth.GetAuthenticationHeaderAsync(CancellationToken.None).ConfigureAwait(false);
|
||||
result.Scheme.Should().Be("Bearer");
|
||||
result.Parameter.Should().Be("token1");
|
||||
|
||||
auth._token_expires_at = DateTime.UtcNow;
|
||||
result = await auth.GetAuthenticationHeaderAsync(CancellationToken.None);
|
||||
auth.TokenExpiresAt = DateTime.UtcNow;
|
||||
result = await auth.GetAuthenticationHeaderAsync(CancellationToken.None).ConfigureAwait(false);
|
||||
result.Scheme.Should().Be("Bearer");
|
||||
result.Parameter.Should().Be("token2");
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace k8s.Tests
|
||||
private static readonly string MockDeletedStreamLine = BuildWatchEventStreamLine(WatchEventType.Deleted);
|
||||
private static readonly string MockModifiedStreamLine = BuildWatchEventStreamLine(WatchEventType.Modified);
|
||||
private static readonly string MockErrorStreamLine = BuildWatchEventStreamLine(WatchEventType.Error);
|
||||
private static readonly string MockBadStreamLine = "bad json";
|
||||
private const string MockBadStreamLine = "bad json";
|
||||
private static readonly TimeSpan TestTimeout = TimeSpan.FromSeconds(150);
|
||||
|
||||
private readonly ITestOutputHelper testOutput;
|
||||
@@ -48,9 +48,9 @@ namespace k8s.Tests
|
||||
private static async Task WriteStreamLine(HttpContext httpContext, string reponseLine)
|
||||
{
|
||||
const string crlf = "\r\n";
|
||||
await httpContext.Response.WriteAsync(reponseLine.Replace(crlf, ""));
|
||||
await httpContext.Response.WriteAsync(crlf);
|
||||
await httpContext.Response.Body.FlushAsync();
|
||||
await httpContext.Response.WriteAsync(reponseLine.Replace(crlf, "")).ConfigureAwait(false);
|
||||
await httpContext.Response.WriteAsync(crlf).ConfigureAwait(false);
|
||||
await httpContext.Response.Body.FlushAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -68,7 +68,7 @@ namespace k8s.Tests
|
||||
{
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(1)); // delay for onerror to be called
|
||||
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false); // delay for onerror to be called
|
||||
Assert.True(onErrorCalled);
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace k8s.Tests
|
||||
|
||||
// this line did not throw
|
||||
// listTask.Watch<Corev1Pod>((type, item) => { });
|
||||
});
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,8 +92,8 @@ namespace k8s.Tests
|
||||
using (var server = new MockKubeApiServer(testOutput, async httpContext =>
|
||||
{
|
||||
// block until reponse watcher obj created
|
||||
await created.WaitAsync();
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine);
|
||||
await created.WaitAsync().ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine).ConfigureAwait(false);
|
||||
return false;
|
||||
}))
|
||||
{
|
||||
@@ -105,7 +105,7 @@ namespace k8s.Tests
|
||||
{
|
||||
// here watcher is ready to use, but http server has not responsed yet.
|
||||
created.Set();
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
Assert.True(eventsReceived.IsSet);
|
||||
@@ -128,20 +128,20 @@ namespace k8s.Tests
|
||||
httpContext.Response.StatusCode = (int)HttpStatusCode.OK;
|
||||
httpContext.Response.ContentLength = null;
|
||||
|
||||
await WriteStreamLine(httpContext, MockKubeApiServer.MockPodResponse);
|
||||
await WriteStreamLine(httpContext, MockBadStreamLine);
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine);
|
||||
await WriteStreamLine(httpContext, MockBadStreamLine);
|
||||
await WriteStreamLine(httpContext, MockModifiedStreamLine);
|
||||
await WriteStreamLine(httpContext, MockKubeApiServer.MockPodResponse).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockBadStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockBadStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockModifiedStreamLine).ConfigureAwait(false);
|
||||
|
||||
// make server alive, cannot set to int.max as of it would block response
|
||||
await serverShutdown.WaitAsync();
|
||||
await serverShutdown.WaitAsync().ConfigureAwait(false);
|
||||
return false;
|
||||
}))
|
||||
{
|
||||
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
|
||||
|
||||
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
|
||||
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
|
||||
|
||||
var events = new HashSet<WatchEventType>();
|
||||
var errors = 0;
|
||||
@@ -164,7 +164,7 @@ namespace k8s.Tests
|
||||
onClosed: connectionClosed.Set);
|
||||
|
||||
// wait server yields all events
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
|
||||
Assert.True(
|
||||
eventsReceived.CurrentCount == 0,
|
||||
@@ -180,7 +180,7 @@ namespace k8s.Tests
|
||||
// Let the server know it can initiate a shut down.
|
||||
serverShutdown.Set();
|
||||
|
||||
await Task.WhenAny(connectionClosed.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(connectionClosed.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
Assert.True(connectionClosed.IsSet);
|
||||
}
|
||||
}
|
||||
@@ -194,11 +194,11 @@ namespace k8s.Tests
|
||||
|
||||
using (var server = new MockKubeApiServer(testOutput, async httpContext =>
|
||||
{
|
||||
await WriteStreamLine(httpContext, MockKubeApiServer.MockPodResponse);
|
||||
await WriteStreamLine(httpContext, MockKubeApiServer.MockPodResponse).ConfigureAwait(false);
|
||||
|
||||
while (serverRunning)
|
||||
{
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine);
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -206,7 +206,7 @@ namespace k8s.Tests
|
||||
{
|
||||
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
|
||||
|
||||
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
|
||||
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
|
||||
|
||||
var events = new HashSet<WatchEventType>();
|
||||
|
||||
@@ -219,7 +219,7 @@ namespace k8s.Tests
|
||||
onClosed: connectionClosed.Set);
|
||||
|
||||
// wait at least an event
|
||||
await Task.WhenAny(Task.Run(() => eventsReceived.Wait()), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(Task.Run(() => eventsReceived.Wait()), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
Assert.True(
|
||||
eventsReceived.CurrentCount == 0,
|
||||
"Timed out waiting for events.");
|
||||
@@ -256,19 +256,19 @@ namespace k8s.Tests
|
||||
|
||||
using (var server = new MockKubeApiServer(testOutput, async httpContext =>
|
||||
{
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine);
|
||||
await WriteStreamLine(httpContext, MockDeletedStreamLine);
|
||||
await WriteStreamLine(httpContext, MockModifiedStreamLine);
|
||||
await WriteStreamLine(httpContext, MockErrorStreamLine);
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockDeletedStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockModifiedStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockErrorStreamLine).ConfigureAwait(false);
|
||||
|
||||
// make server alive, cannot set to int.max as of it would block response
|
||||
await serverShutdown.WaitAsync();
|
||||
await serverShutdown.WaitAsync().ConfigureAwait(false);
|
||||
return false;
|
||||
}))
|
||||
{
|
||||
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
|
||||
|
||||
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
|
||||
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
|
||||
|
||||
var events = new HashSet<WatchEventType>();
|
||||
var errors = 0;
|
||||
@@ -291,7 +291,7 @@ namespace k8s.Tests
|
||||
onClosed: waitForClosed.Set);
|
||||
|
||||
// wait server yields all events
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
|
||||
Assert.True(
|
||||
eventsReceived.CurrentCount == 0,
|
||||
@@ -308,7 +308,7 @@ namespace k8s.Tests
|
||||
|
||||
serverShutdown.Set();
|
||||
|
||||
await Task.WhenAny(waitForClosed.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(waitForClosed.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
Assert.True(waitForClosed.IsSet);
|
||||
Assert.False(watcher.Watching);
|
||||
}
|
||||
@@ -323,21 +323,21 @@ namespace k8s.Tests
|
||||
|
||||
using (var server = new MockKubeApiServer(testOutput, async httpContext =>
|
||||
{
|
||||
await WriteStreamLine(httpContext, MockKubeApiServer.MockPodResponse);
|
||||
await Task.Delay(TimeSpan.FromSeconds(120)); // The default timeout is 100 seconds
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine);
|
||||
await WriteStreamLine(httpContext, MockDeletedStreamLine);
|
||||
await WriteStreamLine(httpContext, MockModifiedStreamLine);
|
||||
await WriteStreamLine(httpContext, MockErrorStreamLine);
|
||||
await WriteStreamLine(httpContext, MockKubeApiServer.MockPodResponse).ConfigureAwait(false);
|
||||
await Task.Delay(TimeSpan.FromSeconds(120)).ConfigureAwait(false); // The default timeout is 100 seconds
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockDeletedStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockModifiedStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockErrorStreamLine).ConfigureAwait(false);
|
||||
|
||||
// make server alive, cannot set to int.max as of it would block response
|
||||
await serverShutdown.WaitAsync();
|
||||
await serverShutdown.WaitAsync().ConfigureAwait(false);
|
||||
return false;
|
||||
}))
|
||||
{
|
||||
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
|
||||
|
||||
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
|
||||
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
|
||||
|
||||
var events = new HashSet<WatchEventType>();
|
||||
var errors = 0;
|
||||
@@ -360,7 +360,7 @@ namespace k8s.Tests
|
||||
onClosed: connectionClosed.Set);
|
||||
|
||||
// wait server yields all events
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
|
||||
Assert.True(
|
||||
eventsReceived.CurrentCount == 0,
|
||||
@@ -377,7 +377,7 @@ namespace k8s.Tests
|
||||
|
||||
serverShutdown.Set();
|
||||
|
||||
await Task.WhenAny(connectionClosed.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(connectionClosed.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
Assert.True(connectionClosed.IsSet);
|
||||
}
|
||||
}
|
||||
@@ -392,14 +392,14 @@ namespace k8s.Tests
|
||||
|
||||
using (var server = new MockKubeApiServer(testOutput, async httpContext =>
|
||||
{
|
||||
await WriteStreamLine(httpContext, MockKubeApiServer.MockPodResponse);
|
||||
await waitForException.WaitAsync();
|
||||
await WriteStreamLine(httpContext, MockKubeApiServer.MockPodResponse).ConfigureAwait(false);
|
||||
await waitForException.WaitAsync().ConfigureAwait(false);
|
||||
throw new IOException("server down");
|
||||
}))
|
||||
{
|
||||
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
|
||||
|
||||
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
|
||||
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
|
||||
|
||||
waitForException.Set();
|
||||
Watcher<V1Pod> watcher;
|
||||
@@ -413,13 +413,13 @@ namespace k8s.Tests
|
||||
onClosed: waitForClosed.Set);
|
||||
|
||||
// wait server down
|
||||
await Task.WhenAny(exceptionReceived.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(exceptionReceived.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
|
||||
Assert.True(
|
||||
exceptionReceived.IsSet,
|
||||
"Timed out waiting for exception");
|
||||
|
||||
await Task.WhenAny(waitForClosed.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(waitForClosed.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
Assert.True(waitForClosed.IsSet);
|
||||
Assert.False(watcher.Watching);
|
||||
Assert.IsType<IOException>(exceptionCatched);
|
||||
@@ -446,11 +446,11 @@ namespace k8s.Tests
|
||||
|
||||
using (var server = new MockKubeApiServer(testOutput, async httpContext =>
|
||||
{
|
||||
await WriteStreamLine(httpContext, MockKubeApiServer.MockPodResponse);
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine);
|
||||
await WriteStreamLine(httpContext, MockKubeApiServer.MockPodResponse).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine).ConfigureAwait(false);
|
||||
|
||||
// make server alive, cannot set to int.max as of it would block response
|
||||
await serverShutdown.WaitAsync();
|
||||
await serverShutdown.WaitAsync().ConfigureAwait(false);
|
||||
return false;
|
||||
}))
|
||||
{
|
||||
@@ -463,7 +463,7 @@ namespace k8s.Tests
|
||||
Assert.False(handler1.Called);
|
||||
Assert.False(handler2.Called);
|
||||
|
||||
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
|
||||
var listTask = await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).ConfigureAwait(false);
|
||||
|
||||
var events = new HashSet<WatchEventType>();
|
||||
|
||||
@@ -475,7 +475,7 @@ namespace k8s.Tests
|
||||
});
|
||||
|
||||
// wait server yields all events
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
|
||||
Assert.True(
|
||||
eventsReceived.CurrentCount == 0,
|
||||
@@ -499,13 +499,13 @@ namespace k8s.Tests
|
||||
|
||||
using (var server = new MockKubeApiServer(testOutput, async httpContext =>
|
||||
{
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine);
|
||||
await WriteStreamLine(httpContext, MockDeletedStreamLine);
|
||||
await WriteStreamLine(httpContext, MockModifiedStreamLine);
|
||||
await WriteStreamLine(httpContext, MockErrorStreamLine);
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockDeletedStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockModifiedStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockErrorStreamLine).ConfigureAwait(false);
|
||||
|
||||
// make server alive, cannot set to int.max as of it would block response
|
||||
await serverShutdown.WaitAsync();
|
||||
await serverShutdown.WaitAsync().ConfigureAwait(false);
|
||||
return false;
|
||||
}))
|
||||
{
|
||||
@@ -533,10 +533,10 @@ namespace k8s.Tests
|
||||
errors += 1;
|
||||
eventsReceived.Signal();
|
||||
},
|
||||
onClosed: connectionClosed.Set);
|
||||
onClosed: connectionClosed.Set).ConfigureAwait(false);
|
||||
|
||||
// wait server yields all events
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
|
||||
Assert.True(
|
||||
eventsReceived.CurrentCount == 0,
|
||||
@@ -553,7 +553,7 @@ namespace k8s.Tests
|
||||
|
||||
serverShutdown.Set();
|
||||
|
||||
await Task.WhenAny(connectionClosed.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(connectionClosed.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
Assert.True(connectionClosed.IsSet);
|
||||
}
|
||||
}
|
||||
@@ -584,19 +584,19 @@ namespace k8s.Tests
|
||||
{
|
||||
Image = "ubuntu/xenial",
|
||||
Name = "runner",
|
||||
Command = new List<string>() {"/bin/bash", "-c", "--" },
|
||||
Command = new List<string>() { "/bin/bash", "-c", "--" },
|
||||
Args = new List<string>()
|
||||
{
|
||||
"trap : TERM INT; sleep infinity & wait"
|
||||
}
|
||||
}
|
||||
"trap : TERM INT; sleep infinity & wait",
|
||||
},
|
||||
},
|
||||
},
|
||||
RestartPolicy = "Never"
|
||||
RestartPolicy = "Never",
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
"default");
|
||||
"default").ConfigureAwait(false);
|
||||
|
||||
Collection<Tuple<WatchEventType, V1Job>> events = new Collection<Tuple<WatchEventType, V1Job>>();
|
||||
|
||||
@@ -618,15 +618,15 @@ namespace k8s.Tests
|
||||
},
|
||||
onClosed: connectionClosed.Set).ConfigureAwait(false);
|
||||
|
||||
await started.WaitAsync();
|
||||
await started.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
await Task.WhenAny(connectionClosed.WaitAsync(), Task.Delay(TimeSpan.FromMinutes(3)));
|
||||
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());
|
||||
new V1DeleteOptions()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Fact(Skip = "https://github.com/kubernetes-client/csharp/issues/165")]
|
||||
@@ -637,14 +637,14 @@ namespace k8s.Tests
|
||||
|
||||
using (var server = new MockKubeApiServer(testOutput, async httpContext =>
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(120)); // The default timeout is 100 seconds
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine);
|
||||
await WriteStreamLine(httpContext, MockDeletedStreamLine);
|
||||
await WriteStreamLine(httpContext, MockModifiedStreamLine);
|
||||
await WriteStreamLine(httpContext, MockErrorStreamLine);
|
||||
await Task.Delay(TimeSpan.FromSeconds(120)).ConfigureAwait(false); // The default timeout is 100 seconds
|
||||
await WriteStreamLine(httpContext, MockAddedEventStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockDeletedStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockModifiedStreamLine).ConfigureAwait(false);
|
||||
await WriteStreamLine(httpContext, MockErrorStreamLine).ConfigureAwait(false);
|
||||
|
||||
// make server alive, cannot set to int.max as of it would block response
|
||||
await serverShutdown.WaitAsync();
|
||||
await serverShutdown.WaitAsync().ConfigureAwait(false);
|
||||
return false;
|
||||
}))
|
||||
{
|
||||
@@ -671,10 +671,10 @@ namespace k8s.Tests
|
||||
|
||||
errors += 1;
|
||||
eventsReceived.Signal();
|
||||
});
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
// wait server yields all events
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout));
|
||||
await Task.WhenAny(eventsReceived.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(false);
|
||||
|
||||
Assert.True(
|
||||
eventsReceived.CurrentCount == 0,
|
||||
@@ -701,8 +701,8 @@ namespace k8s.Tests
|
||||
using (var server = new MockKubeApiServer(testOutput, async httpContext =>
|
||||
{
|
||||
httpContext.Response.StatusCode = 200;
|
||||
await httpContext.Response.Body.FlushAsync();
|
||||
await Task.Delay(TimeSpan.FromSeconds(5)); // The default timeout is 100 seconds
|
||||
await httpContext.Response.Body.FlushAsync().ConfigureAwait(false);
|
||||
await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false); // The default timeout is 100 seconds
|
||||
|
||||
return true;
|
||||
}, resp: ""))
|
||||
@@ -715,8 +715,8 @@ namespace k8s.Tests
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () =>
|
||||
{
|
||||
await client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true,
|
||||
cancellationToken: cts.Token);
|
||||
});
|
||||
cancellationToken: cts.Token).ConfigureAwait(false);
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ namespace k8s.Tests
|
||||
/// <summary>
|
||||
/// The next server port to use.
|
||||
/// </summary>
|
||||
static int NextPort = 13255;
|
||||
|
||||
private static int nextPort = 13255;
|
||||
private bool disposedValue;
|
||||
private readonly ITestOutputHelper testOutput;
|
||||
|
||||
/// <summary>
|
||||
@@ -38,7 +38,7 @@ namespace k8s.Tests
|
||||
{
|
||||
this.testOutput = testOutput;
|
||||
|
||||
int port = Interlocked.Increment(ref NextPort);
|
||||
int port = Interlocked.Increment(ref nextPort);
|
||||
|
||||
// Useful to diagnose test timeouts.
|
||||
TestCancellation.Register(
|
||||
@@ -199,7 +199,7 @@ namespace k8s.Tests
|
||||
await serverSocket.CloseAsync(
|
||||
received.Result.CloseStatus.Value,
|
||||
received.Result.CloseStatusDescription,
|
||||
TestCancellation);
|
||||
TestCancellation).ConfigureAwait(false);
|
||||
|
||||
testOutput.WriteLine("Server socket closed.");
|
||||
}
|
||||
@@ -260,7 +260,7 @@ namespace k8s.Tests
|
||||
|
||||
await webSocket.SendAsync(sendBuffer, WebSocketMessageType.Binary,
|
||||
endOfMessage: true,
|
||||
cancellationToken: TestCancellation);
|
||||
cancellationToken: TestCancellation).ConfigureAwait(false);
|
||||
|
||||
return sendBuffer.Length;
|
||||
}
|
||||
@@ -289,7 +289,7 @@ namespace k8s.Tests
|
||||
using (MemoryStream buffer = new MemoryStream())
|
||||
{
|
||||
byte[] receiveBuffer = new byte[1024];
|
||||
WebSocketReceiveResult receiveResult = await webSocket.ReceiveAsync(receiveBuffer, TestCancellation);
|
||||
WebSocketReceiveResult receiveResult = await webSocket.ReceiveAsync(receiveBuffer, TestCancellation).ConfigureAwait(false);
|
||||
if (receiveResult.MessageType != WebSocketMessageType.Binary)
|
||||
{
|
||||
throw new IOException(
|
||||
@@ -300,7 +300,7 @@ namespace k8s.Tests
|
||||
|
||||
while (!receiveResult.EndOfMessage)
|
||||
{
|
||||
receiveResult = await webSocket.ReceiveAsync(receiveBuffer, TestCancellation);
|
||||
receiveResult = await webSocket.ReceiveAsync(receiveBuffer, TestCancellation).ConfigureAwait(false);
|
||||
buffer.Write(receiveBuffer, 0, receiveResult.Count);
|
||||
}
|
||||
|
||||
@@ -315,11 +315,7 @@ namespace k8s.Tests
|
||||
totalBytes: receivedData.Length);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.CancellationSource.Dispose();
|
||||
this.Host.Dispose();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="ServiceClientCredentials"/> implementation representing no credentials (i.e. anonymous).
|
||||
@@ -335,7 +331,7 @@ namespace k8s.Tests
|
||||
/// <summary>
|
||||
/// Create new <see cref="AnonymousClientCredentials"/>.
|
||||
/// </summary>
|
||||
AnonymousClientCredentials()
|
||||
private AnonymousClientCredentials()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -348,7 +344,35 @@ namespace k8s.Tests
|
||||
/// <summary>
|
||||
/// An error occurred while closing the server-side socket.
|
||||
/// </summary>
|
||||
static readonly EventId ErrorClosingServerSocket = new EventId(1000, nameof(ErrorClosingServerSocket));
|
||||
private static readonly EventId ErrorClosingServerSocket = new EventId(1000, nameof(ErrorClosingServerSocket));
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
CancellationSource.Dispose();
|
||||
Host.Dispose();
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
|
||||
// ~WebSocketTestBase()
|
||||
// {
|
||||
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ kind: Namespace
|
||||
metadata:
|
||||
name: ns";
|
||||
|
||||
var types = new Dictionary<String, Type>();
|
||||
var types = new Dictionary<string, Type>();
|
||||
types.Add("v1/Pod", typeof(V1Pod));
|
||||
types.Add("v1/Namespace", typeof(V1Namespace));
|
||||
|
||||
@@ -157,15 +157,15 @@ metadata:
|
||||
{
|
||||
new V1VolumeMount
|
||||
{
|
||||
Name = "vm1", MountPath = "/vm1", ReadOnlyProperty = true
|
||||
Name = "vm1", MountPath = "/vm1", ReadOnlyProperty = true,
|
||||
},
|
||||
new V1VolumeMount
|
||||
{
|
||||
Name = "vm2", MountPath = "/vm2", ReadOnlyProperty = false
|
||||
Name = "vm2", MountPath = "/vm2", ReadOnlyProperty = false,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -284,7 +284,7 @@ spec:
|
||||
ApiVersion = "v1",
|
||||
Spec = new V1ServiceSpec
|
||||
{
|
||||
Ports = new List<V1ServicePort> { new V1ServicePort { Port = 3000, TargetPort = 3000 } }
|
||||
Ports = new List<V1ServicePort> { new V1ServicePort { Port = 3000, TargetPort = 3000 } },
|
||||
},
|
||||
};
|
||||
|
||||
@@ -336,8 +336,8 @@ data:
|
||||
";
|
||||
|
||||
var result = Yaml.LoadFromString<V1Secret>(kManifest);
|
||||
Assert.Equal(Encoding.UTF8.GetString(result.Data["username"]), "bXktYXBw");
|
||||
Assert.Equal(Encoding.UTF8.GetString(result.Data["password"]), "Mzk1MjgkdmRnN0pi");
|
||||
Assert.Equal("bXktYXBw", Encoding.UTF8.GetString(result.Data["username"]));
|
||||
Assert.Equal("Mzk1MjgkdmRnN0pi", Encoding.UTF8.GetString(result.Data["password"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user