Skip to content

Commit 8e3cf4f

Browse files
dgvivestimt
andauthored
Minimum required changes for working tests (#481)
* Updated models and fixed tests * Discarded model * Failing tests on CI/CD * Debugging tests on CI/CD * Applied PR suggested changes * error when running tests on CI/CD pipeline * Implemented approach from PR #343 for cancelling streamReader * Tests case is behaving differently while it runs on CI/CD pipeline * Merged changes from author fork * Error on CI/CD pipeline due to new Message.Status. Discarted Message.Status condition to validate event monitoring * Serialization for IList<byte> to base64 * PR suggestions by @galvesriverio * Updated test for DockerService_IsRunning * Renamed process name in tests * Updated version for Nerdbank.GitVersioning * Updated ProcesName in test Co-authored-by: timt <timt@spgcontrols.com>
1 parent a5ee061 commit 8e3cf4f

File tree

559 files changed

+871
-231527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

559 files changed

+871
-231527
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<ItemGroup>
3232
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
33-
<PackageReference Include="Nerdbank.GitVersioning" Version="3.1.91">
33+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.3.37">
3434
<PrivateAssets>all</PrivateAssets>
3535
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
3636
</PackageReference>

src/Docker.DotNet/Endpoints/StreamUtil.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
using System.Text;
55
using System.Threading;
66
using System.Threading.Tasks;
7+
using Newtonsoft.Json;
78

89
namespace Docker.DotNet.Models
910
{
1011
internal static class StreamUtil
1112
{
13+
private static Newtonsoft.Json.JsonSerializer _serializer = new Newtonsoft.Json.JsonSerializer();
14+
1215
internal static async Task MonitorStreamAsync(Task<Stream> streamTask, DockerClient client, CancellationToken cancel, IProgress<string> progress)
1316
{
1417
using (var stream = await streamTask)
@@ -31,29 +34,13 @@ internal static async Task MonitorStreamAsync(Task<Stream> streamTask, DockerCli
3134
internal static async Task MonitorStreamForMessagesAsync<T>(Task<Stream> streamTask, DockerClient client, CancellationToken cancel, IProgress<T> progress)
3235
{
3336
using (var stream = await streamTask)
37+
using (var reader = new StreamReader(stream, new UTF8Encoding(false)))
38+
using (var jsonReader = new JsonTextReader(reader) { SupportMultipleContent = true })
3439
{
35-
// ReadLineAsync must be cancelled by closing the whole stream.
36-
using (cancel.Register(() => stream.Dispose()))
40+
while (await jsonReader.ReadAsync().WithCancellation(cancel))
3741
{
38-
using (var reader = new StreamReader(stream, new UTF8Encoding(false)))
39-
{
40-
string line;
41-
try
42-
{
43-
while ((line = await reader.ReadLineAsync()) != null)
44-
{
45-
var prog = client.JsonSerializer.DeserializeObject<T>(line);
46-
if (prog == null) continue;
47-
48-
progress.Report(prog);
49-
}
50-
}
51-
catch (ObjectDisposedException)
52-
{
53-
// The subsequent call to reader.ReadLineAsync() after cancellation
54-
// will fail because we disposed the stream. Just ignore here.
55-
}
56-
}
42+
var ev = _serializer.Deserialize<T>(jsonReader);
43+
progress?.Report(ev);
5744
}
5845
}
5946
}
@@ -92,5 +79,19 @@ internal static async Task MonitorResponseForMessagesAsync<T>(Task<HttpResponseM
9279
}
9380
}
9481
}
82+
83+
private static async Task<T> WithCancellation<T>(this Task<T> task, CancellationToken cancellationToken)
84+
{
85+
var tcs = new TaskCompletionSource<bool>();
86+
using (cancellationToken.Register(s => ((TaskCompletionSource<bool>)s).TrySetResult(true), tcs))
87+
{
88+
if (task != await Task.WhenAny(task, tcs.Task))
89+
{
90+
throw new OperationCanceledException(cancellationToken);
91+
}
92+
}
93+
94+
return await task;
95+
}
9596
}
96-
}
97+
}

src/Docker.DotNet/Endpoints/SwarmOperations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async Task<ServiceUpdateResponse> ISwarmOperations.UpdateServiceAsync(string id,
156156
return this._client.JsonSerializer.DeserializeObject<ServiceUpdateResponse>(response.Body);
157157
}
158158

