Skip to content

Commit fc4e498

Browse files
dependabot[bot]brendandburnsCopilot
authored
Bump Microsoft.TestPlatform.ObjectModel from 17.14.1 to 18.5.1 (#1748)
* Bump Microsoft.TestPlatform.ObjectModel from 17.14.1 to 18.5.1 --- updated-dependencies: - dependency-name: Microsoft.TestPlatform.ObjectModel dependency-version: 18.5.1 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Fix flaky ClientSetTest and GenericTest with retry logic on Kubernetes 409 Conflict Agent-Logs-Url: https://github.com/kubernetes-client/csharp/sessions/8ef4b9da-e277-4546-9106-90e73cfa3afa Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com> * Refine retry logic: scope pod variable inside loop, move exhaustion check into catch block Agent-Logs-Url: https://github.com/kubernetes-client/csharp/sessions/8ef4b9da-e277-4546-9106-90e73cfa3afa Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com> * Fix flaky CannotWatch test: replace 1-second delay with AsyncManualResetEvent wait Agent-Logs-Url: https://github.com/kubernetes-client/csharp/sessions/115e0bbc-5957-42c4-a05e-71420c29e94e Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Brendan Burns <5751682+brendandburns@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 54a7590 commit fc4e498

3 files changed

Lines changed: 43 additions & 17 deletions

File tree

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.7" />
1313
<PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.7" />
1414
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.5.1" />
15-
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="17.14.1" />
15+
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="18.5.1" />
1616
<PackageVersion Include="Moq" Version="4.20.72" />
1717
<PackageVersion Include="Nito.AsyncEx" Version="5.1.2" />
1818
<PackageVersion Include="Nito.AsyncEx.Coordination" Version="5.1.2" />

tests/E2E.Tests/MinikubeTests.cs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -624,14 +624,27 @@ await genericPods.CreateNamespacedAsync(
624624
Assert.Contains(pods.Items, p => p.Labels().Contains(new KeyValuePair<string, string>("test", "generic-test-jsonpatch")));
625625
}
626626

627-
// replace + get
627+
// replace + get (retry on conflict due to Kubernetes optimistic concurrency)
628628
{
629-
var pod = await genericPods.ReadNamespacedAsync<V1Pod>(namespaceParameter, podName).ConfigureAwait(false);
630-
pod.Spec.Containers[0].Image = "httpd";
631-
await genericPods.ReplaceNamespacedAsync(pod, namespaceParameter, podName).ConfigureAwait(false);
629+
var retries = 5;
630+
while (retries-- > 0)
631+
{
632+
try
633+
{
634+
var pod = await genericPods.ReadNamespacedAsync<V1Pod>(namespaceParameter, podName).ConfigureAwait(false);
635+
pod.Spec.Containers[0].Image = "httpd";
636+
await genericPods.ReplaceNamespacedAsync(pod, namespaceParameter, podName).ConfigureAwait(false);
637+
break;
638+
}
639+
catch (HttpOperationException e) when (e.Response.StatusCode == System.Net.HttpStatusCode.Conflict)
640+
{
641+
if (retries == 0) throw;
642+
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
643+
}
644+
}
632645

633-
pod = await genericPods.ReadNamespacedAsync<V1Pod>(namespaceParameter, podName).ConfigureAwait(false);
634-
Assert.Equal("httpd", pod.Spec.Containers[0].Image);
646+
var updatedPod = await genericPods.ReadNamespacedAsync<V1Pod>(namespaceParameter, podName).ConfigureAwait(false);
647+
Assert.Equal("httpd", updatedPod.Spec.Containers[0].Image);
635648
}
636649

637650
// delete + list
@@ -737,14 +750,27 @@ await clientSet.CoreV1.Pod
737750
Assert.Contains(pods.Items, p => p.Labels().Contains(new KeyValuePair<string, string>("test", "clientset-test-jsonpatch")));
738751
}
739752

740-
// replace + get
753+
// replace + get (retry on conflict due to Kubernetes optimistic concurrency)
741754
{
742-
var pod = await clientSet.CoreV1.Pod.GetAsync(podName, namespaceParameter).ConfigureAwait(false);
743-
pod.Spec.Containers[0].Image = "httpd";
744-
await clientSet.CoreV1.Pod.UpdateAsync(pod, podName, namespaceParameter).ConfigureAwait(false);
755+
var retries = 5;
756+
while (retries-- > 0)
757+
{
758+
try
759+
{
760+
var pod = await clientSet.CoreV1.Pod.GetAsync(podName, namespaceParameter).ConfigureAwait(false);
761+
pod.Spec.Containers[0].Image = "httpd";
762+
await clientSet.CoreV1.Pod.UpdateAsync(pod, podName, namespaceParameter).ConfigureAwait(false);
763+
break;
764+
}
765+
catch (HttpOperationException e) when (e.Response.StatusCode == System.Net.HttpStatusCode.Conflict)
766+
{
767+
if (retries == 0) throw;
768+
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
769+
}
770+
}
745771

746-
pod = await clientSet.CoreV1.Pod.GetAsync(podName, namespaceParameter).ConfigureAwait(false);
747-
Assert.Equal("httpd", pod.Spec.Containers[0].Image);
772+
var updatedPod = await clientSet.CoreV1.Pod.GetAsync(podName, namespaceParameter).ConfigureAwait(false);
773+
Assert.Equal("httpd", updatedPod.Spec.Containers[0].Image);
748774
}
749775

750776
// delete + list

tests/KubernetesClient.Tests/WatchTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ public async Task CannotWatch()
5454
var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() });
5555

5656
// did not pass watch param
57-
var onErrorCalled = false;
57+
var onErrorCalled = new AsyncManualResetEvent(false);
5858

5959
using (var watcher = client.CoreV1.WatchListNamespacedPod(
6060
"default",
6161
onEvent: (type, item) => { },
62-
onError: e => { onErrorCalled = true; }))
62+
onError: e => { onErrorCalled.Set(); }))
6363
{
64-
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(true); // delay for onerror to be called
64+
await Task.WhenAny(onErrorCalled.WaitAsync(), Task.Delay(TestTimeout)).ConfigureAwait(true);
6565
}
6666

67-
Assert.True(onErrorCalled);
67+
Assert.True(onErrorCalled.IsSet);
6868

6969
// server did not response line by line
7070
await Assert.ThrowsAnyAsync<Exception>(() =>

0 commit comments

Comments
 (0)