159-
async Task ISwarmOperations.UpdateSwarmAsync(SwarmUpdateParameters parameters, CancellationToken cancellationToken)
159+
async Task ISwarmOperations.UpdateSwarmAsync(SwarmUpdateParameters parameters, CancellationToken cancellationToken)
160160
{
161161
var query = new QueryString<SwarmUpdateParameters>(parameters ?? throw new ArgumentNullException(nameof(parameters)));
162162
var body = new JsonRequestContent<Spec>(parameters.Spec ?? throw new ArgumentNullException(nameof(parameters.Spec)), this._client.JsonSerializer);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
5+
namespace Docker.DotNet
6+
{
7+
internal class JsonBase64Converter : JsonConverter
8+
{
9+
private static readonly Type _byteListType = typeof(IList<byte>);
10+
public override bool CanRead => true;
11+
12+
public override bool CanWrite => false;
13+
14+
public override void WriteJson(JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
15+
{
16+
throw new NotImplementedException();
17+
}
18+
19+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
20+
{
21+
var strVal = reader.Value as string;
22+
23+
return Convert.FromBase64String(strVal);
24+
}
25+
26+
public override bool CanConvert(Type objectType)
27+
{
28+
return objectType == _byteListType;
29+
}
30+
}
31+
}

src/Docker.DotNet/JsonSerializer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ internal class JsonSerializer
1717
new JsonVersionConverter(),
1818
new StringEnumConverter(),
1919
new TimeSpanSecondsConverter(),
20-
new TimeSpanNanosecondsConverter()
20+
new TimeSpanNanosecondsConverter(),
21+
new JsonBase64Converter()
2122
}
2223
};
2324

src/Docker.DotNet/Models/ContainerExecInspectResponse.Generated.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Docker.DotNet.Models
55
[DataContract]
66
public class ContainerExecInspectResponse // (types.ContainerExecInspect)
77
{
8-
[DataMember(Name = "ExecID", EmitDefaultValue = false)]
8+
[DataMember(Name = "ID", EmitDefaultValue = false)]
99
public string ExecID { get; set; }
1010

1111
[DataMember(Name = "ContainerID", EmitDefaultValue = false)]

src/Docker.DotNet/Models/ContainerSpec.Generated.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ public class ContainerSpec // (swarm.ContainerSpec)
7878
[DataMember(Name = "Sysctls", EmitDefaultValue = false)]
7979
public IDictionary<string, string> Sysctls { get; set; }
8080

81-
[DataMember(Name = "Capabilities", EmitDefaultValue = false)]
82-
public IList<string> Capabilities { get; set; }
81+
[DataMember(Name = "CapabilityAdd", EmitDefaultValue = false)]
82+
public IList<string> CapabilityAdd { get; set; }
83+
84+
[DataMember(Name = "CapabilityDrop", EmitDefaultValue = false)]
85+
public IList<string> CapabilityDrop { get; set; }
86+
87+
[DataMember(Name = "Ulimits", EmitDefaultValue = false)]
88+
public IList<Ulimit> Ulimits { get; set; }
8389
}
8490
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Docker.DotNet.Models
4+
{
5+
[DataContract]
6+
public class GlobalJob // (swarm.GlobalJob)
7+
{
8+
}
9+
}

src/Docker.DotNet/Models/HostConfig.Generated.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ public HostConfig(Resources Resources)
8181
[DataMember(Name = "CapDrop", EmitDefaultValue = false)]
8282
public IList<string> CapDrop { get; set; }
8383

84-
[DataMember(Name = "Capabilities", EmitDefaultValue = false)]
85-
public IList<string> Capabilities { get; set; }
86-
8784
[DataMember(Name = "CgroupnsMode", EmitDefaultValue = false)]
8885
public string CgroupnsMode { get; set; }
8986

src/Docker.DotNet/Models/ImagesListParameters.Generated.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ namespace Docker.DotNet.Models
66
[DataContract]
77
public class ImagesListParameters // (main.ImagesListParameters)
88
{
9-
[QueryStringParameter("filter", false)]
10-
public string MatchName { get; set; }
11-
129
[QueryStringParameter("all", false, typeof(BoolQueryStringConverter))]
1310
public bool? All { get; set; }
1411

0 commit comments

Comments
 (0)